pyqonvert.optimization

Single qubit gate multiplication and identities elimination.

numeric_single_qubit_multiplication(circuit, ...)

Optimize circuit by multiplying non-symbolic single-qubit-gates.

numeric_single_qubit_multiplication_quantum_program(...)

Optimize QuantumProgram by multiplying non-symbolic single-qubit-gates.

eliminate_identities(circuit, identity_tolerance)

Optimize circuit by eliminating identity gates.

eliminate_identities_quantum_program(...)

Optimize QuantumProgram by eliminating identity gates.

virtual_z_replacement(input)

Optimize a circuit or QuantumProgram by multiplying non-symbolic single-qubit-gates.

CircuitParallelizer()

Converter that optimizes circuit or QuantumProgram by regrouping operations into parallel execution blocks.

IdentityRemover(identity_tolerance)

Converter that optimizes circuit or QuantumProgram by eliminating identities.

VirtualZGateReplacement()

Converter that applies virtual Z gate optimization.

SleepInserter(gates, involved_qubits, sleep_time)

Converter that adds a PragmaSleep operation before or after a gate, depending on the user inputs.

Functions

eliminate_identities(circuit, identity_tolerance)

Optimize circuit by eliminating identity gates.

eliminate_identities_quantum_program(...)

Optimize QuantumProgram by eliminating identity gates.

numeric_single_qubit_multiplication(circuit, ...)

Optimize circuit by multiplying non-symbolic single-qubit-gates.

numeric_single_qubit_multiplication_quantum_program(...)

Optimize QuantumProgram by multiplying non-symbolic single-qubit-gates.

virtual_z_replacement(input)

Optimize a circuit or QuantumProgram by multiplying non-symbolic single-qubit-gates.

Classes

CircuitParallelizer()

Converter that optimizes circuit or QuantumProgram by regrouping operations into parallel execution blocks.

IdentityRemover(identity_tolerance)

Converter that optimizes circuit or QuantumProgram by eliminating identities.

MultipleRotationGateSimplifier()

Converter that optimizes a Circuit or a QuantumProgram by adding up identical Rotation gates in separate DecompositionBlocks.

NumericSingleQubitMultiplier(identity_tolerance)

Converter that optimizes a Circuit or a QuantumProgram by multiplying non-symbolic single-qubit-gates

SleepInserter(gates, involved_qubits, sleep_time)

Converter that adds a PragmaSleep operation before or after a gate, depending on the user inputs.

VirtualZGateReplacement()

Converter that applies virtual Z gate optimization.

class pyqonvert.optimization.CircuitParallelizer

Converter that optimizes circuit or QuantumProgram by regrouping operations into parallel execution blocks.

Each parallel execution block is terminated by a PragmaStopParallelBlock operation. The execution time of the parallel block is extracted from the properties of a device.

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. --

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.

class pyqonvert.optimization.IdentityRemover(identity_tolerance)

Converter that optimizes circuit or QuantumProgram by eliminating identities.

Identity is identified by 1 - gate.alpha_r <= identity_tolerance.

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. --

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.

class pyqonvert.optimization.MultipleRotationGateSimplifier

Converter that optimizes a Circuit or a QuantumProgram by adding up identical Rotation gates in separate DecompositionBlocks.

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. --

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.

class pyqonvert.optimization.NumericSingleQubitMultiplier(identity_tolerance)

Converter that optimizes a Circuit or a QuantumProgram by multiplying non-symbolic single-qubit-gates

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:
  • ValueError - Error occured in the converting the inputs from Python.. --

  • RuntimeError - Error occured in the conversion. --

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.

class pyqonvert.optimization.SleepInserter(gates, involved_qubits, sleep_time, placement=None)

Converter that adds a PragmaSleep operation before or after a gate, depending on the user inputs.

The PragmaSleep will only be added to gates that have at least one involved qubit of the input and are of the gate type specified in the input. The placement depends on the placement input (before/after).

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 when running the SleepInserter. --

  • ValueError -- Could not convert 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.

class pyqonvert.optimization.VirtualZGateReplacement

Converter that applies virtual Z gate optimization.

On platforms where the RotateXY gate is available and the natural two-qubit gate is diagonal in the Z-basis, it is possible to replace RotateZ gates by virtual changes (rotations) of the qubit basis in the XY-Plane. This is what we implement here.

This is also referred to as VirtualRotateZ gates optimisation in the literature.

apply_final_rotz(apply_final_rotz)

Change whether the VirtualZGateReplacement applies RotateZ gates at the end of the circuit.

When true, at the end of the circuit, the changes in the qubit basis that have been picked up during the circuit will be undone with RotateZ`gates. This is not necessary when the qubits are measured immediately afterwards. The `apply_final_rotz parameter only affects conversions of Circuits, not QuantumPrograms.

Parameters:

apply_final_rotz (bool) -- Whether to apply RotateZ gates at the end of a Circuit.

Returns:

self instance with modified apply_final_rotz boolean.

Return type:

Self

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.

  • ValueError -- Error in the VirtualZGateReplacement optimisation.

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.optimization.eliminate_identities(circuit, identity_tolerance)

Optimize circuit by eliminating identity gates.

Parameters:
  • circuit (Circuit) -- The circuit that is optimized.

  • identity_tolerance (float) -- Tolerance for identifying a single qubit gate with identity. If gate.alpha_r <= identity_tolerance the gate is taken to be the identity.

Returns:

without identity gates.

Return type:

Circuit

Raises:
  • ValueError -- The input cannot be converted to a Circuit.

  • RuntimeError -- Error during optimization.

pyqonvert.optimization.eliminate_identities_quantum_program(quantum_program, identity_tolerance)

Optimize QuantumProgram by eliminating identity gates.

Parameters:
  • program (QuantumProgram) -- The circuit that is optimized.

  • identity_tolerance (float) -- Tolerance for identifying a single qubit gate with identity. If gate.alpha_r <= identity_tolerance the gate is taken to be the identity.

Returns:

without identity gates.

Return type:

QuantumProgram

Raises:
  • ValueError -- The input cannot be converted to a QuantumProgram.

  • RuntimeError -- Error during optimization.

pyqonvert.optimization.numeric_single_qubit_multiplication(circuit, identity_tolerance)

Optimize circuit by multiplying non-symbolic single-qubit-gates.

Parameters:
  • circuit (Circuit) -- The circuit that is optimized..

  • identity_tolerance (float) -- Tolerance for identifying a single qubit gate with identity. If gate.alpha_r <= identity_tolerance the gate is taken to be the identity.

Returns:

with multiplied non-symbolic single-qubit-gates.

Return type:

Circuit

pyqonvert.optimization.numeric_single_qubit_multiplication_quantum_program(quantum_program, identity_tolerance)

Optimize QuantumProgram by multiplying non-symbolic single-qubit-gates.

Args

program (QuantumProgram): The QuantumProgram that is optimized. identity_tolerance (float) Tolerance for identifying a single qubit gate with identity.

If gate.alpha_r <= identity_tolerance the gate is taken to be the identity.

Returns:

with multiplied non-symbolic single-qubit-gates.

Return type:

QuantumProgram

pyqonvert.optimization.virtual_z_replacement(input)

Optimize a circuit or QuantumProgram by multiplying non-symbolic single-qubit-gates.

Parameters:

input (Union[Circuit, QuantumProgram]) -- The circuit or quantum program to which the virtual Z approach is applied.

Returns:

The Circuit/QuantumProgram with replaced gates.

Return type:

Union[Circuit, QuantumProgram]