qoqo.measurements

Measurements

Classes

Cheated

Collected information for executing a cheated measurement.

CheatedInput

Provides Necessary Information to run a cheated measurement.

CheatedPauliZProduct

Collected information for executing a cheated measurement of PauliZ product.

CheatedPauliZProductInput

Collected information for executing a cheated basis rotation measurement.

ClassicalRegister

Collected information for executing a classical register.

PauliZProduct

Collected information for executing a measurement of PauliZ product.

PauliZProductInput

Provides Necessary Information to run a [roqoqo::measurements::PauliZProduct] measurement.

class qoqo.measurements.Cheated

Collected information for executing a cheated measurement.

circuits()

Return the collection of quantum circuits for the separate cheated measurements.

Returns:

The quantum circuits.

Return type:

list[Circuit]

constant_circuit()

Returns constant circuit that is executed before any Circuit in circuits.

Returns:

The constant Circuit (None if not defined).

Return type:

Optional[Circuit]

evaluate(input_bit_registers, float_registers, complex_registers)

Execute the cheated measurement.

Parameters:
  • input_bit_registers (dict[str, Union[list[list[int]], list[list[bool]]]]) – The classical bit registers with the register name as key.

  • float_registers (dict[str, list[list[float]]) – The classical float registers as a dictionary with the register name as key.

  • complex_registers (dict[str, list[list[complex]]) – The classical complex registers as a dictionary with the register name as key.

Returns:

The evaluated expectation values.

Return type:

Optional[dict[str, float]

Raises:
  • RuntimeError – Unexpected repetition of key in bit_register.

  • RuntimeError – Error evaluating cheated measurement.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized Cheated (in [bincode] form).

Returns:

The deserialized Cheated.

Return type:

Cheated

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

  • ValueError – Input cannot be deserialized to Cheated.

static from_json(json_string)

Deserialize the Cheated measurement from json form.

Returns:

The deserialized Cheated Measurement.

Return type:

Cheated

Raises:

RuntimeError – Cannot deserialize string to Cheated.

input()

Returns the measurement input data defining how to construct expectation values from measurements.

Returns:

The input of Cheated measurement

Return type:

CheatedInput

measurement_type()

Returns the type of the measurement in string form.

Returns:

The type of the measurement.

Return type:

str

substitute_parameters(substituted_parameters)

Return copy of Measurement with symbolic parameters replaced.

Parameters:

substituted_parameters (dict[str, float]) – The dictionary containing the substitutions to use in the Circuit.

Raises:

RuntimeError – Error substituting symbolic parameters.

to_bincode()

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

Returns:

The serialized Cheated (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize Cheated to bytes.

to_json()

Serialize the Cheated measurement to json form.

Returns:

The serialized Cheated measurement.

Return type:

str

Raises:

RuntimeError – Unexpected error serializing Cheated.

class qoqo.measurements.CheatedInput

Provides Necessary Information to run a cheated measurement.

add_operator_exp_val(name, operator, readout)

Add operator based expectation value to measurement input.

Adds an expectation value that is defined by an operator on the Hilbert space.

Parameters:
  • name (str) – The name of the expectation value.

  • operator (list[(int, int, complex)]) – The measured operator on the Hilbert space, given as a list of sparse matrix entries of the form (row, col, value).

  • readout (str) – The mame of the readout register that contains the density matrix or satevector.

Raises:

RuntimeError – Failed to add operator based expectation value.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized CheatedInput (in [bincode] form).

Returns:

The deserialized CheatedInput.

Return type:

CheatedInput

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

  • ValueError – Input cannot be deserialized to CheatedInput.

static from_json(json_string)

Deserialize the CheatedInput from json form.

Returns:

The deserialized CheatedInput.

Return type:

CheatedInput

Raises:

PyRuntimeError – Cannot deserialize string to CheatedInput.

to_bincode()

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

Returns:

The serialized CheatedInput (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize CheatedInput to bytes.

to_json()

Serialize the CheatedInput to json form.

Returns:

The serialized CheatedInput.

Return type:

str

Raises:

PyRuntimeError – Unexpected error serializing CheatedInput.

class qoqo.measurements.CheatedPauliZProduct

Collected information for executing a cheated measurement of PauliZ product.

circuits()

Returns the collection of quantum circuits for the separate basis rotations.

Returns:

The quantum circuits.

Return type:

list[Circuit]

constant_circuit()

Returns constant circuit that is executed before any Circuit in circuits.

Returns:

The constant Circuit (None if not defined).

Return type:

Optional[Circuit]

evaluate(input_bit_registers, float_registers, complex_registers)

Executes the cheated PauliZ product measurement.

Parameters:
  • input_bit_registers (dict[str, Union[list[list[int]], list[list[bool]]]]) – The classical bit registers with the register name as key

  • float_registers (dict[str, list[list[float]]) – The classical float registers as a dictionary with the register name as key

  • complex_registers (dict[str, list[list[complex]]) – The classical complex registers as a dictionary with the register name as key

Returns:

The evaluated measurement.

Return type:

Optional[dict[str, float]]

Raises:
  • RuntimeError – Unexpected repetition of key in bit_register.

  • RuntimeError – Error evaluating cheated PauliZ product measurement.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized CheatedPauliZProduct (in [bincode] form).

Returns:

The deserialized CheatedPauliZProduct.

Return type:

CheatedPauliZProduct

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

  • ValueError – Input cannot be deserialized to CheatedPauliZProduct.

static from_json(json_string)

Deserialize the CheatedPauliZProduct from json form using the [serde_json] crate.

Returns:

the deserialized CheatedPauliZProduct.

Return type:

CheatedPauliZProduct

Raises:

RuntimeError – Cannot deserialize string to CheatedPauliZProduct.

input()

Returns the measurement input data defining how to construct expectation values from measurements.

Returns:

The measurment input of CheatedPauliZProduct.

Return type:

CheatedPauliZProductInput

measurement_type()

Returns the type of the measurement in string form.

Returns:

The type of the measurement.

Return type:

str

substitute_parameters(substituted_parameters)

Returns clone of Measurement with symbolic parameters replaced

Parameters:

substituted_parameters (dict[str, float]) – The dictionary containing the substitutions to use in the Circuit.

to_bincode()

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

Returns:

The serialized CheatedPauliZProduct (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize CheatedPauliZProduct to bytes.

to_json()

Serializes the CheatedPauliZProduct to json form using the [serde_json] crate.

Returns:

The serialized CheatedPauliZProduct.

Return type:

str

Raises:

RuntimeError – Unexpected error serializing CheatedPauliZProduct.

class qoqo.measurements.CheatedPauliZProductInput

Collected information for executing a cheated basis rotation measurement.

add_linear_exp_val(name, linear)

Add linear definition of expectation value to measurement input.

Adds an expectation value that is defined by a linear combination of expectation values of Pauli products.

Parameters:
  • name (str) – The name of the expectation value.

  • linear (dict[int, float]) – The linear combination of expectation values as a map between Pauli product index and coefficient.

Raises:

RuntimeError – Failed to add linear expectation value.

add_pauliz_product(readout)

Add measured Pauli product to CheatedPauliZProductInput and returns index of Pauli product.

When the pauli product is already in the measurement input the function only returns its index.

Parameters:

readout (str) – The name of the readout register containing the pauli_product expectation value.

Returns:

The index of the added Pauli product in the list of all Pauli products.

Return type:

int

add_symbolic_exp_val(name, symbolic)

Add symbolic definition of expectation value to measurement input.

Adds an expectation value that is defined by a symbolic combination of expectation values of Pauli products.

Parameters:
  • name (str) – The name of the expectation value.

  • symbolic (str) – The symbolic expression for the expectation values given by [qoqo_calculator::CalculatorFloat].

Raises:

RuntimeError – Failed to add symbolic expectation value.

The i-th PauliProducts are hardcoded as variables pauli_product_i in the string expression of CalculatorFloat.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized CheatedPauliZProductInput (in [bincode] form).

Returns:

The deserialized CheatedPauliZProductInput.

Return type:

CheatedPauliZProductInput

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

  • ValueError – Input cannot be deserialized to CheatedPauliZProductInput.

static from_json(json_string)

Deserialize the CheatedPauliZProductInput from json form.

Returns:

The deserialized CheatedPauliZProductInput.

Return type:

CheatedPauliZProductInput

Raises:

PyRuntimeError – Cannot deserialize string to CheatedPauliZProductInput.

to_bincode()

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

Returns:

The serialized CheatedPauliZProductInput (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize CheatedPauliZProductInput to bytes.

to_json()

Serialize the CheatedPauliZProductInput to json form.

Returns:

The serialized CheatedPauliZProductInput.

Return type:

str

Raises:

PyRuntimeError – Unexpected error serializing CheatedPauliZProductInput.

class qoqo.measurements.ClassicalRegister

Collected information for executing a classical register.

circuits()

Return the collection of quantum circuits that make up the total measurement.

Returns:

The quantum circuits.

Return type:

list[Circuit]

constant_circuit()

Returns constant circuit that is executed before any Circuit in circuits.

Returns:

The constant Circuit (None if not defined).

Return type:

Optional[Circuit]

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized ClassicalRegister (in [bincode] form).

Returns:

The deserialized ClassicalRegister.

Return type:

ClassicalRegister

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

  • ValueError – Input cannot be deserialized to ClassicalRegister.

static from_json(json_string)

Deserialize the ClassicalRegister measurement from json form.

Returns:

The deserialized ClassicalRegister Measurement.

Return type:

ClassicalRegister

Raises:

PyRuntimeError – Cannot deserialize string to ClassicalRegister.

measurement_type()

Returns the type of the measurement in string form.

Returns:

The type of the measurement.

Return type:

str

substitute_parameters(substituted_parameters)

Return copy of Measurement with symbolic parameters replaced.

Parameters:

substituted_parameters (dict[str, float]) – The dictionary containing the substitutions to use in the Circuit.

Raises:

RuntimeError – Error substituting symbolic parameters.

to_bincode()

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

Returns:

The serialized ClassicalRegister (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize ClassicalRegister to bytes.

to_json()

Serialize the ClassicalRegister measurement to json form.

Returns:

The serialized ClassicalRegister measurement.

Return type:

str

Raises:

PyRuntimeError – Unexpected error serializing ClassicalRegister.

class qoqo.measurements.PauliZProduct

Collected information for executing a measurement of PauliZ product.

circuits()

Return the collection of quantum circuits for the separate basis rotations.

Returns:

The quantum circuits.

Return type:

list[Circuit]

constant_circuit()

Return constant circuit that is executed before any Circuit in circuits.

Returns:

The constant Circuit (None if not defined).

Return type:

Optional[Circuit]

evaluate(input_bit_registers, float_registers, complex_registers)

Execute the PauliZ product measurement.

Parameters:
  • input_bit_registers (dict[str, Union[list[list[int]], list[list[bool]]]]) – The classical bit registers with the register name as key

  • float_registers (dict[str, list[list[float]]) – The classical float registers as a dictionary with the register name as key

  • complex_registers (dict[str, list[list[complex]]) – The classical complex registers as a dictionary with the register name as key

Returns:

The evaluated measurement.

Return type:

Optional[dict[str, float]]

Raises:
  • RuntimeError – Unexpected repetition of key in bit_register.

  • RuntimeError – Error evaluating PauliZ product measurement.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized PauliZProduct (in [bincode] form).

Returns:

The deserialized PauliZProduct.

Return type:

PauliZProduct

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

  • ValueError – Input cannot be deserialized to PauliZProduct.

static from_json(json_string)

Deserialize the PauliZProduct from json form using the [serde_json] crate.

Returns:

The deserialized PauliZProduct.

Return type:

PauliZProduct

Raises:

RuntimeError – Cannot deserialize string to PauliZProduct.

input()

Returns the measurement input data defining how to construct expectation values from measurements.

Returns:

The measurment input of PauliZProduct.

Return type:

PauliZProductInput

measurement_type()

Returns the type of the measurement in string form.

Returns:

The type of the measurement.

Return type:

str

substitute_parameters(substituted_parameters)

Return clone of Measurement with symbolic parameters replaced.

Parameters:

substituted_parameters (dict[str, float]) – The dictionary containing the substitutions to use in the Circuit.

to_bincode()

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

Returns:

The serialized PauliZProduct (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize PauliZProduct to bytes.

to_json()

Serialize the PauliZProduct to json form using the [serde_json] crate.

Returns:

The serialized PauliZProduct.

Return type:

str

Raises:

RuntimeError – Unexpected error serializing PauliZProduct.

class qoqo.measurements.PauliZProductInput

Provides Necessary Information to run a [roqoqo::measurements::PauliZProduct] measurement.

add_linear_exp_val(name, linear)

Add linear definition of expectation value to measurement input.

Adds an expectation value that is defined by a linear combination of expectation values of Pauli products.

Parameters:
  • name (str) – The name of the expectation value.

  • linear (dict[int, float]) – The linear combination of expectation values as a map between Pauli product index and coefficient.

Raises:

RuntimeError – Failed to add linear expectation value.

add_pauliz_product(readout, pauli_product_mask)

Add measured Pauli product to PauliZProductInput and returns index of Pauli product.

When the pauli product is already in the measurement input the function only returns it index.

Parameters:
  • readout (str) – The name of the readout register the pauli_product is defined on.

  • pauli_product_mask (list[int]) – List of the qubits involved in the Pauli produc measurement.

Returns:

The index of the added Pauli product in the list of all Pauli products.

Return type:

int

Raises:

RuntimeError – Failed to add pauli product.

add_symbolic_exp_val(name, symbolic)

Add symbolic definition of expectation value to measurement input.

Adds an expectation value that is defined by a symbolic combination of expectation values of Pauli products.

Parameters:
  • name (str) – The name of the expectation value.

  • symbolic (str) – The symbolic expression for the expectation values given by [qoqo_calculator::CalculatorFloat].

Raises:

RuntimeError – Failed to add symbolic expectation value.

The i-th PauliProducts are hardcoded as variables pauli_product_i in the string expression of CalculatorFloat.

static from_bincode(input)

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

Parameters:

input (ByteArray) – The serialized PauliZProductInput (in [bincode] form).

Returns:

The deserialized PauliZProductInput.

Return type:

PauliZProductInput

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

  • ValueError – Input cannot be deserialized to PauliZProductInput.

static from_json(json_string)

Deserialize the PauliZProductInput from json form.

Returns:

The deserialized PauliZProductInput.

Return type:

PauliZProductInput

Raises:

PyRuntimeError – Cannot deserialize string to PauliZProductInput.

to_bincode()

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

Returns:

The serialized PauliZProductInput (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize PauliZProductInput to bytes.

to_json()

Serialize the PauliZProductInput to json form.

Returns:

The serialized PauliZProductInput.

Return type:

str

Raises:

PyRuntimeError – Unexpected error serializing PauliZProductInput.