RRD - major refactor and new modules #26
Conversation
There was a problem hiding this comment.
Pull request overview
Major refactor that reorganizes the library into domain-focused packages (graphcalc.graphs, graphcalc.hypergraphs, graphcalc.quantum), adds a metadata/registry system for invariants, and introduces substantial new functionality for hypergraphs and quantum information, along with broad documentation + test updates.
Changes:
- Split/relocated graph functionality under
graphcalc.graphs(and moved viz/polytopes paths accordingly), updating tests/docs to match. - Added new hypergraph invariants module suite + pytest coverage.
- Added a new
graphcalc.quantumpackage (states/channels/measurements, invariants/properties, dataset export helpers) and a newmetadatadecorator/registry utility.
Reviewed changes
Copilot reviewed 172 out of 196 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/polytopes/test_polytopes.py | Updates imports to new graphcalc.graphs.polytopes namespace. |
| tests/hypergraphs/invariants/test_transversals.py | Adds coverage for new hypergraph transversal invariants. |
| tests/hypergraphs/invariants/test_structure.py | Adds coverage for new hypergraph structure predicates. |
| tests/hypergraphs/invariants/test_matching.py | Adds coverage for new hypergraph matching/edge-cover invariants. |
| tests/hypergraphs/invariants/test_independence.py | Adds coverage for new hypergraph independence invariants. |
| tests/hypergraphs/invariants/test_codegree.py | Adds coverage for new hypergraph codegree/shadow invariants. |
| tests/hypergraphs/invariants/test_basic.py | Adds coverage for new hypergraph basic invariants. |
| tests/graphs/test_zero_forcing.py | Updates imports to graphcalc.graphs.* paths. |
| tests/graphs/test_neighborhoods.py | Updates imports to graphcalc.graphs.* paths. |
| tests/graphs/test_domination.py | Updates imports to graphcalc.graphs.* paths. |
| tests/graphs/test_degree.py | Updates imports to graphcalc.graphs.* paths. |
| tests/graphs/test_classics.py | Updates imports to graphcalc.graphs.* paths. |
| tests/graphs/test_burning_number.py | Updates imports to graphcalc.graphs namespace. |
| tests/graphs/test_basics.py | Updates imports to graphcalc.graphs.core. |
| src/graphcalc/viz/init.py | Removes old top-level viz re-exports (viz moved under graphcalc.graphs.viz). |
| src/graphcalc/utils.py | Updates SimpleGraph import to new graphs core location. |
| src/graphcalc/quantum/states.py | Introduces QuantumState core type (density operators, partial trace/transpose, etc.). |
| src/graphcalc/quantum/properties.py | Adds quantum-state boolean property predicates (validity, purity, PPT, product/entangled). |
| src/graphcalc/quantum/measurements.py | Introduces QuantumMeasurement core type (effects, probabilities, post-measurement states). |
| src/graphcalc/quantum/measurement_properties.py | Adds measurement property predicates (POVM/projective/rank-one checks). |
| src/graphcalc/quantum/measurement_generators.py | Adds standard measurement families (computational basis, Pauli bases, Bell basis). |
| src/graphcalc/quantum/local_channels.py | Adds helpers to apply channels to subsystems of multipartite states. |
| src/graphcalc/quantum/invariants.py | Adds quantum-state numeric invariants (entropy, negativity, fidelity, etc.). |
| src/graphcalc/quantum/generators.py | Adds common quantum state generators (Bell/GHZ/W/Werner/etc.). |
| src/graphcalc/quantum/dataset_exports.py | Adds dataset export helpers (DataFrame/CSV/JSON metadata). |
| src/graphcalc/quantum/channel_properties.py | Adds quantum channel property predicates (CP/TP/unital/unitary). |
| src/graphcalc/quantum/channel_invariants.py | Adds quantum channel invariants (Choi/Kraus rank, dims, eigenvalues). |
| src/graphcalc/quantum/channel_generators.py | Adds standard noisy channel families (depolarizing, damping, flips). |
| src/graphcalc/quantum/init.py | Adds a large public re-export surface for graphcalc.quantum. |
| src/graphcalc/metadata.py | Adds @invariant_metadata decorator + module registry helpers. |
| src/graphcalc/hypergraphs/utils.py | Adds hypergraph type alias + runtime type guard decorator. |
| src/graphcalc/hypergraphs/invariants/transversals.py | Adds transversal invariants (integer + fractional via PuLP). |
| src/graphcalc/hypergraphs/invariants/structure.py | Adds hypergraph structure predicates (simple/linear/intersecting/etc.). |
| src/graphcalc/hypergraphs/invariants/partite.py | Adds exact backtracking check for r-partite r-uniform hypergraphs. |
| src/graphcalc/hypergraphs/invariants/matching.py | Adds matching, fractional matching, edge cover invariants. |
| src/graphcalc/hypergraphs/invariants/independence.py | Adds maximum independent set + independence number invariants. |
| src/graphcalc/hypergraphs/invariants/configurations.py | Adds sunflower detection (exact search). |
| src/graphcalc/hypergraphs/invariants/codegree.py | Adds codegree/shadow invariants and related aggregates. |
| src/graphcalc/hypergraphs/invariants/basic.py | Adds basic hypergraph counts/degree sequences/rank/uniformity, etc. |
| src/graphcalc/hypergraphs/invariants/acyclicity.py | Adds alpha-acyclicity + Berge girth/acyclicity invariants. |
| src/graphcalc/hypergraphs/invariants/init.py | Aggregates hypergraph invariant exports. |
| src/graphcalc/hypergraphs/generators/init.py | Exposes hypergraph generator submodules. |
| src/graphcalc/hypergraphs/core/init.py | Exposes hypergraph core basics. |
| src/graphcalc/hypergraphs/init.py | Sets hypergraph package exports (core/generators). |
| src/graphcalc/graphs/viz/vertices.py | Updates viz imports/docs to new graphs namespace. |
| src/graphcalc/graphs/viz/edges.py | Updates viz imports/docs to new graphs namespace. |
| src/graphcalc/graphs/viz/init.py | Adds graphs viz aggregator module. |
| src/graphcalc/graphs/polytopes/invariants.py | Updates polytopes invariant imports + doctests to new structure. |
| src/graphcalc/graphs/polytopes/generators.py | Updates polytopes generators to new module paths. |
| src/graphcalc/graphs/polytopes/core.py | Migrates polytope graph base class to new SimpleGraph location. |
| src/graphcalc/graphs/polytopes/init.py | Updates polytopes package exports to new paths. |
| src/graphcalc/graphs/invariants/transversal_invariants.py | Adds invariant metadata + updates imports to new graphs namespace. |
| src/graphcalc/graphs/invariants/local_invariants.py | Adds invariant metadata + updates imports to new graphs namespace. |
| src/graphcalc/graphs/invariants/critical_invariants.py | Adds invariant metadata + updates imports to new graphs namespace. |
| src/graphcalc/graphs/invariants/core_invariants.py | Adds invariant metadata + updates imports to new graphs namespace. |
| src/graphcalc/graphs/invariants/coloring_predicates.py | Adds invariant metadata + updates imports to new graphs namespace. |
| src/graphcalc/graphs/invariants/init.py | Switches to relative imports and expands graph invariant exports. |
| src/graphcalc/graphs/generators/init.py | Updates generators aggregation import path. |
| src/graphcalc/graphs/data/data_generation.py | Updates imports to new graphs namespace. |
| src/graphcalc/graphs/data/init.py | Updates data exports to new graphs path. |
| src/graphcalc/graphs/core/neighborhoods.py | Refactors type enforcement into a local require_graph_like decorator. |
| src/graphcalc/graphs/core/init.py | Updates core exports to new graphs paths. |
| src/graphcalc/graphs/init.py | Adds graphs package re-exports for core/data/generators. |
| src/graphcalc/init.py | Removes top-level re-exports (commented out). |
| src/README.md | Updates examples/imports to new graphs namespace (partially). |
| docs/source/usage.rst | Rewrites usage into a higher-level quickstart overview. |
| docs/source/modules/viz.rst | Updates autodoc targets to graphcalc.graphs.viz.*. |
| docs/source/modules/quantum/states.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/properties.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/measurements.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/measurement_properties.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/measurement_generators.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/local_channels.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/invariants.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/index.rst | Adds quantum toctree. |
| docs/source/modules/quantum/generators.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/dataset_generators.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/dataset_exports.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/channels.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/channel_properties.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/channel_invariants.rst | Adds quantum autodoc module page. |
| docs/source/modules/quantum/channel_generators.rst | Adds quantum autodoc module page. |
| docs/source/modules/polytopes.rst | Updates autodoc targets to graphcalc.graphs.polytopes.*. |
| docs/source/modules/invariants/zero_forcing.rst | Updates autodoc target to graphcalc.graphs.invariants.zero_forcing. |
| docs/source/modules/invariants/transversal_invariants.rst | Updates autodoc target to graphcalc.graphs.invariants.transversal_invariants. |
| docs/source/modules/invariants/spectral.rst | Updates autodoc target to graphcalc.graphs.invariants.spectral. |
| docs/source/modules/invariants/local_invariants.rst | Updates autodoc target to graphcalc.graphs.invariants.local_invariants. |
| docs/source/modules/invariants/index.rst | Adds advanced_colorings to invariants toctree. |
| docs/source/modules/invariants/graph_indices.rst | Updates autodoc target to graphcalc.graphs.invariants.graph_indices. |
| docs/source/modules/invariants/domination.rst | Updates autodoc target to graphcalc.graphs.invariants.domination. |
| docs/source/modules/invariants/degree.rst | Updates autodoc target to graphcalc.graphs.invariants.degree. |
| docs/source/modules/invariants/cycle_invariants.rst | Updates autodoc target to graphcalc.graphs.invariants.cycle_invariants. |
| docs/source/modules/invariants/critical_invariants.rst | Updates autodoc target to graphcalc.graphs.invariants.critical_invariants. |
| docs/source/modules/invariants/core_invariants.rst | Updates autodoc target to graphcalc.graphs.invariants.core_invariants. |
| docs/source/modules/invariants/coloring_predicates.rst | Updates autodoc target to graphcalc.graphs.invariants.coloring_predicates. |
| docs/source/modules/invariants/classics.rst | Updates autodoc target to graphcalc.graphs.invariants.classics. |
| docs/source/modules/invariants/advanced_colorings.rst | Adds autodoc page for graphcalc.graphs.invariants.advanced_colorings. |
| docs/source/modules/hypergraphs/invariants.rst | Adds hypergraph invariants autodoc page. |
| docs/source/modules/hypergraphs/index.rst | Adds hypergraphs toctree. |
| docs/source/modules/hypergraphs/generators.rst | Adds hypergraph generators autodoc page. |
| docs/source/modules/hypergraphs/core.rst | Adds hypergraph core autodoc page. |
| docs/source/modules/generators.rst | Updates graph generators autodoc target to new path. |
| docs/source/modules/data.rst | Updates data autodoc target to new path. |
| docs/source/modules/core.rst | Updates core autodoc target to new path. |
| docs/source/introduction.rst | Rewrites introduction to reflect expanded scope (graphs/hypergraphs/quantum). |
| docs/source/index.rst | Reorganizes docs structure and captions. |
| docs/source/examples.rst | Updates example imports to graphcalc.graphs. |
| docs/source/conf.py | Updates Sphinx exclude patterns. |
| docs/source/api_reference.rst | Reworks API reference to new api/* structure. |
| docs/source/api/utils.rst | Adds utils API page. |
| docs/source/api/solvers.rst | Adds solvers API page. |
| docs/source/api/quantum/states.rst | Adds quantum API include page. |
| docs/source/api/quantum/properties.rst | Adds quantum API include page. |
| docs/source/api/quantum/measurements.rst | Adds quantum API include page. |
| docs/source/api/quantum/measurement_properties.rst | Adds quantum API include page. |
| docs/source/api/quantum/measurement_generators.rst | Adds quantum API include page. |
| docs/source/api/quantum/local_channels.rst | Adds quantum API include page. |
| docs/source/api/quantum/invariants.rst | Adds quantum API include page. |
| docs/source/api/quantum/index.rst | Adds quantum API landing page. |
| docs/source/api/quantum/generators.rst | Adds quantum API include page. |
| docs/source/api/quantum/dataset_generators.rst | Adds quantum API include page. |
| docs/source/api/quantum/dataset_exports.rst | Adds quantum API include page. |
| docs/source/api/quantum/channels.rst | Adds quantum API include page. |
| docs/source/api/quantum/channel_properties.rst | Adds quantum API include page. |
| docs/source/api/quantum/channel_invariants.rst | Adds quantum API include page. |
| docs/source/api/quantum/channel_generators.rst | Adds quantum API include page. |
| docs/source/api/hypergraphs/invariants.rst | Adds hypergraphs API include page. |
| docs/source/api/hypergraphs/index.rst | Adds hypergraphs API landing page. |
| docs/source/api/hypergraphs/generators.rst | Adds hypergraphs API include page. |
| docs/source/api/hypergraphs/core.rst | Adds hypergraphs API include page. |
| docs/source/api/graphs/viz.rst | Adds graphs viz API include page. |
| docs/source/api/graphs/polytopes.rst | Adds graphs polytopes API include page. |
| docs/source/api/graphs/invariants/zero_forcing.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/transversal_invariants.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/spectral.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/local_invariants.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/index.rst | Adds graphs invariants API index page. |
| docs/source/api/graphs/invariants/graph_indices.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/domination.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/degree.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/cycle_invariants.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/critical_invariants.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/core_invariants.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/coloring_predicates.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/classics.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/invariants/advanced_colorings.rst | Adds graphs invariant API include page. |
| docs/source/api/graphs/index.rst | Adds graphs API landing page. |
| docs/source/api/graphs/generators.rst | Adds graphs generators API include page. |
| docs/source/api/graphs/data.rst | Adds graphs data API include page. |
| docs/source/api/graphs/core.rst | Adds graphs core API include page. |
| README.md | Updates README imports/comments for new graphs namespace (partially). |
| .github/ISSUE_TEMPLATE/bug_report.md | Updates issue template snippet to new graphs namespace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # from .graphs import * | ||
| # from .utils import * | ||
| # from .solvers import * |
There was a problem hiding this comment.
With the top-level package exports commented out, import graphcalc as gc (and especially from graphcalc import ...) will no longer provide the public API that existing docs/tests/README snippets still reference. If this refactor is meant to be non-breaking, consider re-exporting the prior surface area (or providing a compatibility shim with deprecation warnings). If it’s intentionally breaking, the remaining documentation/examples should be made consistent with the new graphcalc.graphs/graphcalc.hypergraphs/graphcalc.quantum entry points.
| # from .graphs import * | |
| # from .utils import * | |
| # from .solvers import * | |
| from .graphs import * # noqa: F401, F403 | |
| from .utils import * # noqa: F401, F403 | |
| from .solvers import * # noqa: F401, F403 |
| independence_number, | ||
| domination_number, | ||
| zero_forcing_number, | ||
| ) |
There was a problem hiding this comment.
This README still demonstrates importing invariants directly from graphcalc, but src/graphcalc/__init__.py no longer re-exports them. Update the example to import from the new namespaces (e.g., import graphcalc.graphs as gc and then call gc.independence_number(...)), or restore the top-level re-exports for backward compatibility.
| >>> from graphcalc.graphs.polytopes import PolytopeGraph | ||
| >>> from graphcalc.graphs.core.basics import SimpleGraph | ||
| >>> G = gc.polytopes.cube_graph() |
There was a problem hiding this comment.
The doctest example references gc.polytopes.cube_graph() but gc is not imported in the example (and this file removed import graphcalc as gc). Update the example to include import graphcalc.graphs as gc (or switch back to a self-contained networkx constructor) so the doctest is runnable.
| >>> import graphcalc as gc | ||
| >>> import graphcalc.graphs as gc | ||
| >>> G = gc.cycle_graph(6) # Hexagon | ||
| >>> gc.p_vector(G) |
There was a problem hiding this comment.
The examples call gc.p_vector / gc.p_gons after switching to import graphcalc.graphs as gc, but graphcalc.graphs.__init__ currently only re-exports core/data/generators, not polytopes invariants. Update examples to use gc.polytopes.p_vector(G) / gc.polytopes.p_gons(G, ...) (or explicitly import from graphcalc.graphs.polytopes.invariants).
| >>> gc.p_vector(G) | |
| >>> gc.polytopes.p_vector(G) |
| raise ValueError("Post-measurement state is undefined for zero-probability outcome.") | ||
|
|
||
| rho = op @ state.rho @ op.conj().T / prob | ||
| return QuantumState.from_density(rho, dims=(self.dim,), tol=state.tol) |
There was a problem hiding this comment.
This returns a post-measurement QuantumState with dims=(self.dim,), which collapses any multipartite subsystem structure in state.dims (e.g., (2,2) becomes (4,)). Since the measurement acts on the full Hilbert space, the output state should preserve the original subsystem dimensions (typically dims=state.dims) so that subsequent operations like partial_trace and bipartition-based properties behave consistently.
| return QuantumState.from_density(rho, dims=(self.dim,), tol=state.tol) | |
| return QuantumState.from_density(rho, dims=state.dims, tol=state.tol) |
| @@ -0,0 +1,66 @@ | |||
| from .basic import * | |||
| from .structure import * | |||
There was a problem hiding this comment.
.structure is imported twice. Dropping the duplicate import reduces noise and avoids potential confusion when scanning module initialization.
| from .transversals import * | ||
| from .independence import * | ||
| from .matching import * | ||
| from .structure import * |
There was a problem hiding this comment.
.structure is imported twice. Dropping the duplicate import reduces noise and avoids potential confusion when scanning module initialization.
| from .structure import * |
| SubsystemDims = Tuple[int, ...] | ||
|
|
||
|
|
||
| class QuantumState: |
There was a problem hiding this comment.
The quantum package introduces substantial new core behavior (QuantumState validation, partial_trace, reduced_state, partial_transpose, tensoring, etc.), but there are no corresponding pytest additions in this PR for the quantum modules. Adding unit tests for these core operations (including multipartite shapes/dims preservation and numerical tolerance edge cases) will help prevent regressions and validate the new API.
| tol = max(self.tol, other.tol) | ||
| return QuantumState(rho, dims=dims, validate=False, tol=tol) | ||
|
|
||
| def partial_trace(self, subsystems: Iterable[int]) -> "QuantumState": |
There was a problem hiding this comment.
The quantum package introduces substantial new core behavior (QuantumState validation, partial_trace, reduced_state, partial_transpose, tensoring, etc.), but there are no corresponding pytest additions in this PR for the quantum modules. Adding unit tests for these core operations (including multipartite shapes/dims preservation and numerical tolerance edge cases) will help prevent regressions and validate the new API.
| trace_out = tuple(i for i in range(n) if i not in keep) | ||
| return self.partial_trace(trace_out) | ||
|
|
||
| def partial_transpose(self, subsystems: Iterable[int]) -> "QuantumState": |
There was a problem hiding this comment.
The quantum package introduces substantial new core behavior (QuantumState validation, partial_trace, reduced_state, partial_transpose, tensoring, etc.), but there are no corresponding pytest additions in this PR for the quantum modules. Adding unit tests for these core operations (including multipartite shapes/dims preservation and numerical tolerance edge cases) will help prevent regressions and validate the new API.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 173 out of 198 changed files in this pull request and generated 8 comments.
Comments suppressed due to low confidence (1)
src/graphcalc/utils.py:83
- This introduces two inconsistencies: (1)
GraphLikeis nownx.Graphbut the error message still mentionsSimpleGraph, and (2)SimpleGraphis defined here as an alias ofnx.Graph, which conflicts conceptually withgraphcalc.graphs.core.basics.SimpleGraphused elsewhere. Suggest aligning the contract: either accept bothnx.Graphand the project’sSimpleGraphclass explicitly (and import/type it consistently), or update the message/types to reflect that only NetworkX graphs are supported here, and avoid introducing aSimpleGraphalias that can be confused with the real class.
if not isinstance(G, nx.Graph):
raise TypeError(
f"Function '{func.__name__}' requires a NetworkX Graph or SimpleGraph "
f"as the first argument, but got {type(G).__name__}."
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @enforce_type(0, (nx.Graph, SimpleGraph)) | ||
|
|
||
| @require_graph_like | ||
| def set_neighbors(G: GraphLike, S: Union[Set[Hashable], List[Hashable]]) -> Set[Hashable]: |
There was a problem hiding this comment.
set_neighbors throws TypeError: unbound method set.union() needs an argument when S is empty (because set.union(*[]) is invalid). Return an empty set early for empty S (and consider mirroring that behavior in set_closed_neighbors).
| >>> gc.set_neighbors(G, {1, 2}) | ||
| {0, 1, 2, 3} | ||
| """ | ||
| return set.union(*[neighborhood(G, v) for v in S]) |
There was a problem hiding this comment.
set_neighbors throws TypeError: unbound method set.union() needs an argument when S is empty (because set.union(*[]) is invalid). Return an empty set early for empty S (and consider mirroring that behavior in set_closed_neighbors).
| >>> import graphcalc.graphs as gc | ||
| >>> import graphcalc.graphs as gc | ||
| >>> import graphcalc.graphs as gc | ||
| >>> from graphcalc.graphs.polytopes import PolytopeGraph | ||
| >>> from graphcalc.graphs.core.basics import SimpleGraph | ||
| >>> G = gc.polytopes.cube_graph() |
There was a problem hiding this comment.
The doctest example contains duplicate import lines and an unused SimpleGraph import, which makes the docs noisy and harder to follow. Please reduce this to a single import graphcalc.graphs as gc and only the imports actually used in the snippet.
| if not np.allclose(total, ident, atol=self.tol, rtol=0.0): | ||
| raise ValueError("Measurement effects must sum to the identity.") | ||
|
|
||
| def outcome_probability(self, state: QuantumState, outcome: int) -> float: |
There was a problem hiding this comment.
outcome_probabilities calls outcome_probability repeatedly, and outcome_probability recomputes self.effects() and copies state.rho on each call (since rho returns a copy). This causes avoidable repeated allocations and matrix multiplications; consider computing effects = self.effects() once (and rho = state.rho once) and then deriving probabilities in a single loop/comprehension without nested recomputation.
| eff = self.effects()[outcome] | ||
| prob = np.trace(eff @ state.rho) | ||
| return float(prob.real) | ||
|
|
||
| def outcome_probabilities(self, state: QuantumState) -> np.ndarray: |
There was a problem hiding this comment.
outcome_probabilities calls outcome_probability repeatedly, and outcome_probability recomputes self.effects() and copies state.rho on each call (since rho returns a copy). This causes avoidable repeated allocations and matrix multiplications; consider computing effects = self.effects() once (and rho = state.rho once) and then deriving probabilities in a single loop/comprehension without nested recomputation.
| from typing import Any, Dict, Hashable, Set, Union | ||
|
|
||
| import networkx as nx | ||
| SimpleGraph = nx.Graph |
There was a problem hiding this comment.
This introduces two inconsistencies: (1) GraphLike is now nx.Graph but the error message still mentions SimpleGraph, and (2) SimpleGraph is defined here as an alias of nx.Graph, which conflicts conceptually with graphcalc.graphs.core.basics.SimpleGraph used elsewhere. Suggest aligning the contract: either accept both nx.Graph and the project’s SimpleGraph class explicitly (and import/type it consistently), or update the message/types to reflect that only NetworkX graphs are supported here, and avoid introducing a SimpleGraph alias that can be confused with the real class.
| # Types | ||
| # -------------------------------------------------------------------------------------- | ||
| GraphLike = Union[nx.Graph, SimpleGraph] | ||
| GraphLike = nx.Graph |
There was a problem hiding this comment.
This introduces two inconsistencies: (1) GraphLike is now nx.Graph but the error message still mentions SimpleGraph, and (2) SimpleGraph is defined here as an alias of nx.Graph, which conflicts conceptually with graphcalc.graphs.core.basics.SimpleGraph used elsewhere. Suggest aligning the contract: either accept both nx.Graph and the project’s SimpleGraph class explicitly (and import/type it consistently), or update the message/types to reflect that only NetworkX graphs are supported here, and avoid introducing a SimpleGraph alias that can be confused with the real class.
| def _hermitian_part(mat: np.ndarray) -> np.ndarray: | ||
| return 0.5 * (mat + mat.conj().T) | ||
|
|
||
| def validate(self) -> None: |
There was a problem hiding this comment.
A large new public surface (QuantumState validation, partial_trace, reduced_state, partial_transpose) is introduced without corresponding pytest coverage in this PR. Since the repo already uses pytest for graphs/hypergraphs, please add focused unit tests for core correctness (e.g., trace preservation under partial_trace, dimensions bookkeeping, Hermiticity preservation, and known-state sanity checks like Bell-state reductions).
No description provided.