pyqonvert.routing
SWAP operations insertion for limited connectivity devices.
|
Helper to keep track of current layout of logical qubits on physical qubits. |
|
Converter that inserts SWAP operations in Circuit to enable operations on limited connectivity. |
|
Insert SWAP operations in Circuit to enable operations on limited connectivity. |
Insert SWAP operations in QuantumProgram to enable operations on limited connectivity. |
Functions
|
Insert SWAP operations in Circuit to enable operations on limited connectivity. |
Insert SWAP operations in QuantumProgram to enable operations on limited connectivity. |
Classes
|
Helper to keep track of current layout of logical qubits on physical qubits. |
|
Converter that inserts SWAP operations in Circuit to enable operations on limited connectivity. |
- class pyqonvert.routing.Layout(number_qubits)
Helper to keep track of current layout of logical qubits on physical qubits.
Used internally to keep track of current layout during routing
- is_trivial()
Return true when Layout is trivial i:i.
- Returns:
whether the Layout is trivial or not.
- Return type:
bool
- logical_to_physical()
Return the logical_to_physical dictionary of the Layout.
- Returns:
The dictionary of {qubit: qubit} elements.
- Return type:
dict[int, int]
- physical_to_logical()
Return the physical_to_logical dictionary of the Layout.
- Returns:
The dictionary of {qubit: qubit} elements.
- Return type:
dict[int, int]
- swap_physical(control, target)
Update Layout for a SWAP of two physical qubits.
- Parameters:
control (int) -- The control qubit.
target (int) -- The target qubit.
- class pyqonvert.routing.SingleOperationSwapRouter(swap_back, only_before_decomposition)
Converter that inserts SWAP operations in Circuit to enable operations on limited connectivity.
Noise mapping becomes difficult when circuit operations are remapped inside a Decomposition block. On the other hand swapping back after routing for each single operation is highly inefficient.
Often the majority of Decomposition blocks only involve one or two qubit operations. To save the amount of SWAPS and enable remapping without breaking noise mapping, the SWAPS can be inserted only before decomposition blocks that invovle one and two qubits and remapping all following operations. This is activated with the only_before_decomposition option. With this option the SWAPS will also be inserted as decomposition blocks which is necessary for noise mapping when the SWAPS occur between decomposition blocks.
Note that this can not route all operations in the Circuit (especially decomposition blocks involving more qubits in the first place). For full routing a second pass with swap_back=true is necessary.
- convert(conversion_input, device, noise_models=None)
Convert Circuits or QuantumPrograms for decomposition, optimization and adding noise.
- Parameters:
conversion_input -- Circuit or QuantumProgram to be converted.
device (Device) -- determines connectivity and gate times.
noise_models (List[NoiseModel]) -- Noise models determining noise properties. Not used in conversions without noise.
- Returns:
Output of converted Circuit when input is a Circuit. QuantumProgram: Output of converted QuantumProgram when input is a QuantumProgram.
- Return type:
Circuit
- Raises:
RuntimeError - Error occured in the conversion of the inputs. --
- static current_version()
Returns the current version of the pyqonvert library .
- Returns:
The current version of the library.
- Return type:
str
- static from_bincode(input)
Convert the bincode representation of the Converter to a Converter using the [bincode] crate.
- Parameters:
input (ByteArray) -- The serialized Converter (in [bincode] form).
- Returns:
The deserialized Converter.
- Return type:
Converter
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized to Converter.
- static from_json(json_string)
Convert the json representation of a Converter to a Converter.
- Parameters:
input (str) -- The serialized Converter in json form.
- Returns:
The deserialized Converter.
- Return type:
Converter
- Raises:
ValueError -- Input cannot be deserialized to Converter.
- static json_schema()
Return the JsonSchema for the json serialisation of the class.
- Returns:
The json schema serialized to json
- Return type:
str
- min_supported_version()
Return the minimum version of pyqonvert that supports this object.
- Returns:
The minimum version of the pyqonvert library to deserialize this object.
- Return type:
str
- to_bincode()
Return the bincode representation of the Converter using the [bincode] crate.
- Returns:
The serialized Converter (in [bincode] form).
- Return type:
ByteArray
- Raises:
ValueError -- Cannot serialize Converter to bytes.
- to_json()
Return the json representation of the Converter.
- Returns:
The serialized form of Converter.
- Return type:
str
- Raises:
ValueError -- Cannot serialize Converter to json.
- pyqonvert.routing.insert_single_operation_swaps(circuit, device, swap_back, only_before_decomposition, initial_layout=None)
Insert SWAP operations in Circuit to enable operations on limited connectivity.
Noise mapping becomes difficult when circuit operations are remapped inside a Decomposition block. On the other hand swapping back after routing for each single operation is highly inefficient.
Often the majority of Decomposition blocks only involve one or two qubit operations. To save the amount of SWAPS and enable remapping without breaking noise mapping, the SWAPS can be inserted only before decomposition blocks that invovle one and two qubits and remapping all following operations. This is activated with the only_before_decomposition option. With this option the SWAPS will also be inserted as decomposition blocks which is necessary for noise mapping when the SWAPS occur between decomposition blocks.
Note that this can not route all operations in the Circuit (especially decomposition blocks involving more qubits in the first place). For full routing a second pass with swap_back=true is necessary.
- Parameters:
circuit (Circuit) -- The circuit that is routed.
device (GenericDevice) -- The device determining the topology.
swap_back (bool) -- Whether to insert SWAPS to original layout or remap.
only_before_decomposition (bool) -- Only insert SWAPS before two qubit decomposition blocks.
- Raises:
RuntimeError -- Could not convert inputs.
ValueError -- Could not find a suitable routing.
- Returns:
The circuit with inserted SWAPs and the corresponding layout.
- Return type:
(Circuit, Layout)
- pyqonvert.routing.insert_single_operation_swaps_program(quantum_program, device, swap_back, only_before_decomposition)
Insert SWAP operations in QuantumProgram to enable operations on limited connectivity.
- Parameters:
quantum_program (QuantumProgram) -- The quantum program that is routed.
device (GenericDevice) -- The device determining the topology.
swap_back (bool) -- Whether to insert SWAPS to original layout or remap.
only_before_decomposition (bool) -- Only insert SWAPS before two qubit decomposition blocks
- Raises:
RuntimeError -- Could not convert inputs.
ValueError -- Could not find a suitable routing.
- Returns:
the routed QuantumProgram.
- Return type:
QuantumProgram