mqt.qecc.circuit_synthesis.synthesis_utils¶
Utility functions for synthesizing circuits.
Functions¶
|
Run a function with a timeout. |
|
Geometrically increases the parameter and timeout until a result is found or the maximum timeout is reached. |
|
Build a quantum circuit consisting of Hadamards followed by a layer of CNOTs from a list of CNOTs and a list of checks. |
|
Return assertion that two symbolic vectors should be equal. |
|
Return True if the overlap of symbolic vector with constant vector is odd. |
|
Multiply a concrete vector by a symbolic scalar. |
|
Add two symbolic vectors. |
|
Measure a stabilizer without flags. The measurement is done in place. |
|
Measure a w-flagged stabilizer. |
|
Measure a 1-flagged stabilizer. |
|
Measure a 2-flagged stabilizer using the scheme of https://arxiv.org/abs/1708.02246 (page 13). |
|
Measure a 2-flagged weight 4 stabilizer. In this case only one flag is required. |
|
Measure a two-flagged weight 6 stabilizer using an optimized scheme. |
|
Measure a w-flagged weight 6 stabilizer using an optimized scheme. |
|
Measure a two-flagged weight 8 stabilizer using an optimized scheme. |
|
Measure a three-flagged weight 8 stabilizer using an optimized scheme. |
|
Measure a two-flagged weight 12 stabilizer using an optimized scheme. |
|
Measure a three-flagged weight 12 stabilizer using an optimized scheme. |
|
Compute the stabilizer measured giving the generators and the measurement variables. |
Module Contents¶
- run_with_timeout(func: Callable[[Any], Any], *args: Any, timeout: int = 10) Any | str | None[source]¶
Run a function with a timeout.
If the function does not complete within the timeout, return None.
- Parameters:
func – The function to run.
args – The arguments to pass to the function.
timeout – The maximum time to allow the function to run for in seconds.
- iterative_search_with_timeout(fun: Callable[[int], Any], min_param: int, max_param: int, min_timeout: int, max_timeout: int, param_factor: float = 2, timeout_factor: float = 2) tuple[Any, int] | None[source]¶
Geometrically increases the parameter and timeout until a result is found or the maximum timeout is reached.
- Parameters:
fun – function to run with increasing parameters and timeouts
min_param – minimum parameter to start with
max_param – maximum parameter to reach
min_timeout – minimum timeout to start with
max_timeout – maximum timeout to reach
param_factor – factor to increase the parameter by at each iteration
timeout_factor – factor to increase the timeout by at each iteration
- build_css_circuit_from_cnot_list(n: int, cnots: list[tuple[int, int]], hadamards: list[int]) QuantumCircuit[source]¶
Build a quantum circuit consisting of Hadamards followed by a layer of CNOTs from a list of CNOTs and a list of checks.
- Parameters:
n – Number of qubits in the circuit.
cnots – List of CNOTs to apply. Each CNOT is a tuple of the form (control, target).
hadamards – List of qubits to apply Hadamards to.
- Returns:
The quantum circuit.
- symbolic_vector_eq(v1: numpy.typing.NDArray[numpy.bool_] | list[z3.BoolRef], v2: numpy.typing.NDArray[numpy.bool_]) z3.BoolRef[source]¶
Return assertion that two symbolic vectors should be equal.
- odd_overlap(v_sym: numpy.typing.NDArray[numpy.bool_], v_con: numpy.typing.NDArray[numpy.int8]) z3.BoolRef[source]¶
Return True if the overlap of symbolic vector with constant vector is odd.
- symbolic_scalar_mult(v: numpy.typing.NDArray[numpy.int8], a: z3.BoolRef | bool) numpy.typing.NDArray[numpy.bool_][source]¶
Multiply a concrete vector by a symbolic scalar.
- symbolic_vector_add(v1: numpy.typing.NDArray[numpy.bool_], v2: numpy.typing.NDArray[numpy.bool_]) numpy.typing.NDArray[numpy.bool_][source]¶
Add two symbolic vectors.
- measure_stab_unflagged(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True) None[source]¶
Measure a stabilizer without flags. The measurement is done in place.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – The qubits to measure.
ancilla – The ancilla qubit to use for the measurement.
measurement_bit – The classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
- measure_flagged(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, t: int, z_measurement: bool = True) None[source]¶
Measure a w-flagged stabilizer.
The measurement is done in place.
- Parameters:
Args
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
t – The number of errors to protect against.
z_measurement – Whether to measure the ancilla in the Z basis.
- measure_one_flagged(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True) None[source]¶
Measure a 1-flagged stabilizer.
In this case only one flag is required.
- measure_two_flagged_general(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True) None[source]¶
Measure a 2-flagged stabilizer using the scheme of https://arxiv.org/abs/1708.02246 (page 13).
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
- measure_two_flagged_4(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True) None[source]¶
Measure a 2-flagged weight 4 stabilizer. In this case only one flag is required.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
- measure_two_flagged_5_or_6(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_5: bool = False) None[source]¶
Measure a two-flagged weight 6 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_5 – Whether the stabilizer has weight 5.
- measure_w_flagged_5_or_6(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_5: bool = False) None[source]¶
Measure a w-flagged weight 6 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_5 – Whether the stabilizer has weight 5.
- measure_two_flagged_7_or_8(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_7: bool = False) None[source]¶
Measure a two-flagged weight 8 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_7 – Whether the stabilizer has weight 7.
- measure_three_flagged_7_or_8(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_7: bool = False) None[source]¶
Measure a three-flagged weight 8 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_7 – Whether the stabilizer has weight 7.
- measure_two_flagged_11_or_12(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_11: bool = False) None[source]¶
Measure a two-flagged weight 12 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_11 – Whether the stabilizer has weight 11.
- measure_three_flagged_12(qc: QuantumCircuit, stab: list[Qubit] | numpy.typing.NDArray[int_], ancilla: AncillaQubit, measurement_bit: Clbit, z_measurement: bool = True, weight_11: bool = False) None[source]¶
Measure a three-flagged weight 12 stabilizer using an optimized scheme.
- Parameters:
qc – The quantum circuit to add the measurement to.
stab – Support of the stabilizer to measure.
ancilla – Ancilla qubit to use for the measurement.
measurement_bit – Classical bit to store the measurement result of the ancilla.
z_measurement – Whether to measure the ancilla in the Z basis.
weight_11 – Whether the stabilizer has weight 11.