Repository navigation
Description
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 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:
full = sum(diags)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 + d6Justification
It should be easier to work with multiple Diagrams, especially if #1190 is not implemented. For example, lack of support for 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
-
Definition of
$K_0$
Activity
dimitri-yatsenko commentedon Sep 28, 2024
Let's discuss first.
dimitri-yatsenko commentedon Sep 28, 2024
To clarify, the
connection.dependenciesobject handles the complete graph of all active schemas.Diagramobjects only select the relevant portions of that graph for plotting. It lazy loads, so if you activate all the schemas you need and then plot the diagrams, it executes efficiently with a single call to the information schema.dimitri-yatsenko commentedon Sep 28, 2024
reduce(lambda a, b: a + b, diagram_sequence)dimitri-yatsenko commentedon Sep 30, 2024
After reviewing with @ethho, we cleared the disconnect. This feature is unnecessary. Closing.