Remove BackendState base class for simulator backend states.#396
Merged
Remove BackendState base class for simulator backend states.#396
BackendState base class for simulator backend states.#396Conversation
This commit introduces the classes `BaseN` and `PrepareMethod`, which allow the user to customize how `N` commands are handled. For instance, in the VBQC context of Veriphix, `N` commands do not necessarily prepare the node in the |+> state: for each prepared qubit, the preparation should be performed by the client, so that the server does not even see the state.
This commit adapts the existing method `graphix.opengraph.OpenGraph.isclose` to the new API introduced in #358. Additionally, it introduces the new methods `graphix.opengraph.OpenGraph.is_equal_structurally` which compares the underlying structure of two open graphs, and `graphix.fundamentals.AbstractMeasurement.isclose` which defaults to `==` comparison.
This commit adapts the existing method `:func: OpenGraph.compose` to the new API introduced in #358.
This commit fixes domains in the transpiler so that every pattern transpiled from a circuit has a flow. Previously, some domains were incompatible with any flow, despite the patterns being deterministic, because some measurement angles were zero, causing the measurements to ignore certain signals. This commit also adds `optimization.remove_useless_domains` to remove the domains ignored by measurements with angle zero, to recover the same "optimized" patterns as before when needed. This commit also adds `rand_state_vector` to draw a random state vector.
This PR introduces the methods `:func: PauliFlow.check_well_formed`, `:func: GFlow.check_well_formed` and `:func: CausalFlow.check_well_formed` which verify the correctness of flow objects and raise exceptions when the flow is incorrect. Exception classes are grouped in the new module `graphix.flow.exceptions`. The error messages explain which proposition in the flow is violated. Flow-finding algorithms always (in principle) output well-formed flows, but it is possible to instantiate flow objects by passing arbitrary parameters to the constructors. In such cases, there is not any guarantee that the flow objects are well formed. The methods introduced here can be useful for debugging or researching. The exception handling adapts the pattern introduced in #364. The new methods subsume `:func: gflow.verify_flow`, `:func: gflow.verify_gflow`, `:func: gflow.verify_pauli_flow`. Additionally, this PR introduces the methods `:func: PauliFlow.get_measurement_label`, `:func: GFlow.get_measurement_label` which return the measurement label of a given node. They follow same criteria employed in the flow-finding algorithms, that is, querying this method on a node with a measurement `Measurement(0, Plane.XY)` will return `Plane.XY` in a `GFlow` or `CausalFlow` and `Axis.X` in a `PauliFlow`. **Additional information on the exception management** ```mermaid --- config: layout: elk elk: mergeEdges: false nodePlacementStrategy: LINEAR_SEGMENTS --- flowchart TD a0(**Exception**) n0(**FlowError**) n1(FlowGenericError) n2(FlowPropositionError) n3(FlowPropositionOrderError) n4(PartialOrderError) n5(PartialOrderLayerError) a0 --> n0 n0 --FGEReason--> n1 n0 --FPEReason--> n2 n0 --FPOEReason--> n3 n0 --POEReason--> n4 n0 --POLEReason--> n5 ``` - Arrows indicate inheritance (from parent to child). - "Reasons" (`FlowPropositionErrorReason`, `PartialOrderLayerErrorReason`, etc.) are `Enum` classes. - Error subclasses: - `FlowPropositionError` - Violations of the flow-definition propositions which concern the correction function only (C0, C1, G1, G3, G4, G5, P4, P5, P6, P7, P8, P9). - Additional parameters: - `node` - `correction_set` - `FlowPropositionOrderError` - Violations of the flow-definition propositions which concern the correction function and the partial order (C2, C3, G1, G2, P1, P2, P3). - Additional parameters: - `node` - `correction_set` - `past_and_present_nodes` - `FlowGenericError` - General errors in the flow correction function, XY planes in causal flow. - Does not require additional parameters. - `PartialOrderError` - General flow and XZ-corrections errors in the partial order. - Does not require additional parameters. - `PartialOrderLayerError` - Flow and XZ-corrections errors concerning a specific layer of the partial order. - Additional parameters: - `layer_index` - `layer`
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #396 +/- ##
=======================================
Coverage 86.64% 86.65%
=======================================
Files 44 44
Lines 6149 6150 +1
=======================================
+ Hits 5328 5329 +1
Misses 821 821 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
|
Regarding 55febbe (disabling the QASM parser): see #392 (comment) . |
mgarnier59
reviewed
Jan 7, 2026
Contributor
mgarnier59
left a comment
There was a problem hiding this comment.
Apart from my comment on the object typing in the tests, everything looks good to me, thanks!
mgarnier59
approved these changes
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes the
BackendStateparent class from thesim/base_backendmodule and downstream classes/methods. The intent of this PR is to generalise the simulator requirements, to allow for future additions as plugins or in the Graphix repository itself.Summary of changes
BackendorBackendStateoutputs have now been split into overloaded functions, with concrete return objectsStatevec | DensityMatrix | MBQCTensorNetor backend equivalents. This is because we can no longer returnBackendState(removed) orBackend[_StateT_co](for some typing scope reason I don't quite understand).initialise_backendfunction has been extracted from thePatternSimulatorclass for readability.For discussion
Does this approach meet our requirements? It will force further Graphix PRs or additional external functions if we want to make use of other backends as plugins.