Feature Request
Problems
Construct Null Diagram
It is not simple to create the null datajoint.Diagram, which we define as a Diagram with no nodes or edges, and notate conventionally as $K_0$. It should be simple to construct $K_0$ using Diagram.__init__; ideally, this would be the default behavior if no source is passed, or if the source is null.
sum() Diagrams
In addition, while it is possible to __add__ two Diagrams, it is not straightforward to join a list of Diagrams. The current approaches include:
diags: list[dj.Diagram] = [diag1, diag2, ...]
# for loop accumulation
full = diags[0]
for diag in diags[1::]:
full += diag
# accumulate in comprehension (ew)
full = diags[0]
[full := full + diag for diag in diags[1::]]
# sum() accumulation
full = sum(diags[1::], diags[0])
Ideally, one should be able to simply:
but this is not supported because Diagram.__radd__ is not implemented.
Check Diagram Equality
It would be nice to implement Diagram.__eq__ so that one can check diag1 == diag2:
def __eq__(self, other: dj.Diagram, approx=False) -> bool:
# Check other attributes, like `nodes_to_show` and `type(source)`
if approx:
return networkx.algorithms.faster_could_be_isomorphic(self, other)
else:
return networkx.algorithms.is_isomorphic(self, other)
Requirements
d1 = dj.Diagram()
d2 = dj.Diagram()
d3 = dj.Diagram(d2)
d4 = dj.Diagram(empty_schema)
d5 = dj.Diagram(non_empty_schema)
d6 = dj.Diagram(table)
diags = [d1, d2, d3, d4, d5, d6]
assert d1 == d2 == d3 == d4
assert d5 != d1
assert d5 != d6
assert sum(diags) == d5 + d6
Justification
It should be easier to work with multiple Diagrams, especially if #1190 is not implemented. For example, lack of support for $K_0$ is troublesome in the works-api implementation, since we must create _placeholder schemas for empty pipelines.
Alternative Considerations
#1190 covers some of the use cases where these operations would be used.
Related Errors
#1190 also proposes changes to datajoint.Diagram.__init__.
Environment
- OS: Linux (relevant for all)
- Python Version: 3.9 (relevant for all)
- MySQL Version: 8.0 (relevant for all)
- MySQL Deployment Strategy: remote (percona-qa.datajoint.io)
- DataJoint Version: 0.14.3
Additional Research and Context
Feature Request
Problems
Construct Null Diagram
It is not simple to create the null$K_0$ . It should be simple to construct $K_0$ using
datajoint.Diagram, which we define as aDiagramwith no nodes or edges, and notate conventionally asDiagram.__init__; ideally, this would be the default behavior if nosourceis passed, or if thesourceis null.sum()DiagramsIn addition, while it is possible to
__add__twoDiagrams, it is not straightforward to join a list ofDiagrams. The current approaches include:Ideally, one should be able to simply:
but this is not supported because
Diagram.__radd__is not implemented.Check Diagram Equality
It would be nice to implement
Diagram.__eq__so that one can checkdiag1 == diag2:Requirements
Justification
It should be easier to work with multiple$K_0$ is troublesome in the
Diagrams, especially if #1190 is not implemented. For example, lack of support forworks-apiimplementation, since we must create_placeholderschemas for empty pipelines.Alternative Considerations
#1190 covers some of the use cases where these operations would be used.
Related Errors
#1190 also proposes changes to
datajoint.Diagram.__init__.Environment
Additional Research and Context