qoqo.QuantumProgram

class qoqo.QuantumProgram

Represents a quantum program evaluating measurements based on a one or more free float parameters.

The main use of QuantumProgram is to contain a Measurements implementing [crate::measurements::Measure] that measures expectation values or output registers of [crate::Circuit] quantum circuits that contain symbolic parameters. Circuit with symbolic parameters can not be simulated or executed on real hardware. The symbolic parameters need to be replaced with real floating point numbers first. A QuantumProgram contains a list of the free parameters (input_parameter_names) and can automatically replace the parameters with its run methods and return the result.

The QuantumProgram should correspond as closely as possible to a normal multi-parameter function in classical computing that can be called with a set of parameters and returns a result. It is the intended way to interface between normal program code and roqoqo based quantum programs.

__init__()

Methods

__init__()

from_bincode(input)

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

from_json(input)

Convert the json representation of a QuantumProgram to a QuantumProgram.

input_parameter_names()

Returns the input_parameter_names attribute of the qoqo QuantumProgram.

measurement()

Returns the measurement attribute of the QuantumProgram as Python object.

run(backend)

Runs the QuantumProgram and returns expectation values.

run_registers(backend)

Runs the QuantumProgram and returns the classical registers of the quantum program.

to_bincode()

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

to_json()

Return the json representation of the QuantumProgram.

static from_bincode(input)

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

Parameters:

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

Returns:

The deserialized QuantumProgram.

Return type:

QuantumProgram

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

  • ValueError – Input cannot be deserialized to QuantumProgram.

static from_json(input)

Convert the json representation of a QuantumProgram to a QuantumProgram.

Parameters:

input (str) – The serialized QuantumProgram in json form.

Returns:

The deserialized QuantumProgram.

Return type:

QuantumProgram

Raises:

ValueError – Input cannot be deserialized to QuantumProgram.

input_parameter_names()

Returns the input_parameter_names attribute of the qoqo QuantumProgram.

Returns:

List of input parameter names.

measurement()

Returns the measurement attribute of the QuantumProgram as Python object.

Returns:

PyObject corresponding to the qoqo measurement type of the QuantumProgram, i.e. PauliZProduct, CheatedPauliZProduct, Cheated or ClassicalRegister.

run(backend)

Runs the QuantumProgram and returns expectation values.

Runs the quantum programm for a given set of parameters passed in the same order as the parameters listed in input_parameter_names and returns expectation values.

Parameters:
  • backend (Backend) – The backend the program is executed on.

  • parameters (Optional[List[float]) – List of float parameters of the function call in order of input_parameter_names

run_registers(backend)

Runs the QuantumProgram and returns the classical registers of the quantum program.

Runs the quantum programm for a given set of parameters passed in the same order as the parameters listed in input_parameter_names and returns the classical register output. The classical registers usually contain a record of measurement values for the repeated execution of a [crate::Circuit] quantum circuit for real quantum hardware or the readout of the statevector or the density matrix for simulators.

Parameters:
  • backend (Backend) – The backend the program is executed on.

  • parameters (Optional[List[float]) – List of float parameters of the function call in order of input_parameter_names

to_bincode()

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

Returns:

The serialized QuantumProgram (in [bincode] form).

Return type:

ByteArray

Raises:

ValueError – Cannot serialize QuantumProgram to bytes.

to_json()

Return the json representation of the QuantumProgram.

Returns:

The serialized form of QuantumProgram.

Return type:

str

Raises:

ValueError – Cannot serialize QuantumProgram to json.