pyqonvert.noise

Single qubit gate multiplication and identities elimination.

NoiseInserter(mode)

Provides functionality to insert noise Pragma operations into a circuit based on a given device.

insert_parallel_noise_noise_mapping(circuit, ...)

Parallelize a circuit and insert noise in a noise mapping compatible way.

insert_parallel_noise_noise_mapping_program(...)

Parallelize a QuantumProgram and insert noise in a noise mapping compatible way.

NoiseMappingParallelizer([placement])

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

Functions

insert_parallel_noise_noise_mapping(circuit, ...)

Parallelize a circuit and insert noise in a noise mapping compatible way.

insert_parallel_noise_noise_mapping_program(...)

Parallelize a QuantumProgram and insert noise in a noise mapping compatible way.

Classes

NoiseInserter(mode)

Provides functionality to insert noise Pragma operations into a circuit based on a given device.

NoiseMappingParallelizer([placement])

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

SingleQubitOverrotationAdder([seed])

Provides functionality to insert overrotation noise into a circuit based on overrotation descriptions.

class pyqonvert.noise.NoiseInserter(mode)

Provides functionality to insert noise Pragma operations into a circuit based on a given device.

Based on the information about the noise model for a specific device noise Pragma operations (PragmaNoiseOperation) can be placed in a Circuit to include the noise model in the circuit description.

The added noise is determined from the gate time obtained from a device and the qubit noise rates.

There are three modes of insertions (or in other words noise models) availables:

  • all_qubits - The noise model adds noise on all qubits that are involved in the whole Circuit after each gate operation

  • active_qubits_only - The noise model only adds noise on the qubits that are actively involved in the gate operation after each operation.

  • parallelization_blocks - The noise model only noise on all qubits that that are involved in the whole Circuit after each parallelization block marked by PragmaStopParallelBlock.

A noise inserter using each mode can be created using the corresponding methods all_qubits, active_qubits_only and parallelization_blocks.

Usually noise can be inserted with the insert_noise method providing Circuit and Device references.

add_noise_active_qubits(circuit, device, noise_models)

Add noise Pragmas after gate operations based on device properties.

Adds noise Pragmas (PragmaNoiseOperation) after each gate operation in a Circuit. The added noise is determined from the gate time obtained from a device and the qubit noise rates. The noise model here only adds noise on the qubits that are actively involved in the gate operation.

Parameters:
  • circuit (Circuit) -- The circuit prividing the gate operations that determine the inserted Pragmas.

  • device (GenericDevice) -- The device providing the noise model.

  • noise_models (List[NoiseModel]) -- Noise models determining noise properties. Not used in conversions without noise.

Returns:

The Circuit with inserted PragmaNoiseOperations and the total

execution time.

Return type:

(Circuit, float)

Raises:
  • ValueError -- Could not convert inputs from Python.

  • ValueError -- Could not insert noise Pragmas.

add_noise_all_qubits(circuit, device, noise_models)

Add noise Pragmas after gate operations based on device properties.

Adds noise Pragmas (PragmaNoiseOperation) after each gate operation in a Circuit. The added noise is determined from the gate time obtained from a device and the qubit noise rates. The noise model here adds noise on all qubits that are involved in the whole Circuit.

Parameters:
  • circuit (Circuit) -- The circuit prividing the gate operations that determine the inserted Pragmas.

  • device (GenericDevice) -- The device providing the noise model.

  • noise_models (List[NoiseModel]) -- Noise models determining noise properties. Not used in conversions without noise.

Returns:

The Circuit with inserted PragmaNoiseOperations and the total

execution time.

Return type:

(Circuit, float)

Raises:
  • ValueError -- Could not convert inputs from Python.

  • ValueError -- Could not insert noise Pragmas.

add_noise_parallelization_blocks(circuit, device, noise_models)

Add noise Pragmas after gate operations based on device properties.

Adds noise Pragmas (PragmaNoiseOperation) after each gate operation in a Circuit. The added noise is determined from the gate time obtained from a device and the qubit noise rates. The noise model here adds noise on all qubits that are involved in the whole Circuit after each parallelization block marked by PragmaStopParallelBlock.

Parameters:
  • circuit (Circuit) -- The circuit prividing the gate operations that determine the inserted Pragmas.

  • device (GenericDevice) -- The device providing the noise model.

  • noise_models (List[NoiseModel]) -- Noise models determining noise properties. Not used in conversions without noise.

Returns:

The Circuit with inserted PragmaNoiseOperations and the total

execution time.

Return type:

(Circuit, float)

Raises:
  • ValueError -- Could not convert inputs from Python.

  • ValueError -- Could not insert noise Pragmas.

convert(conversion_input, device, noise_models)

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 -- Could not convert inputs from Python.

  • ValueError -- Could not insert noise Pragmas.

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.

insert_noise(circuit, device)

Inserts noise Pragmas (PragmaNoiseOperation) in circuit.

The noise model or mode of insertion is determined by the mode set in the NoiseInserter. The original circuit is not modified but a new circuit with additional Pragmas is returned.

Parameters:
  • circuit (Circuit) -- The circuit prividing the gate operations that determine the inserted Pragmas.

  • device (GenericDevice) -- The device providing the noise model.

Returns:

The Circuit with inserted PragmaNoiseOperations.

Return type:

Circuit

insert_noise_quantum_program(quantum_program, device)

Insert noise Pragmas (PragmaNoiseOperation) in QuantumProgram.

The noise model or mode of insertion is determined by the mode set in the NoiseInserter. The original circuit is not modified but a new circuit with additional Pragmas is returned.

Parameters:
  • quantum_program (QuantumProgram) -- The QuantumProgram containing the Circuit providing the gate operations that determine the inserted Pragmas.

  • device (GenericDevice) -- The device providing the noise model.

Returns:

with inserted PragmaNoiseOperation.

Return type:

QuantumProgram

Raises:
  • ValueError -- Could not convert inputs from Python.

  • ValueError -- Could not insert noise Pragmas.

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

noise_after_gate()

Set placement of noise Pragmas to after gate.

Returns:

with After placement mode.

Return type:

NoiseInserter

noise_before_gate()

Set placement of noise Pragmas to before gate.

Returns:

with Before placement mode.

Return type:

NoiseInserter

noise_symmetric_around_gate()

Set placement of noise Pragmas to symmetric around gate.

Returns:

with Symmetric placement mode.

Return type:

NoiseInserter

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.noise.NoiseMappingParallelizer(placement=None)

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)

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

return_noise_mapping_circuit()

Sets the return_noise_mapping_circuit flag.

Returns:

The instance of the NoiseMappingParallelizer with the return_noise_mapping_circuit flag set.

Return type:

Self

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.noise.SingleQubitOverrotationAdder(seed=None)

Provides functionality to insert overrotation noise into a circuit based on overrotation descriptions.

The added overrotation is determined from the overrotation description specified by the noise model, that contains the name of the rotation gate and Gaussian statistics to sample an overrotation angle. The overrotation adder (optionally) takes in a positive integer argument as the seed for the random number generator. If a seed is not provided, then a non-deterministic number generator is used.

convert(conversion_input, device, noise_models)

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 conversion of the inputs from Python.

  • ValueError -- Error occured in the overrotation insertion.

static current_version()

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

insert_overrotation(circuit, noise_models)

Insert overrotations (SingleQubitOverrotationOnGate) in circuit.

The added overrotation is determined from the overrotation description specified by the noise model, that contains the name of the rotation gate and Gaussian statistics to sample an overrotation angle. The model here only adds overrotation on the qubits that are specified by their corresponding overrotation description.

Currently, only overrotation on single qubit and two qubit gates is supported. Additionally, only overrotations of the type RotateZ, RotateX, RotateY gates are available.

Parameters:
  • circuit (Circuit) -- The circuit providing the gate operations.

  • noise_models (&[NoiseModel]) -- Noise models determining noise properties including overrotation noise models that dictates how overrotation is added to the circuit.

Returns:

The Circuit with inserted SingleQubitGateOperation corresponding to overrotations.

Return type:

Circuit

Raises:
  • ValueError -- Error occured in the conversion of the inputs from Python.

  • ValueError -- Error occured in the overrotation insertion.

insert_overrotation_quantum_program(quantum_program, noise_models)

Insert overrotations (SingleQubitOverrotationOnGate) in QuantumProgram.

The added overrotation is determined from the overrotation description specified by the noise model, that contains the name of the rotation gate and Gaussian statistics to sample an overrotation angle. The model here only adds overrotation on the qubits that are specified by their corresponding overrotation description.

Currently, only overrotation on single qubit and two qubit gates is supported. Additionally, only overrotations of the type RotateZ, RotateX, RotateY gates are available.

Parameters:
  • quantum_program (QuantumProgram) -- The QuantumProgram containing the Circuit providing the gate operations.

  • noise_models (&[NoiseModel]) -- Noise models determining noise properties including overrotation noise models that dictates how overrotation is added to the quantum program.

Returns:

with inserted SingleQubitGateOperation corresponding to overrotations determined from the noise models.

Return type:

QuantumProgram

Raises:
  • ValueError -- Error occured in the conversion of the inputs from Python.

  • ValueError -- Error occured in the overrotation insertion.

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.noise.insert_parallel_noise_noise_mapping(circuit, device, noise_models, placement=None)

Parallelize a circuit and insert noise in a noise mapping compatible way.

Returns two circuits:

  • The first circuit is a parallelized circuit without decomposition blocks but with PragmaStopParallelBlock annotations. It can be used for further programs.

  • The second circuit is a circuit containing decomposition blocks specifically for noise mapping.

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

  • device (Device) -- The Device containing noise information.

  • noise_models (List[NoiseModel]) -- List of noise models that define noise like continuous background noise or noise on gates.

  • placement (str) -- Where the noise is inserted relative to the gates Available: after, before, symmetric. Default: after.

Returns:

Tuple of the parallelized circuit and the circuit for noise mapping.

Return type:

(Circuit, Circuit)

Raises:
  • RuntimeError -- Error occurred during parallelization or noise mapping.

  • ValueError -- Could not convert inputs from Python.

pyqonvert.noise.insert_parallel_noise_noise_mapping_program(program, device, placement=None)

Parallelize a QuantumProgram and insert noise in a noise mapping compatible way.

The returned program is a parallelized program without decomposition blocks but with PragmaStopParallelBlock annotations.

Note that contrary to insert_parallel_noise_noise_mapping for a Circuit only one QuantumProgram containing PragmaStopParallelBlock annotations is returned. No QuantumProgram with modified PragmaDecompositionBlock statements is returned as that can only be used for noise mapping of Trotter step circuits.

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

  • device (Device) -- The Device containing noise information.

  • placement (str) -- Where the noise is inserted relative to the gates Available: after, before, symmetric. Default: after.

Returns:

The parallelized program.

Return type:

QuantumProgram

Raises:
  • RuntimeError -- Error occurred during parallelization or noise mapping.

  • ValueError -- Could not convert inputs from Python.