You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 457a351
Browse filesBrowse the repository at this point in the historyBrowse files
This PR addresses #580. The PR comprises three blocks:
## Block 1: Introduction of ancilla qubits
Concerns `graphix.transpiler.py` only.
**Now it's possible to distinguish between input and ancilla qubits in circuits.**
- Two new attributes are added to the `Circuit` class:
- `ancillas: int` to indicate the number of ancilla qubits. Ancilla qubits are indexed from `range(width, width + ancillas - 1)`, where `width` is the number of input qubits (existing attribute).
- `ancilla_state: State` to indicate the state of the ancilla qubits.
- Supported operations on circuits with ancillas:
- Simulation: always
- Transpilation to pattern or causal flow: only if `ancilla_state` is a `BasicState`:
- If `ancilla_state` is `BasicState.PLUS`, ancilla qubits are represented as non-input nodes in the open graph.
- Any other `BasicState` is transpiled into `BasicState.PLUS` by prepending the appropriate gates to the circuit (via `Circuit.transpile_ancilla_state`). This is unavoidable because transpilation is carried out by first constructing an open graph with causal flow, and non-input nodes in `OpenGraph` always represent `BasicState.PLUS` qubits, even if Graphix supports `N` commands with an arbitrary state.
- QASM 3 export: only if `ancilla_state` is a `BasicState`. Same mechanism as for transpilation but transforming to state |0>.
- Note: this addition is a first step towards implementing circuit compilation of PDDAGs representing isometries.
## Block 2: Introduction of conditional instructions
Concerns `graphix.instruction.py` and `graphix.transpiler.py`.
**Now it's possible to represent conditional instructions in circuits.**
- A new instruction `CONDINSTR` is added. This instruction bundles a sequence of instructions (possibly incuding other `CONDINSTR`) and a qubit domain (`set[int]`). The instruction sequence is applied when the XOR of the measurement outcomes of the qubits in ``domain`` evaluates to ``1``.
- Two side modifications:
- #### `InstructionVisitor`
- `InstructionVisitor` now has an additional method `visit_domain`. The method `CONDINSTR.visit` visits the instruction's domain **and** all the instructions in the instruction sequence.
- Introduced a new `_InstructionValidatorVisitor(InstructionVisitor)` class. This visitor reimplements the method `visit_qubit` and `visit_domain` so that calling `visit` for a given instruction checks the qubit validity. As a result:
1) Valid-qubit sanity checks are factorized into a single function.
2) There is a generic way to check the validity of any `InstructionKind`, without knowing which specific instruction it is. This allows to verify the validity of conditional instructions containing a sequence of other instructions.
- Checking that multi-qubit gates don't act on repeated qubits is delegated to the method `visit` of the corresponding instructions instead of the `Circuit` methods.
- #### `graphix.utils.check_kind`
- The function `graphix.utils.check_kind` has been slightly modified to fix an error due to the self-reference in the definition of `CONDINSTR`. This modification is an LLM suggestion, it's a bit obscure.
- Supported operations on circuits with conditional instructions:
- Simulation: always.
- Simulation is **very inefficient**: all qubits are instantianted at the beginning.
- Exisiting simulation logic is encapsulated in a new function `simulate_instructions` that is called recursively for `CONDINSTR`.
- Changes in simulation are minimal to support testing conditional instructions and keeping the PR as small as possible. In a future PR we'll address the following:
- Simulation logic should be moved to `simulator` module.
- Currently we are rewriting some code exisiting in `MeasureMethod`.
- How to handle classical output results ?
- Now keeping `classical_outputs` to achieve a minimal PR.
- Ideally we should find a common interface for pattern and circuit simulation.
- Transpilation to pattern or causal flow: always.
- Required logic is encapsulated in `Circuit.transpile_condinstr` that is called from exisiting transpilation methods when there is any conditional instruction in the circuit.
- Conditional instructions are replaced by controlled instructions, using measurements of their domain qubits in the $Z$ basis as control conditions. Measurements are moved to the end of the circuit. When the domain of the conditional instruction comprises various qubits (whose measurement outputs are xored), they are combined by chaining CNOT gates).
- QASM 3 export: always (implemented by @thierry-martinez).
## Block 3: Introduction of a `Pattern.to_circuit` method.
Concerns `graphix.pattern.py`
- This method requires the changes in block 1 and block 2.
- Logic is similar to existing `Pattern.to_qasm3`, with two differences:
- Swap gates are added at the end of circuit to ensure that active qubits are in the same order as output nodes in the pattern. This guarantees that a pattern and its circuit produce the same state up to a phase.
- Qubits are labelled with consecutive integers starting from 0. In the qasm export, we label qubits with the same node labels.
- `Pattern.to_qasm3` should be refactored to be a wrapper over `Pattern.to_circuit().to_qasm3`
---------
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
- Added `Pattern.to_circuit` method to convert a `Pattern` into a `Circuit` with ancillas and classical control.
24
+
20
25
### Fixed
21
26
22
27
-#591: `FixedBranchSelector` now passes its RNG parameter to its `default` branch selector.
23
28
24
-
-#595: `RZZ` gates are no longer incorrectly exported as `crz`; transpilation to `CNOT`-`RZ`-`CNOT` is provided.
25
-
26
29
-#596, #597: Pattern's `n_node` property updated after Pauli removal.
27
30
28
-
## Changed
31
+
-#595: Fixed the export of circuit measurements and `RZZ` gates to OpenQASM. `RZZ` gates are no longer incorrectly exported as `crz`; transpilation to `CNOT`-`RZ`-`CNOT` is provided.
32
+
33
+
-#592:
34
+
- Added the following gates specified in the OpenQASM 3.0 specification: SDG, T, TDG, SX, SXDG, CY, P, U, CP, CRX, CRY, CRZ, CU, CSWAP, and GPHASE.
35
+
- Subsumed `Circuit.transpile_measurements_to_z_axis`, `Circuit.transpile_j_to_rzh` and `Circuit.transpile_rzz` by `Circuit.transpile_to_qasm_gates`
29
36
30
-
-#601: New documentation / tutorial
37
+
### Changed
38
+
39
+
-#587;
40
+
- Factorized instruction-validity checks in method `Circuit.add` via an instruction visitor.
41
+
- Instruction methods of the `Circuit` class now return `self` allowing method chaining.
Copy file name to clipboardExpand all lines: COMPATIBILITY.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,11 @@
2
2
3
3
Graphix does not guarantee backwards compatibility between 0.x version releases. Here we list API changes which may break existing code using Graphix.
4
4
5
+
## Unreleased
6
+
7
+
-#592:
8
+
-`Circuit.transpile_measurements_to_z_axis`, `Circuit.transpile_j_to_rzh` and `Circuit.transpile_rzz` are subsumed by `Circuit.transpile_to_qasm_gates`
"""Base class for conditional circuit instructions.
1110
+
1111
+
Conditional measurements are not well defined since they would result in circuits with an indeterminate number of qubits. Therefore, the attribute ``instructions`` cannot contain instances of `Instruction.M`.
0 commit comments