Transforms
qiskit_addon_cutting.utils.transforms
Functions for manipulating quantum circuits.
separate_circuit
separate_circuit(circuit, partition_labels=None)
Separate the circuit into its disconnected components.
If partition_labels
is provided, then the circuit will be separated according to those labels. A partition label of None
is treated specially: it must be applied to an unused (idle) qubit, and that qubit will be removed when separating the circuit.
If partition_labels
is None
, then the circuit will be fully separated into its disconnected components, each of which will be labeled with consecutive integers starting with 0. Each idle wire will be eliminated in the resulting circuits.
>>> qc = QuantumCircuit(4)
>>> _ = qc.x(0)
>>> _ = qc.cx(1, 2)
>>> separate_circuit(qc, "ABBA").subcircuits.keys()
dict_keys(['A', 'B'])
>>> separate_circuit(qc, "ABBA").qubit_map
[('A', 0), ('B', 0), ('B', 1), ('A', 1)]
>>> separate_circuit(qc, ["A", "B", "B", None]).qubit_map
[('A', 0), ('B', 0), ('B', 1), (None, None)]
>>> separate_circuit(qc).subcircuits.keys()
dict_keys([0, 1])
>>> separate_circuit(qc).qubit_map
[(0, 0), (1, 0), (1, 1), (None, None)]
>>> separate_circuit(qc, "BAAC").subcircuits.keys()
dict_keys(['B', 'A', 'C'])
>>> separate_circuit(qc, "BAAC").qubit_map
[('B', 0), ('A', 0), ('A', 1), ('C', 0)]
Parameters
- circuit (QuantumCircuit) – The circuit to separate into disconnected subcircuits
- partition_labels (Sequence[Hashable] | None) – A sequence of length
num_qubits
. Qubits with the same label will end up in the same subcircuit.
Return type
SeparatedCircuits
Returns
A SeparatedCircuits
named tuple containing the subcircuits
and qubit_map
.
Raises
- ValueError – The number of partition labels does not equal the number of qubits in the input circuit.
- ValueError – Operation spans more than one partition.
SeparatedCircuits
class SeparatedCircuits(subcircuits, qubit_map)
Bases: NamedTuple
Named tuple for result of separate_circuit()
.
subcircuits
is a dict of circuits, keyed by each partition label. qubit_map
is a list with length equal to the number of qubits in the original circuit. Each element of that list is a 2-tuple which includes the partition label of that qubit, together with the index of that qubit in the corresponding subcircuit. If the original qubit is unused and has been removed from the separated circuits, then that tuple will be equal to (None, None)
.
Create new instance of SeparatedCircuits(subcircuits, qubit_map)
Parameters
- subcircuits (dict[Hashable, QuantumCircuit])
- qubit_map (list[tuple[Hashable, int] | tuple[None, None]])
count
count(value, /)
Return number of occurrences of value.
index
index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
qubit_map
Type: list[tuple[Hashable, int] | tuple[None, None]]
Alias for field number 1
subcircuits
Type: dict[Hashable, QuantumCircuit]
Alias for field number 0