Uh oh!
There was an error while loading. Please reload this page.
Refactor of flow tools - Verification of flow objects - #378
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #378 +/- ##
==========================================
- Coverage 86.31% 86.00% -0.31%
==========================================
Files 44 45 +1 Lines 6183 6476 +293 ==========================================
+ Hits 5337 5570 +233 - Misses 846 906 +60 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
matulni
commented
Nov 28, 2025
Note: the functionality introduced here assumes that the open graph is well formed (currently ensured at instantiation). This should be updated when/if we move away from this design. See #374 (comment) |
emlynsg
left a comment
There was a problem hiding this comment.
LGTM. Very thorough test suite!
mgarnier59
left a comment
There was a problem hiding this comment.
LGTM!
No additional comments.
thierry-martinez
left a comment
There was a problem hiding this comment.
LGTM! Nice work!
Uh oh!
There was an error while loading. Please reload this page.
This PR adds a new method `:func: XZCorrections.check_well_formed` to verify the correctness of XZ-corrections objects. A correct `XZCorrections` instance verifies the following properties: - Keys of the correction dictionaries are measured nodes, i.e., a subset of $O^c$. - Corrections respect the partial order. - The first layer of the partial order contains all the output nodes if there are any. - The partial order contains all the nodes (without duplicates) and it does not have empty layers. This PR builds on the exception classes introduced in #378. We detail next the full exception landscape. ```mermaid --- config: layout: elk elk: mergeEdges: false nodePlacementStrategy: LINEAR_SEGMENTS --- flowchart TD a0(**Exception**) m0(**XZCorrectionsError**) n0(**FlowError**) n1(FlowGenericError) n2(FlowPropositionError) n3(FlowPropositionOrderError) n4(PartialOrderError) n5(PartialOrderLayerError) m1(XZCorrectionsOrderError) m2(XZCorrectionsGenericError) a0 --> m0 a0 --> n0 m0 --POEReason--> n4 m0 --POLEReason--> n5 m0 --XZCOEReason--> m1 m0 --XZCGEReason--> m2 n0 --FGEReason--> n1 n0 --FPEReason--> n2 n0 --FPOEReason--> n3 n0 --POEReason--> n4 n0 --POLEReason--> n5 ``` - Arrows indicate inheritance (from parent to child). - "Reasons" (`XZCorrectionsOrderErrorReason`, etc.) are `Enum` classes. - New error subclasses: - `XZCorrectionsOrderError` - Errors in XZ-corrections objects concerning the correction dictionaries and the partial order. - Additional parameters: - `node` - `correction_set` - `past_and_present_nodes` - `XZCorrectionsGenericError` - Generic errors. - Does not require additional parameters.
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`
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`
* trying to remove BackendState still causing problems * trying to remove BackendState bad fixed version * Fixing typing. * Fixed typing after removing backend state. * Introduce `BaseN` and `PrepareMethod` (#383) 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. * trying to remove BackendState still causing problems * Refactor of flow tools - `OpenGraph.isclose` (#374) 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. * Refactor of flow tools - `OpenGraph.compose` (#375) This commit adapts the existing method `:func: OpenGraph.compose` to the new API introduced in #358. * Fix#349: ensure flow for patterns transpiled from circuit (#362) 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. * Fixing typing. * Refactor of flow tools - Verification of flow objects (#378) 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` * Fixed typing after removing backend state. * trying to rebase * fixed rebasing and conflicts * fixed changelog and vscode * final fix of changelog * aligning changelog * Ruff fixes * added change to CHANGELOG * Fixed typing of str and Backend functions in and * Final typing fix * Remove Any import. * Pushing again to check CI. * Disabled qasm parser CI tests causing Graphix CI to fail. * Added qasm test back in. * Fixed merge from master. * Fixed merge from master. * fixing added code * fixing CI * fixing imports * fixing typing in tests * fixing typing in tests * fixed test typing * fixed test typing * fixed test typing * fixed test typing * fixing merge problems * fixing import issue --------- Co-authored-by: Emlyn Graham <egraham@PTB-02009984.paris.inria.fr> Co-authored-by: thierry-martinez <thierry.martinez@inria.fr> Co-authored-by: matulni <m.uldemolins@gmail.com>
This PR introduces the methods
:func: PauliFlow.check_well_formed,:func: GFlow.check_well_formedand:func: CausalFlow.check_well_formedwhich 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_labelwhich 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 measurementMeasurement(0, Plane.XY)will returnPlane.XYin aGFloworCausalFlowandAxis.Xin aPauliFlow.Additional information on the exception management
Arrows indicate inheritance (from parent to child).
"Reasons" (
FlowPropositionErrorReason,PartialOrderLayerErrorReason, etc.) areEnumclasses.Error subclasses:
FlowPropositionErrornodecorrection_setFlowPropositionOrderErrornodecorrection_setpast_and_present_nodesFlowGenericErrorPartialOrderErrorPartialOrderLayerErrorlayer_indexlayer