hqs_noise_app.HqsNoiseApp

class hqs_noise_app.HqsNoiseApp

Create a new HqsNoiseApp.

Example

>>> from hqs_noise_app import HqsNoiseApp
... noise_app = HqsNoiseApp()
Returns:

A new HqsNoiseApp object.

__init__()

Methods

__init__()

add_noise(program, device, noise_models)

Adds device specific noise to QuantumProgram created by HqsNoiseApp.

compile_program(program, device)

Compiles a QuantumProgram created by HqsNoiseApp for a device & setting in the HqsNoiseApp.

from_bincode(input)

Convert the bincode representation of the HqsNoiseApp to a HqsNoiseApp using the [bincode] crate.

from_json(input)

Convert the json representation of a HqsNoiseApp to a HqsNoiseApp.

noisy_algorithm_model(trotter_timestep, device)

Returns the noisy algorithms noise model derived for a given Hamiltonian.

quantum_program(hamiltonian, ...)

Creates a qoqo QuantumProgram for observable measurement after time propagation.

system_bath_execution_time(hamiltonian, ...)

Returns the execution time of one Trotterstep.

system_bath_noisy_algorithm_model(...[, ...])

Returns the noisy algorithms noise model derived for a given Hamiltonian.

system_bath_quantum_program(hamiltonian, ...)

Creates a qoqo QuantumProgram for observable measurement after time propagation.

system_bath_trotter_circuit_depth(...[, ...])

Returns the depth of the circuit that implements one Trotter step.

to_bincode()

Return the bincode representation of the HqsNoiseApp using the [bincode] crate.

to_json()

Return the json representation of the HqsNoiseApp.

trotter_circuit_depth(trotter_timestep, device)

Returns the depth of the circuit that implements one Trotter step.

unroll_quantum_program(program, ...[, ...])

Unrolls quantum program that has an internal PragmaLoop.

Attributes

algorithm

Setter for the algorithm setting for HqsNoiseApp

noise_symmetrization

Set the noise symmetrization option for HqsNoiseApp

number_measurements

Setter for the number of projective measurements used when measuring observables

parallelization_blocks

Setter for the parallelization blocks for noise insertion.

trotterization_order

Setter for the Trotterization order for HqsNoiseApp

use_bath_as_control

Setter for the value of option use_bath_as_control

add_noise(program, device, noise_models)

Adds device specific noise to QuantumProgram created by HqsNoiseApp.

Parameters:
  • program (QuantumProgram) -- QuantumProgram without noise PRAGMA operations.

  • device (qoqo.Device) -- Device defining the connectivity and available gates.

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

Returns:

The QuantumProgram with added noise in the form of noise PRAGMA operations

in the circuits in the program

Return type:

QuantumProgram

Raises:

RuntimeError -- Inserting noise failed.

algorithm

Setter for the algorithm setting for HqsNoiseApp

Four Options are available:
ParityBased: An algorithm that implements the time evolution under a product of PauliOperators

via the total Parity of the set of involved qubits. The total parity is perpared in the last involved qubit.

QSWAP: Terms in the Hamiltonian involving two qubits are implemented using a swap network

that reorders the terms. Uses the ParityBased algorithm for multi qubit terms.

QSWAPMolmerSorensen: The QSWAP algorithm using variable angle Mølmer Sørensen XX interaction

gates

VariableMolmerSorensen: An algorithm that implements terms in the Hamiltonian

involving two qubits with a basis change and variable angle Mølmer Sørensen gates

Parameters:

algorithm (str) -- The option for the algorithm that is set

compile_program(program, device)

Compiles a QuantumProgram created by HqsNoiseApp for a device & setting in the HqsNoiseApp.

Parameters:
  • program (QuantumProgram) -- The uncompiled QuantumProgram.

  • device (qoqo.Device) -- Device defining the connectivity and available gates.

Returns:

The QuantumProgram compiled for fhe available one and two-qubit gates,

given by the device.

Return type:

QuantumProgram

Raises:

RuntimeError -- Inserting noise failed.

static from_bincode(input)

Convert the bincode representation of the HqsNoiseApp to a HqsNoiseApp using the [bincode] crate.

Parameters:

input (ByteArray) -- The serialized HqsNoiseApp (in [bincode] form).

Returns:

The deserialized HqsNoiseApp.

Return type:

HqsNoiseApp

Raises:
  • TypeError -- Input cannot be converted to byte array.

  • ValueError -- Input cannot be deserialized to HqsNoiseApp.

static from_json(input)

Convert the json representation of a HqsNoiseApp to a HqsNoiseApp.

Parameters:

input (str) -- The serialized HqsNoiseApp in json form.

Returns:

The deserialized HqsNoiseApp.

Return type:

HqsNoiseApp

Raises:

ValueError -- Input cannot be deserialized to HqsNoiseApp.

noise_symmetrization

Set the noise symmetrization option for HqsNoiseApp

Noise symmetrization controls whether the Trotterstep is symmetrized with respect to damping noise. When the overall noise has the tendency to favor one state |0> or |1>, the Trotterstep can be symmetrized by doubling the Trotter circuit and flipping the definition of |0> and |1> for the second circuit. This process will bring the effective noise closer to a balanced noise at the cost of incuring larger decoherence overall.

Parameters:

noise_symmetrization (bool) -- The option for the noise symmetrization that is set

noisy_algorithm_model(trotter_timestep, device)

Returns the noisy algorithms noise model derived for a given Hamiltonian.

Constructs the quantum circuit for a time propagating under a Hamiltonian with the algorithm parameters set in the HqsNoiseApp. Performs the noise mapping from discrete noise operations after each operation in the circuit to the effective noise model. The function will automatically compile the Circuit to the available one and two-qubit gates, and apply noise.

Example:

>>> from qoqo import Circuit
... from qoqo import operations
... from qoqo.devices import AllToAllDevice
... from hqs_noise_app import HqsNoiseApp
... from struqture_py.spins import PauliProduct, PauliHamiltonian
...
... noise_app = HqsNoiseApp()
... hamiltonian = PauliHamiltonian()
... # A XX interaction between spins 0 and 1 and spins 1 and 0
... hamiltonian.set(PauliProduct().x(0).x(1), 1.0)
... # A XX interaction between spins 1 and 2 and spins 1 and 0
... hamiltonian.set(PauliProduct().x(1).x(2), 1.0)
...
... device = AllToAllDevice(4, ["RotateX", "RotateY", "RotateZ"], ["CNOT"], 1.0)
...
... noise_model = noise_app.noisy_algorithm_model(hamiltonian, 0.001, device)

Note that the superoperator corresponds to the continuous time evolution of a density matrix but has been derived from a Trotterstep with a discrete time-step. This approximation is only valid if the time-step is short enough compared to the energy scales in the system that the Trotterization errors of the unitary evolution and the noise terms are small.

Parameters:
  • hamiltonian (PauliHamiltonian) -- The Hamiltonian for which the noise algorithm model is created.

  • trotter_timestep (float) -- The simulation time the circuit propagates the simulated system

  • device (qoqo.Device) -- The device determining the topology and the physical noise

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

Returns:

The noise model.

Return type:

PauliLindbladNoiseOperator

Raises:
  • ValueError -- Could not convert hamiltonian input.

  • ValueError -- Could not convert device input.

  • RuntimeError -- Extracting effective noise model failed.

  • TypeError -- Wrong input type for noisy_algorithm_model.

number_measurements

Setter for the number of projective measurements used when measuring observables

Parameters:

number_measurements (int) -- The new number of measurements

parallelization_blocks

Setter for the parallelization blocks for noise insertion.

This controls the noise_mode of the HqsNoiseApp:
If the parallelization input is false: the noise mode remains as AllQubits, which

is the default. In this case, the noise model adds noise on all qubits that are involved in the whole quantum circuit after each gate operation.

If the parallelization input is true, the noise mode is changed to

ParallelizationBlocks. In this case, the noise model adds noise on the qubits that are involved in a block or parallel operations. These noise is added after a PragmaStopParallelBlock that notifies the end of the parallel operations in a qoqo circuit.

Parameters:

parallelization (bool) -- The boolean indicating whether to use parallelization blocks for noise insertion, instead of noise on all qubits.

quantum_program(hamiltonian, trotter_timestep, initialisation, measured_operators, operator_names, device)

Creates a qoqo QuantumProgram for observable measurement after time propagation.

The QuantumProgram will

  • Initialize a spin state on a quantum computer

  • Time propagte the spin state with a quantum algorithm

  • Measure the values of spin observables

The parameters of the algorithm are taken from the NoiseApp. The hamiltonian, observables and the device the QuantumProgram is created for are parameters of the function.

The initialisation is not universal, but limited to manipulating single spins.

For a N-qubit probem the state starts out in N times |0> or |spin-up>. The initialisation proved N float values. One fj for each spin j. For each qubit j a RotateY(j, f * pi) is applied. So an fj value of 1.0 would flip the spin j from |spin-up> to |spin-down>

Note that a device needs to have at least N qubits or no quantum program can be constructed.

Parameters:
  • hamiltonian (PauliHamiltonian) -- The Spin Hamiltonian.

  • trotter_timestep (float) -- One Trotterstep propagates the system under the hamiltonian for this time. Smallest time increment when running simulations.

  • initialisation (List[float])

  • measured_operators (List[PauliOperator]) -- All the observables that are measured.

  • operator_names (List[str]) -- The names of the measured operators.

  • device (qoqo.Device) -- The device determining topology and noise.

Returns:

the created quantum program from inputs.

Return type:

QuantumProgram

Raises:
  • TypeError -- Could not convert hamiltonian input.

  • TypeError -- Could not convert device input.

  • TypeError -- Could not convert measured_operators input.

system_bath_execution_time(hamiltonian, trotter_timestep, device, logical_to_physical_system=None, logical_to_physical_bath=None, bath_qubit_connectivity=None)

Returns the execution time of one Trotterstep.

Constructs the quantum circuit for a time propagating under a Hamiltonian with the algorithm parameters set in the HqsNoiseApp. The function will automatically compile the Circuit to the available one and two-qubit gates, and apply noise.

Example:

>>> from qoqo import Circuit
... from qoqo import operations
... from qoqo.devices import AllToAllDevice
... from hqs_noise_app import HqsNoiseApp
... from struqture_py.mixed_systems import HermitianMixedProduct, MixedHamiltonian
...
... noise_app = HqsNoiseApp()
... hamiltonian = MixedHamiltonian(2, 0, 0)
... # A XX interaction between spins 0 and 1 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["0X1X", ""], [], []), 1.0)
... # A XX interaction between spins 1 and 2 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["1X2X", ""], [], []), 1.0)
... hamiltonian.set(HermitianMixedProduct(["0Z", "0Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["1Z", "1Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["2Z", "2Z"], [], []), 0.1)
... device = AllToAllDevice(9, ["RotateX", "RotateY", "RotateZ"], ["CNOT"], 1.0)
...
... _noise_model_execution_time = noise_app.system_bath_execution_time(hamiltonian, 0.001, device)
```

The number of qubits in the problem depends on the number of spins in system and bath and the algorithm chosen. For a QSWAP algorithms the number of qubits is three times the maximum of the number of system spins Nsys and the number of bath spins Nbath devided by 2. N = 3 * max(Nsys, Nbath / 2).

Note that a device needs to have at least N qubits or no quantum program can be constructed.

Parameters:
  • hamiltonian (MixedHamiltonian) -- The Hamiltonian for which the noise algorithm model is created.

  • trotter_timestep (float) -- The simulation time the circuit propagates the simulated system

  • device (qoqo.Device) -- The device determining the topology and the physical noise

  • logical_to_physical_system (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the system.

  • logical_to_physical_bath (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the bath.

  • bath_qubit_connectivity (Optional[Dict[int, List[int]]]) -- Optional connectivity between physical system and bath qubits.

Returns:

PauliLindbladNoiseOperator The noise model.

Raises:
  • TypeError -- Could not convert hamiltonian input.

  • RuntimeError -- Extracting effective noise model failed.

system_bath_noisy_algorithm_model(hamiltonian, trotter_timestep, device, noise_models, logical_to_physical_system=None, logical_to_physical_bath=None, bath_qubit_connectivity=None)

Returns the noisy algorithms noise model derived for a given Hamiltonian.

Constructs the quantum circuit for a time propagating under a Hamiltonian with the algorithm parameters set in the HqsNoiseApp. Performs the noise mapping from discrete noise operations after each operation in the circuit to the effective noise model. The function will automatically compile the Circuit to the available one and two-qubit gates, and apply noise.

Example:

>>> from qoqo import Circuit
... from qoqo import operations
... from qoqo.devices import AllToAllDevice
... from hqs_noise_app import HqsNoiseApp
... from struqture_py.mixed_systems import HermitianMixedProduct, MixedHamiltonian
...
... noise_app = HqsNoiseApp()
... hamiltonian = MixedHamiltonian(2, 0, 0)
... # A XX interaction between spins 0 and 1 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["0X1X", ""], [], []), 1.0)
... # A XX interaction between spins 1 and 2 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["1X2X", ""], [], []), 1.0)
... hamiltonian.set(HermitianMixedProduct(["0Z", "0Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["1Z", "1Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["2Z", "2Z"], [], []), 0.1)
... device = AllToAllDevice(9, ["RotateX", "RotateY", "RotateZ"], ["CNOT"], 1.0)
...
... _noise_model = noise_app.system_bath_noisy_algorithm_model(hamiltonian, 0.001, device)
```

Note that the superoperator corresponds to the continuous time evolution of a density matrix but has been derived from a Trotterstep with a discrete time-step. This approximation is only valid if the time-step is short enough compared to the energy scales in the system that the Trotterization errors of the unitary evolution and the noise terms are small.

The number of qubits in the problem depends on the number of spins in system and bath and the algorithm chosen. For a QSWAP algorithms the number of qubits is three times the maximum of the number of system spins Nsys and the number of bath spins Nbath devided by 2. N = 3 * max(Nsys, Nbath / 2).

Note that a device needs to have at least N qubits or no quantum program can be constructed.

Parameters:
  • hamiltonian (MixedHamiltonian) -- The Hamiltonian for which the noise algorithm model is created.

  • trotter_timestep (float) -- The simulation time the circuit propagates the simulated system

  • device (qoqo.Device) -- The device determining the topology and the physical noise

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

  • logical_to_physical_system (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the system.

  • logical_to_physical_bath (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the bath.

  • bath_qubit_connectivity (Optional[Dict[int, List[int]]]) -- Optional connectivity between physical system and bath qubits.

Returns:

The noise model.

Return type:

PauliLindbladNoiseOperator

Raises:
  • TypeError -- Could not convert hamiltonian input.

  • RuntimeError -- Extracting effective noise model failed.

system_bath_quantum_program(hamiltonian, trotter_timestep, initialisation, measured_operators, operator_names, device, logical_to_physical_system=None, logical_to_physical_bath=None, bath_qubit_connectivity=None)

Creates a qoqo QuantumProgram for observable measurement after time propagation.

The QuantumProgram will

  • Initialize a spin state on a quantum computer

  • Time propagte the spin state with a quantum algorithm

  • Measure the values of spin observables

The parameters of the algorithm are taken from the NoiseApp. The hamiltonian, observables and the device the QuantumProgram is created for are parameters of the function.

The initialisation is not universal, but limited to manipulating single spins.

For a N-qubit probem the state starts out in N times |0> or |spin-up>. The initialisation proved N float values. One fj for each spin j. For each qubit j a RotateY(j, f * pi) is applied. So an fj value of 1.0 would flip the spin j from |spin-up> to |spin-down>

The number of qubits in the problem depends on the number of spins in system and bath and the algorithm chosen. For a QSWAP algorithms the number of qubits is three times the maximum of the number of system spins Nsys and the number of bath spins Nbath devided by 2. N = 3 * max(Nsys, Nbath / 2).

Note that a device needs to have at least N qubits or no quantum program can be constructed.

Parameters:
  • hamiltonian (MixedHamiltonian) -- The Spin Hamiltonian.

  • trotter_timestep (float) -- One Trotterstep propagates the system under the hamiltonian for this time. Smallest time increment when running simulations.

  • initialisation (List[float])

  • measured_operators (List[PauliOperator]) -- All the observables that are measured.

  • operator_names (List[str]) -- The names of the measured operators.

  • device (qoqo.Device) -- The device determining topology and noise.

  • logical_to_physical_system (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the system.

  • logical_to_physical_bath (Optional[Dict[int, int]]) -- Optional mapping from logical to physical qubits for the bath.

  • bath_qubit_connectivity (Optional[Dict[int, List[int]]]) -- Optional connectivity between physical system and bath qubits.

Returns:

the created system-bath quantum program.

Return type:

QuantumProgram

Raises:
  • TypeError -- Could not convert hamiltonian input.

  • TypeError -- Could not convert device input.

  • TypeError -- Could not convert measured_operators input.

  • RuntimeError -- QuantumProgram creation failed.

system_bath_trotter_circuit_depth(hamiltonian, trotter_timestep, device, system_bath_physical_definition=None)

Returns the depth of the circuit that implements one Trotter step.

The depth of the circuit strongly depends on the device parameters and the chosen optimisations. The function constructs the circuit for one Trotter step and determines the depth.

The number of qubits in the problem depends on the number of spins in system and bath and the algorithm chosen. For a QSWAP algorithms the number of qubits is three times the maximum of the number of system spins Nsys and the number of bath spins Nbath devided by 2. N = 3 * max(Nsys, Nbath / 2).

Note that a device needs to have at least N qubits or no circuit depth can be constructed.

Example:

>>> from qoqo import Circuit
... from qoqo import operations
... from qoqo.devices import AllToAllDevice
... from hqs_noise_app import HqsNoiseApp
... from struqture_py.mixed_systems import HermitianMixedProduct, MixedHamiltonian
...
... noise_app = HqsNoiseApp()
... hamiltonian = MixedHamiltonian(2, 0, 0)
... # A XX interaction between spins 0 and 1 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["0X1X", ""], [], []), 1.0)
... # A XX interaction between spins 1 and 2 and spins 1 and 0
... hamiltonian.set(HermitianMixedProduct(["1X2X", ""], [], []), 1.0)
... hamiltonian.set(HermitianMixedProduct(["0Z", "0Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["1Z", "1Z"], [], []), 0.1)
... hamiltonian.set(HermitianMixedProduct(["2Z", "2Z"], [], []), 0.1)
... device = AllToAllDevice(9, ["RotateX", "RotateY", "RotateZ"], ["CNOT"], 1.0)
...
... _noise_model = noise_app.system_bath_trotter_circuit_depth(hamiltonian, 0.001, device)
Parameters:
  • hamiltonian (MixedHamiltonian) -- The Hamiltonian for which the noise algorithm model is created.

  • trotter_timestep (float) -- The simulation time the circuit propagates the simulated system

  • device (qoqo.Device) -- The device determining the topology and the physical noise

  • system_bath_physical_definition (Tuple[List[int], List[int], Optional[Dict[int, List[int]]]]) -- A combination of lists defining the mapping of system and bath qubits to physical qubits.

Returns:

The depth.

Return type:

float

Raises:
  • TypeError -- Could not convert hamiltonian input.

  • RuntimeError -- Extracting effective noise model failed.

to_bincode()

Return the bincode representation of the HqsNoiseApp using the [bincode] crate.

Returns:

The serialized HqsNoiseApp (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize HqsNoiseApp to bytes.

to_json()

Return the json representation of the HqsNoiseApp.

Returns:

The serialized form of HqsNoiseApp.

Return type:

str

Raises:

ValueError -- Cannot serialize HqsNoiseApp to json.

trotter_circuit_depth(trotter_timestep, device)

Returns the depth of the circuit that implements one Trotter step.

The depth of the circuit strongly depends on the device parameters and the chosen optimisations. The function constructs the circuit for one Trotter step and determines the depth.

Example:

>>> from qoqo import Circuit
... from qoqo import operations
... from qoqo.devices import AllToAllDevice
... from hqs_noise_app import HqsNoiseApp
... from struqture_py.spins import PauliProduct, PauliHamiltonian
...
... noise_app = HqsNoiseApp()
... hamiltonian = PauliHamiltonian()
... # A XX interaction between spins 0 and 1 and spins 1 and 0
... hamiltonian.set(PauliProduct().x(0).x(1), 1.0)
... # A XX interaction between spins 1 and 2 and spins 1 and 0
... hamiltonian.set(PauliProduct().x(1).x(2), 1.0)
...
... device = AllToAllDevice(4, ["RotateX", "RotateY", "RotateZ"], ["CNOT"], 1.0)
...
... noise_model = noise_app.trotter_circuit_depth(hamiltonian, 0.001, device)
Parameters:
  • hamiltonian (PauliHamiltonian) -- The Hamiltonian for which the noise algorithm model is created.

  • trotter_timestep (float) -- The simulation time the circuit propagates the simulated system

  • device (qoqo.Device) -- The device determining the topology and the physical noise

Returns:

The depth.

Return type:

int

Raises:

RuntimeError -- Extracting effective noise model failed.

trotterization_order

Setter for the Trotterization order for HqsNoiseApp

Second order Trotterization order is only supported for the circuit function using the ParityBased and VariableMolmerSorensen algorithm option. SWAP based algorithms and the system_bath methods only support first order Trotterization

Parameters:

trotterization_order (int) -- The new trotterization order, that can be 1 or 2. In the case of the CNOT algorithm it gives the order to which the terms in the Suzuki-Trotter decomposition are kept.

Returns:

Updated HqsNoiseApp object with the modified trotterization order setting.

Raises:

ValueError -- Option not available.

unroll_quantum_program(program, number_trottersteps, measured_operators, operator_names, logical_to_physical_remapping=None)

Unrolls quantum program that has an internal PragmaLoop.

Unrolls a QuantumProgram with an internal PragmaLoop, transforming all real PauliZProduct measurements to cheated PauliZProduct measurements. This is meant to only be used for obtaining simulation speedups.

Args

program (QuantumProgram): The quantum program to unroll. number_trottersteps (int): The number of trotter steps that gives the iterations of the unrolled circuit. measured_operators (List[PauliOperator]): The operators measured after each Trotter step. operator_names (List[str]) The main components of the names of teh measured operators.

will be appended with _tstep{n} where n is the trotter step.

logical_to_physical_remapping (Option[Dict[int,int]]): An optional mapping from logical qubit indices to physical qubits

Returns:

A quantum program that measures the observables after each Trotter step.

use_bath_as_control

Setter for the value of option use_bath_as_control

Use bath qubits as control when solving system-bath problems and interacting between system and bath qubits with CNOT operations. Only used when using the ParityBased or QSWAP algorithm options for system_bath problems.

Parameters:

use_bath_as_control (str) -- The new value