py_alqorithms

Alqorithms Python interface.

Copyright © 2021-2024 HQS Quantum Simulations GmbH. All Rights Reserved.

CNOTAlgorithm(number_trotter_steps)

SystemBathCNOTAlgorithm(...)

CNOT algorithm for system bath

VariableMSXXAlgorithm(number_trotter_steps)

SystemBathQSWAPMSAlgorithm(number_trotter_steps)

QSWAP algorithm for system bath

SystemBathQSWAPAlgorithm(...)

QSWAP algorithm for system bath

QSWAPMSAlgorithm(number_trotter_steps)

QSWAPAlgorithm(number_trotter_steps)

single_measurement_circuit(pauli_products, ...)

Create a measurement circuit using single projective measurements on qubits.

basis_rotations_from_z_basis(pauli_products)

Creates a the circuit of basis rotations from Z basis to measurement basis.

basis_rotations_to_z_basis(pauli_products[, ...])

Creates the circuit of basis rotations back to the Z basis from the measurement basis.

repeated_measurement_circuit(pauli_products, ...)

Create a measurement circuit using repeated measurements on all qubits.

measure_spin_operator(input_operator, ...[, ...])

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised PauliZ-basis measurement of all of the terms in it.

measure_spin_operator_map(input_operators, ...)

Take a list of SpinSystems and apply an optimised PauliZ-basis measurement of all of the terms in it.

measure_spin_operator_map_cheated(...[, ...])

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised CheatedPauliZ-basis measurement of all of the terms in it.

concat_cheated_paulizproduct_inputs(left, right)

Concatenates two CheatedPauliZProductInputs to combine two measurement inputs

sort_spin_operator(input_operator)

Sort a SpinSystem/SpinHamiltonianSystem into a vector of the same type, where each object has all of the qubits involved in its keys (PauliProducts) in the same basis.

Functions

apply_symmetrization_spins(algorithm, ...)

Symmetrize a spin Hamiltonian.

apply_symmetrization_system_bath(algorithm, ...)

Symmetrize a system-bath Hamiltonian.

basis_rotations_from_z_basis(pauli_products)

Creates a the circuit of basis rotations from Z basis to measurement basis.

basis_rotations_to_z_basis(pauli_products[, ...])

Creates the circuit of basis rotations back to the Z basis from the measurement basis.

concat_cheated_paulizproduct_inputs(left, right)

Concatenates two CheatedPauliZProductInputs to combine two measurement inputs

create_symmetrized_spin_circuit(algorithm, ...)

Create a circuit for the symmetrized spins.

create_symmetrized_system_bath_circuit(...)

Create a symmetrized system-bath circuit and the vector of system qubits.

create_xyz_shadow_measurement(num_qubits[, ...])

Generates circuits for shadow measurements based on specified measurement bases for each qubit.

measure_spin_operator(input_operator, ...[, ...])

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised PauliZ-basis measurement of all of the terms in it.

measure_spin_operator_map(input_operators, ...)

Take a list of SpinSystems and apply an optimised PauliZ-basis measurement of all of the terms in it.

measure_spin_operator_map_cheated(...[, ...])

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised CheatedPauliZ-basis measurement of all of the terms in it.

repeated_measurement_circuit(pauli_products, ...)

Create a measurement circuit using repeated measurements on all qubits.

single_measurement_circuit(pauli_products, ...)

Create a measurement circuit using single projective measurements on qubits.

sort_spin_operator(input_operator)

Sort a SpinSystem/SpinHamiltonianSystem into a vector of the same type, where each object has all of the qubits involved in its keys (PauliProducts) in the same basis.

Classes

CNOTAlgorithm(number_trotter_steps)

InfiniteTemperatureCorrelator(...)

Class constructing qoqo measurements for infinite temperature correlators.

QSWAPAlgorithm(number_trotter_steps)

QSWAPMSAlgorithm(number_trotter_steps)

SystemBathCNOTAlgorithm(...)

CNOT algorithm for system bath

SystemBathQSWAPAlgorithm(...)

QSWAP algorithm for system bath

SystemBathQSWAPMSAlgorithm(number_trotter_steps)

QSWAP algorithm for system bath

VariableMSXXAlgorithm(number_trotter_steps)

class py_alqorithms.CNOTAlgorithm(number_trotter_steps)
create_circuit(hermitian_operator, parameter)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[SpinHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

order(order)

Change the Trotter order (first or second order available) property of self.

Parameters:

order (int) -- The new order (1 or 2).

Returns:

The instance with the modified order parameter

Return type:

self

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.InfiniteTemperatureCorrelator(number_trottersteps)

Class constructing qoqo measurements for infinite temperature correlators.

Example

>>> from py_alqorithms import InfiniteTemperatureCorrelator
... correlator = InfiniteTemperatureCorrelator(number_trottersteps=10)
Parameters:

number_trottersteps (int) -- The number of trottersteps used for the internal time evolution.

Returns:

A new InfiniteTemperatureCorrelator object with provided input parameters.

Raises:

ValueError -- Option not available.

algorithm

Setter for the algorithm option of InfiniteTemperatureCorrelator.

Parameters:

algorithm (str) -- The option for the algorithm that is set. Available options are paritybased, qswap, qswapmolmersorensen, variablemolmersorensen, bandedqswap.

Raises:

ValueError -- Option not available.

decoherence_loops

Sets the number of PauliX loops that allow decoherence to act in initialisation

Parameters:

decoherence_loops (int) -- The new number of decoherence loops.

decomposition_blocks

Changes the decomposition_blocks settings of the InfiniteTemperatureCorrelator.

Parameters:

decomposition_blocks (int) -- The new number of measurements.

from_bincode()

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

Parameters:

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

Returns:

The deserialized InfiniteTemperature.

Return type:

InfiniteTemperature

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

  • ValueError -- Input cannot be deserialized to InfiniteTemperature.

from_json()

Convert the json representation of a InfiniteTemperature to a InfiniteTemperature.

Parameters:

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

Returns:

The deserialized InfiniteTemperature.

Return type:

InfiniteTemperature

Raises:

ValueError -- Input cannot be deserialized to InfiniteTemperature.

initialisation

Setter for the initialisation option of InfiniteTemperatureCorrelator.

Parameters:
  • initialisation (str) -- The option for the initialisation that is set. Available options

  • active_reset (are)

  • measurement

  • dephasing

  • local_operator_measurement

  • all_initial_states.

Raises:

ValueError -- Option not available.

number_measurements

Changes the number of measurements in projective readout.

Parameters:

number_measurements (int) -- The new number of measurements.

number_trottersteps

Changes the number of trottersteps for the time evolution.

Parameters:

number_trottersteps (int) -- The new number of trottersteps.

readout_register

Changes the readout register name for InfiniteTemperature

Parameters:

readout_register (str) -- The new readout register name.

time_correlation_measurement(hamiltonian, right_operator)

Creates a [roqoqo::measurements::PauliZProduct] measurement to measure a correlator.

The resulting measurement will calculate Tr[A(t)B rho]

where rho is the infinite temperature steady state, A and B are SpinSystems and the time evolution of A is given by a hamiltonian H. The time t of the correlator is a symbolic variable in the measurement with name time

Parameters:
  • left_operator (spins.SpinSystem) -- Left operator A

  • hamiltonian (spins.SpinHamiltonianSystem) -- Hamiltonina H determining the time evolution

  • right_operator (spins.SpinSystem) -- Right operator B

Returns:

The measurement that can calculate the correlation function

Return type:

PauliZProduct

time_correlation_measurement_multiple_left(hamiltonian, right_operator)

Creates a [roqoqo::measurements::PauliZProduct] measurement to measure several correlators.

The resulting measurement will calculate a dictionay of Tr[A_i(t)B rho]

where A_i are SpinSystems and the keys in the dict are given by a list of provided names, rho is the infinite temperature steady state, B is a SpinSystem and the time evolution of the A_i is given by a hamiltonian H. The time t of the correlator is a symbolic variable in the measurement with name time

Parameters:
  • left_input_operators (List[SpinSystem]) -- List of left operators A_i

  • left_operator_names (List[str]) -- List of names of operator A_i

  • hamiltonian (SpinHamiltonianSystem) -- Hamiltonina H determining the time evolution

  • right_operator (SpinSystem) -- Right operator B

Returns:

The measurement that can calculate the correlation functions

Return type:

PauliZProduct

time_correlation_measurement_multiple_left_fixed_timestep(hamiltonian, right_operator)

Creates a [roqoqo::measurements::PauliZProduct] measurement to measure several correlators.

The resulting measurement will calculate a dictionay of Tr[A_i(n*trotter_timestep)B rho]

where A_i are SpinSystems and the keys in the dict are given by a list of provided names, rho is the infinite temperature steady state, B is a SpinSystem and the time evolution of the A_i is given by a hamiltonian H. The time n*trotter_timestep of the correlator is a multiple of a given Trotter step. The variable n can is a symbolic value with the name number_trottersteps

Parameters:
  • left_input_operators (List[SpinSystem]) -- List of left operators A_i

  • left_operator_names (List[str]) -- List of names of operator A_i

  • hamiltonian (SpinHamiltonianSystem) -- Hamiltonina H determining the time evolution

  • right_operator (SpinSystem) -- Right operator B

  • trotter_timestep (float) -- The fixed trotter timestep

Returns:

The measurement that can calculate the correlation function

Return type:

PauliZProduct

to_bincode()

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

Returns:

The serialized InfiniteTemperature (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize InfiniteTemperature to bytes.

to_json()

Return the json representation of the InfiniteTemperature.

Returns:

The serialized form of InfiniteTemperature.

Return type:

str

Raises:

ValueError -- Cannot serialize InfiniteTemperature to json.

class py_alqorithms.QSWAPAlgorithm(number_trotter_steps)
create_circuit(hermitian_operator, parameter)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[SpinHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_remapped(hermitian_operator, parameter, initial_ordering)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm, given an initial qubit ordering.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

  • initial_ordering (List[int]) -- A list of the qubit indices in the ordering they start in.

Returns:

The created circuit and resulted qubit ordering.

Return type:

Tuple[Circuit, List[int]]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.QSWAPMSAlgorithm(number_trotter_steps)
create_circuit(hermitian_operator, parameter)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[SpinHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_remapped(hermitian_operator, parameter, initial_ordering)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm, given an initial qubit ordering.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

  • initial_ordering (List[int]) -- A list of the qubit indices in the ordering they start in.

Returns:

The created circuit and resulted qubit ordering.

Return type:

Tuple[Circuit, List[int]]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.SystemBathCNOTAlgorithm(number_trotter_steps, use_bath_as_control)

CNOT algorithm for system bath

This algorithm is designed to simulate an interacting spin system in contact with an (internally) non-interacting bath.

create_circuit(hermitian_operator, parameter, system_bath_physical_definition=None)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (MixedHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[MixedHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.SystemBathQSWAPAlgorithm(number_trotter_steps, use_bath_as_control)

QSWAP algorithm for system bath

Based on the following paper: https://arxiv.org/abs/1711.04789 We have implemented the fermionic swapping algorithm in this paper for qubits. This algorithm is designed to simulate an interacting spin system in contact with an (internally) non-interacting bath

create_circuit(hermitian_operator, parameter, system_bath_physical_definition=None)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (MixedHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[MixedHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

create_circuit_remapped(hermitian_operator, parameter, initial_ordering, system_bath_physical_definition=None)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm, given an initial qubit ordering.

Parameters:
  • hermitian_operator (MixedHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

  • initial_ordering (List[int]) -- A list of the qubit indices in the ordering they start in.

Returns:

The created circuit and resulted qubit ordering.

Return type:

Tuple[Circuit, List[int]]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.SystemBathQSWAPMSAlgorithm(number_trotter_steps)

QSWAP algorithm for system bath

Based on the following paper: https://arxiv.org/abs/1711.04789 We have implemented the fermionic swapping algorithm in this paper for qubits. This algorithm is designed to simulate an interacting spin system in contact with an (internally) non-interacting bath

create_circuit(hermitian_operator, parameter, system_bath_physical_definition=None)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (MixedHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[MixedHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

  • PyValueError -- System Bath must consist of exactly two spin subsystem.

create_circuit_remapped(hermitian_operator, parameter, initial_ordering, system_bath_physical_definition=None)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm, given an initial qubit ordering.

Parameters:
  • hermitian_operator (MixedHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

  • initial_ordering (List[int]) -- A list of the qubit indices in the ordering they start in.

Returns:

The created circuit and resulted qubit ordering.

Return type:

Tuple[Circuit, List[int]]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a MixedHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

class py_alqorithms.VariableMSXXAlgorithm(number_trotter_steps)
create_circuit(hermitian_operator, parameter)

Create the circuit corresponding to the hermitian operator, according to the chosen algorithm.

Parameters:
  • hermitian_operator (SpinHamiltonianSystem) -- The hamiltonian to turn into a circuit according to the algorithm.

  • parameter (CalculatorFloat) -- The parameter for which to create the circuit.

Returns:

The created circuit.

Return type:

Circuit

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

create_circuit_from_list(hermitian_operators, parameters)

Create the circuits corresponding to the hermitian operators, according to the chosen algorithm.

Parameters:
  • hermitian_operators (List[SpinHamiltonianSystem]) -- The list of hamiltonians to turn into circuits according to the algorithm.

  • parameters (List[CalculatorFloat]) -- The parameters for which to create the circuit.

Returns:

The created circuits.

Return type:

List[Circuit]

Raises:
  • PyTypeError -- Parameter is not a CalculatorFloat.

  • PyTypeError -- Hermitian operator is not a SpinHamiltonianSystem.

decomposition_blocks(decomposition_blocks)

Change whether or not to use PragmaStart/StopDecompositionBlocks in the circuit.

Parameters:

decomposition_blocks (bool) -- The new decomposition_blocks flag.

Returns:

The instance with the modified decomposition_blocks parameter

Return type:

self

static from_bincode(input)

Convert the bincode representation of self to an instance using the [bincode] crate.

Parameters:

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

Returns:

The deserialized object.

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

  • ValueError -- Input cannot be deserialized.

static from_json(input)

Convert the json representation of self to an instance.

Parameters:

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

Returns:

The deserialized object.

Raises:

ValueError -- Input cannot be deserialized.

order(order)

Change the Trotter order (first or second order available) property of self.

Parameters:

order (int) -- The new order (1 or 2).

Returns:

The instance with the modified order parameter

Return type:

self

to_bincode()

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

Returns:

The serialized object (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize object to bytes.

to_json()

Return the json representation of self.

Returns:

The serialized form of self.

Return type:

str

Raises:

ValueError -- Cannot serialize object to json.

py_alqorithms.apply_symmetrization_spins(algorithm, hamiltonian, trotterization_order, number_trottersteps, time)

Symmetrize a spin Hamiltonian.

The input hamiltonian is multiplied from left and right by PauliX on each of the system qubits (here, all of them). The circuit is then generated with this symmetrised hamiltonian, and before we append it to the input circuit we flip the system qubits (which are the symmetrised ones) using PauliX gates.

Parameters:
  • algorithm (string) -- Choice of algorithm

  • hamiltonian (SpinHamiltonianSystem) -- The input mixed hamiltonian

  • trotterization_order (int) -- Trotterization order, either 1 or 2

  • number_trottersteps (int) -- The number of times to apply the Hamiltonian, which has been trotterised by the user

  • time (float) -- The time interval over which Hamiltonian is applied

Returns:

symmetrized circuit obtained from the input hamiltonian

Return type:

circuit (Circuit)

Raises:
  • ValueError -- Error occured in the conversion of SpinAlgorithm or trotterization order

  • RuntimeError -- Error occured in symmetrization of hamiltonian

py_alqorithms.apply_symmetrization_system_bath(algorithm, hamiltonian, number_trottersteps, trotter_timestep, use_bath_as_control, system_bath_physical_definition=None)

Symmetrize a system-bath Hamiltonian.

The input hamiltonian is multiplied from left and right by PauliX on each of the system qubits. The circuit is then generated with this symmetrised hamiltonian, and before we append it to the input circuit we flip the system qubits (which are the symmetrised ones) using PauliX gates.

Parameters:
  • algorithm (string) -- Choice of algorithm

  • hamiltonian (MixedHamiltonianSystem) -- The input mixed hamiltonian

  • number_trottersteps (int) -- The number of times to apply the Hamiltonian, which has been trotterised by the user

  • trotter_timestep (float) -- The time interval over which Hamiltonian is applied

  • use_bath_as_control (bool) -- In the CNOT part of the algorithm, a CNOT gate is applied for the coupling between system and bath. We can choose to use the bath qubit as the control qubit for the CNOT (True) or the system qubit as the control qubit for the CNOT (False).

  • system_bath_physical_defintion ((List, List, Option[Dict[int, List]])) -- An optional custom specification for system and bath logical_to_physical mappings and device connectivity.

Returns:

symmetrized circuit obtained from the input hamiltonian

Return type:

circuit (Circuit)

Raises:
  • ValueError -- Error occured in the conversion of SpinAlgorithm

  • RuntimeError -- Error occured in symmetrization of hamiltonian

py_alqorithms.basis_rotations_from_z_basis(pauli_products, qubit_mapping=None)

Creates a the circuit of basis rotations from Z basis to measurement basis.

To measure a product of general products of Pauli operators, the local basis of each qubit must be transformed so that the available Z-measurement corresponds to the measurement of the Pauli operator that should be measured.

The circuit can transform the local bases for several PauliProducts at the same time, as long as the PauliProducts are compatible. Two PauliProducts are compatible if for each qubit (or spin) in the PauliProduct the both PauliProducts have either the same PauliOperator (X, Y, Z) or at least one has the identity I.

The function returns an error when the PauliProducts are not compatible.

The resulting circuit will rotate each qubit into a new basis so that a Z-Measurement will be equivalent to a X, Y or Z measurement in the original basis, depending on which Pauli Operator is supposed to be measured.

Parameters:
  • pauli_products (List[PauliProduct]) -- The PauliProducts that should be measured by the circuit

  • qubit_mapping (Optional[Dict[int, int]]) -- Optional mapping of the qubits

Returns:

the measurement circuit produced.

Return type:

Circuit

Raises:
  • PyTypeError -- Error converting the list of PauliProducts.

  • PyValueError -- PauliProducts can not be measured in same circuit with chosen method.

py_alqorithms.basis_rotations_to_z_basis(pauli_products, qubit_mapping=None)

Creates the circuit of basis rotations back to the Z basis from the measurement basis.

To measure a product of general products of Pauli operators, the local basis of each qubit must be transformed so that the available Z-measurement corresponds to the measurement of the Pauli operator that should be measured.

The circuit can transform the local bases for several PauliProducts at the same time, as long as the PauliProducts are compatible. Two PauliProducts are compatible if for each qubit (or spin) in the PauliProduct the both PauliProducts have either the same PauliOperator (X, Y, Z) or at least one has the identity I.

The function returns an error when the PauliProducts are not compatible.

The resulting circuit will rotate each qubit into a new basis so that a Z-Measurement will be equivalent to a X, Y or Z measurement in the original basis, depending on which Pauli Operator is supposed to be measured.

Parameters:
  • pauli_products (List[PauliProduct]) -- The PauliProducts that should be measured by the circuit.

  • qubit_mapping (Optional[Dict[int, int]]) -- Optional mapping of the qubits.

Returns:

the measurement circuit produced.

Return type:

Circuit

Raises:
  • PyTypeError -- Error converting the list of PauliProducts.

  • PyValueError -- PauliProducts can not be measured in same circuit with chosen method.

py_alqorithms.concat_cheated_paulizproduct_inputs(left, right)

Concatenates two CheatedPauliZProductInputs to combine two measurement inputs

Parameters:
  • left -- The left measurement input that is concatenated

  • right -- The right measurement input that is concatenated

Returns:

concatenated measurement input

Return type:

CheatedPauliZProductInput

Raises:

RuntimeError -- Incompatible measurements inputs. Use the same readout register or expectation value name

py_alqorithms.create_symmetrized_spin_circuit(algorithm, hamiltonian, trotterization_order, number_trottersteps, time)

Create a circuit for the symmetrized spins.

Parameters:
  • algorithm (string) -- Choice of algorithm

  • hamiltonian (SpinHamiltonianSystem) -- The input mixed hamiltonian

  • trotterization_order (int) -- Trotterization order, either 1 or 2

  • number_trottersteps (int) -- The number of times to apply the Hamiltonian, which has been trotterised by the user

  • time (float) -- The time interval over which Hamiltonian is applied

Returns:

symmetrized circuit obtained from the input hamiltonian

Return type:

circuit (Circuit)

Raises:
  • ValueError -- Error occured in the conversion of SpinAlgorithm or trotterization order

  • RuntimeError -- Error occured in symmetrization of hamiltonian

py_alqorithms.create_symmetrized_system_bath_circuit(algorithm, hamiltonian, number_trottersteps, trotter_timestep, use_bath_as_control, system_bath_physical_definition=None)

Create a symmetrized system-bath circuit and the vector of system qubits.

Parameters:
  • algorithm (string) -- Choice of algorithm

  • hamiltonian (MixedHamiltonianSystem) -- The input mixed hamiltonian

  • number_trottersteps (int) -- The number of times to apply the Hamiltonian, which has been trotterised by the user

  • trotter_timestep (float) -- The time interval over which Hamiltonian is applied

  • use_bath_as_control (bool) -- In the CNOT part of the algorithm, a CNOT gate is applied for the coupling between system and bath. We can choose to use the bath qubit as the control qubit for the CNOT (True) or the system qubit as the control qubit for the CNOT (False).

  • system_bath_physical_defintion ((List, List, Option[Dict[int, List]])) -- An optional custom specification for system and bath logical_to_physical mappings and device connectivity.

Returns:

symmetrized circuit obtained from the input hamiltonian system_qubits (List): vector of system qubits

Return type:

circuit (Circuit)

Raises:
  • ValueError -- Error occured in the conversion of SpinAlgorithm

  • RuntimeError -- Error occured in symmetrization of hamiltonian

py_alqorithms.create_xyz_shadow_measurement(num_qubits, n_measurements=None, max_circuits=None, constant_circuit=None)

Generates circuits for shadow measurements based on specified measurement bases for each qubit.

Each circuit corresponds to a different combination of measurement bases (X, Y, Z, etc.), applied across all qubits. This function iterates over all possible combinations of measurement bases, constructs the circuit for each combination by applying the corresponding unitary transformations, and then stores the circuit along with its unitary matrices.

Parameters: - num_qubits (int): The number of qubits in the circuit. - n_measurement (int, optional): The number of measurements to perform. Defaults to 1. - map_for_unitaries (dict, optional): A mapping from measurement basis labels (e.g., 'X', 'Y', 'Z') to the

corresponding quantum operations (unitaries). Defaults to XYZ_MAP, a predefined dictionary.

  • max_circuits (int, optional): The maximum number of circuits to generate. Defaults to None, which means all combinations possible.

  • constant_circuit (Circuit, optional): The constant circuit to use in the measurement.

Returns: - dict: A dictionary where keys are strings representing the combination of measurement bases applied to

each qubit, and values are tuples containing the corresponding quantum circuit and a dictionary of unitary matrices for each qubit.

py_alqorithms.measure_spin_operator(input_operator, constant_circuit, name, undo_basis_rotation, number_measurements, qubit_mapping=None)

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised PauliZ-basis measurement of all of the terms in it.

Parameters:
  • input_operator (SpinSystem) -- The SpinSystem/SpinHamiltonianSystem to be measured

  • constant_circuit (Optional[Circuit]) -- Optional circuit to apply to all parts of the measurement, before the measurement circuits

  • name (str) -- Name of the measured operator

  • undo_basis_rotation (bool) -- Optional append operations undoing basis rotations

  • number_measurements (Optional[int]) -- Optional number of measurements. If None, the code will perform a single measurement circuit. If Some(x), the code will perform x repeated measurements of the measurement circuit.

  • qubit_remapping (Optional[Dict[int, int]]) -- Optional qubit remapping to be applied in the measurement circuit

Returns:

The PauliZProduct measurement struct populated with the circuits and inputs corresponding to the SpinOperator given

Return type:

PauliZProduct

Raises:
  • PyTypeError -- Could not convert input_operator to SpinSystem.

  • PyTypeError -- Could not convert constant_circuit to Circuit.

  • PyValueError -- Issue in the add_operator_product function in struqture

  • PyValueError -- Issue in the float function in qoqo_calculator

  • PyValueError -- Length of PauliProduct exceeds length of measurement register

  • PyValueError -- The two PauliProducts given are incompatible

  • PyValueError -- Issue in the add_pauliz_product function in roqoqo

  • PyValueError -- The name of expectation value is already taken

py_alqorithms.measure_spin_operator_map(input_operators, operator_names, constant_circuit=None, number_measurements=None, qubit_mapping=None)

Take a list of SpinSystems and apply an optimised PauliZ-basis measurement of all of the terms in it.

Parameters:
  • input_operators (List[SpinSystem]) -- The SpinSystems to be measured

  • constant_circuit (Optional[Circuit]) -- Optional circuit to apply to all parts of the measurement, before the measurement circuits

  • name (str) -- Name of the measured operator

  • undo_basis_rotation (bool) -- Optional append operations undoing basis rotations

  • number_measurements (int) -- Optional number of measurements. If None, the code will perform a single measurement circuit. If Some(x), the code will perform x repeated measurements of the measurement circuit.

  • qubit_remapping (Optional[Dict[int, int]]) -- Optional qubit remapping to be applied in the measurement circuit

Returns:

The PauliZProduct measurement struct populated with the circuits and inputs corresponding to the SpinOperator given

Return type:

PauliZProduct

Raises:
  • PyTypeError -- Could not convert list of SpinSystems.

  • PyTypeError -- Could not convert constant_circuit to Circuit.

  • PyValueError -- Issue in the add_operator_product function in struqture

  • PyValueError -- Issue in the float function in qoqo_calculator

  • PyValueError -- Length of PauliProduct exceeds length of measurement register

  • PyValueError -- The two PauliProducts given are incompatible

  • PyValueError -- Issue in the add_pauliz_product function in roqoqo

  • PyValueError -- The name of expectation value is already taken

py_alqorithms.measure_spin_operator_map_cheated(input_operators, operator_names, constant_circuit=None, qubit_mapping=None, readout_register=None)

Take a SpinSystem/SpinHamiltonianSystem and apply an optimised CheatedPauliZ-basis measurement of all of the terms in it.

The measurement is based on the PragmaGetPauliProduct operations that directly extract the expectation values of PauliProducts.

Parameters:
  • input_operators (List[SpinSystem]) -- The SpinSystems to be measured

  • operator_names (List[circuits]) -- Name of the measured operator

  • constant_circuit (Optional[Circuit]) -- Optional circuit to apply to all parts of the measurement, before the measurement circuits

  • qubit_remapping (Optional[Dict[int, int]]) -- Optional qubit remapping to be applied in the measurement circuit

  • readout_register (Optional[str]) -- Optional base name for the readout registers used to save the expectation values of Pauli products

Returns:

The CheatedPauliZProduct measurement struct populated with the circuits and inputs corresponding to the SpinOperator given

Return type:

CheatedPauliZProduct

Raises:
  • PyTypeError -- Could not convert list of SpinSystems.

  • PyTypeError -- Could not convert constant_circuit to Circuit.

  • PyValueError -- Issue in the add_operator_product function in struqture

  • PyValueError -- Issue in the float function in qoqo_calculator

  • PyValueError -- Length of PauliProduct exceeds length of measurement register

  • PyValueError -- The two PauliProducts given are incompatible

  • PyValueError -- Issue in the add_pauliz_product function in roqoqo

  • PyValueError -- The name of expectation value is already taken

py_alqorithms.repeated_measurement_circuit(pauli_products, readout_register, number_qubits, number_measurements, qubit_mapping=None)

Create a measurement circuit using repeated measurements on all qubits.

The circuit can measure several PauliProducts at the same time using basis rotations, as long as the PauliProducts are compatible. Two PauliProducts are compatible if for each qubit (or spin) in the PauliProduct the both PauliProducts have either the same PauliOperator (X, Y, Z) or at least one has the identity I.

The function returns an error when the PauliProducts are not compatible.

The resulting circuit will rotate each qubit into a new basis so that a Z-Measurement will be equivalent to a X, Y or Z measurement in the original basis, depending on which Pauli Operator is supposed to be measured.

It then inserts a repeated-measurement Pragma measuring all qubits.

Parameters:
  • pauli_products (List[PauliProduct]) -- The PauliProducts that should be measured by the circuit

  • readout_register (str) -- Name of the readout-register

  • number_qubits (int) -- The total number of qubits in the device, used for measurement register

  • numper_measurements (int) -- The number of times the circuit and measurement are repeated

  • qubit_mapping (Optional[Dict[int, int]]) -- Optional qubit remapping to be applied in the measurement circuit

Returns:

the measurement circuit produced.

Return type:

Circuit

Raises:
  • PyTypeError -- Error converting the list of PauliProducts.

  • PyValueError -- Length of PauliProduct exceeds length of measurement register.

  • PyValueError -- PauliProducts can not be measured in same circuit with chosen method.

py_alqorithms.single_measurement_circuit(pauli_products, readout_register, undo_basis_rotation, number_qubits, qubit_mapping=None)

Create a measurement circuit using single projective measurements on qubits.

The circuit can measure several PauliProducts at the same time using basis rotations, as long as the PauliProducts are compatible. Two PauliProducts are compatible if for each qubit (or spin) in the PauliProduct the both PauliProducts have either the same PauliOperator (X, Y, Z) or at least one has the identity I.

The function returns an error when the PauliProducts are not compatible.

The resulting circuit will rotate each qubit into a new basis so that a Z-Measurement will be equivalent to a X, Y or Z measurement in the original basis, depending on which Pauli Operator is supposed to be measured.

It than performs a single projective Z-Basis Measurement on each qubit, writing the result to an output register.

Optionally the basis rotations can be undone after the measurement.

Parameters:
  • pauli_products (List[PauliProduct]) -- The PauliProducts that should be measured by the circuit

  • readout_register (str) -- Name of the readout-register

  • undo_basis_rotation (bool) -- Optional append operations undoing basis rotations

  • number_qubits -- The number of qubits in the operator to be measured

  • qubit_mapping (Optional[Dict[int, int]]) -- Optional qubit remapping to be applied in the measurement circuit

Returns:

the measurement circuit produced.

Return type:

Circuit

Raises:
  • PyTypeError -- Error converting the list of PauliProducts.

  • PyValueError -- PauliProducts can not be measured in same circuit with chosen method.

py_alqorithms.sort_spin_operator(input_operator)

Sort a SpinSystem/SpinHamiltonianSystem into a vector of the same type, where each object has all of the qubits involved in its keys (PauliProducts) in the same basis.

For example, the SpinSystem containing: ``` text

  • (0X1Z4Y, 1.0)

  • (0X1Y, 1.5)

  • (4Y6Z, 2.0)

``` would become two SpinSystems:

  • (0X1Z4Y, 1.0)

  • (4Y6Z, 2.0)

and
  • (0X1Y, 1.5)

Parameters:

input_operator (SpinSystem) -- The SpinSystem to be split up into same basis SpinSystems

Returns:

The same basis SpinSystems

Return type:

List[SpinSystem]

Raises:
  • PyTypeError -- Could not convert input_operator to SpinSystem

  • PyValueError -- Issue in the add_operator_product function

  • PyValueError -- Could not create 2.x QubitOperator from 1.x SpinOperator