qoqo_qryd

QRydDemo support for the qoqo quantum toolkit.

qryd_devices

Prototype qoqo devices for Rydberg hardware

api_devices

Devices available on the QRydDemo WebAPI.

pragma_operations

QRyd specific PragmaOperations that support changing the QRyd device during a circuit evaluation

SimulatorBackend(device, number_qubits, /)

Local simulator backend for Rydberg devices.

APIBackend(device, access_token, timeout, ...)

Qoqo backend interfacing QRydDemo WebAPI.

tweezer_devices

Tweezer devices for the QRyd platform.

emulator_devices

Emulator devices for the QRyd platform.

Functions

device_from_api([device_name, access_token, ...])

Creates a new TweezerDevice instance containing populated tweezer data or EmulatorDevice instance.

Classes

APIBackend(device, access_token, timeout, ...)

Qoqo backend interfacing QRydDemo WebAPI.

FirstDevice(number_rows, number_columns, ...)

First example of a QRyd quantum device.

PragmaChangeQRydLayout(new_layout, /)

This PRAGMA operation changes the layout of a QRyd device.

PragmaDeactivateQRydQubit(qubit, /)

This PRAGMA Operation deactivates a qubit in a QRyd Experimental device.

PragmaShiftQRydQubit(new_positions, /)

This PRAGMA operation shifts qubits between tweezer positions.

PragmaShiftQubitsTweezers(shifts, /)

This PRAGMA Operation lists the shift operations to be executed in a QRyd Tweezer device.

PragmaSwitchDeviceLayout(new_layout, /)

This PRAGMA operation changes the layout of a Tweezer device.

QrydEmuSquareDevice(seed, ...)

QRyd quantum device having a squared configuration.

QrydEmuTriangularDevice(seed, ...)

QRyd quantum device having a triangular configuration.

SimulatorBackend(device, number_qubits, /)

Local simulator backend for Rydberg devices.

TweezerDevice(seed, ...)

Tweezer Device

TweezerMutableDevice(seed, ...)

Tweezer Mutable Device

class qoqo_qryd.APIBackend(device, access_token, timeout, mock_port, dev, api_version, /)

Qoqo backend interfacing QRydDemo WebAPI.

The WebAPI Backend implements methods available in the QRyd Web API. Furthermore, QRyd quantum computer only allows gate operations that are available on a device model of a QRyd device (stored in a [crate::QRydDevice]). This limitation is introduced by design to check the compatability of quantum programs with a model of the QRyd hardware. For simulations of the QRyd quantum computer use the Backend simulator [crate::Backend].

delete_job(job_location, /)

Delete a posted WebAPI job

Parameters:

job_location (str) -- location (url) of the job one is interested in.

Raises:

RuntimeError -- Could not delete job.

static from_bincode(input, /)

Convert the bincode representation of the APIBackend to a APIBackend using the bincode crate.

Parameters:

input (ByteArray) -- The serialized APIBackend (in bincode form).

Returns:

The deserialized APIBackend.

Return type:

APIBackend

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

  • ValueError -- Input cannot be deserialized to APIBackend.

static from_json(input, /)

Convert the json representation of a APIBackend to a APIBackend.

Parameters:

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

Returns:

The deserialized APIBackend.

Return type:

APIBackend

Raises:

ValueError -- Input cannot be deserialized to APIBackend.

get_job_result(job_location, /)

Get status of a completed WebAPI job.

Parameters:

job_location (str) -- location (url) of the job one is interested in.

Returns

dict: Result of the job.

get_job_status(job_location, /)

Get status of a posted WebAPI job.

Parameters:

job_location (str) -- location (url) of the job one is interested in.

Returns:

status and message of the job.

Return type:

Dict[str, str]

post_job(quantumprogram, /)

Post to add a new job to be run on the backend and return the location of the job.

Other free parameters of the job (seed, pcz_theta etc.) are provided by the device given during the initializing of the backend.

The returned location is the URL of the job in String form that can be used to query the job status and result or to delete the job.

Parameters:

quantumprogram (qoqo.QuantumProgram) -- qoqo QuantumProgram to be executed.

Returns:

URL of the location of the job.

Return type:

str

run_circuit(circuit, /)

Run a circuit with the QRyd APIBackend.

A circuit is passed to the APIBackend and executed. During execution values are written to and read from classical registers (List[bool], List[float], List[complex]). To produce sufficient statistics for evaluating expectation values, circuits have to be run multiple times. The results of each repetition are concatenated in OutputRegisters (List[List[bool]], List[List[float]], List[List[complex]]).

Parameters:

circuit (Circuit) -- The circuit that is run on the APIBackend.

Returns:

The output registers written by the evaluated circuits.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:
  • TypeError -- Circuit argument cannot be converted to qoqo Circuit

  • RuntimeError -- Running Circuit failed

run_measurement(measurement, /)

Evaluates expectation values of a measurement with the APIBackend.

Parameters:

measurement (Measurement) -- The measurement that is run on the APIBackend.

Returns:

The dictionary of expectation values.

Return type:

Optional[Dict[str, float]]

Raises:
  • TypeError -- Measurement evaluate function could not be used

  • RuntimeError -- Internal error measurement.evaluation returned unknown type

run_measurement_registers(measurement, /)

Run all circuits corresponding to one measurement with the QRyd APIBackend.

An expectation value measurement in general involves several circuits. Each circuit is passed to the APIBackend and executed separately. During execution values are written to and read from classical registers (List[bool], List[float], List[complex]). To produce sufficient statistics for evaluating expectation values, circuits have to be run multiple times. The results of each repetition are concatenated in OutputRegisters (List[List[bool]], List[List[float]], List[List[complex]]).

Parameters:

measurement (Measurement) -- The measurement that is run on the APIBackend.

Returns:

The output registers written by the evaluated circuits.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:
  • TypeError -- Circuit argument cannot be converted to qoqo Circuit

  • RuntimeError -- Running Circuit failed

set_dev(dev, /)

Setter for the dev option of the APIDevice.

Parameters:

dev (bool) -- The boolean to set the dev option to.

to_bincode()

Return the bincode representation of the APIBackend using the bincode crate.

Returns:

The serialized APIBackend (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize APIBackend to bytes.

to_json()

Return the json representation of the APIBackend.

Returns:

The serialized form of APIBackend.

Return type:

str

Raises:

ValueError -- Cannot serialize APIBackend to json.

class qoqo_qryd.FirstDevice(number_rows, number_columns, qubits_per_row, row_distance, initial_layout, controlled_z_phase_relation, controlled_phase_phase_relation, allow_ccz_gate, allow_ccp_gate, /)

First example of a QRyd quantum device.

At the moment, it is only a prototype showcasing the fundamental design. The device has a 2D grid of tweezer positions with a fixed number of rows and columns Each row contains a columns tweezer positions. The distance between neighbouring rows are fixed but in each row the tweezer positions can be changed.

Parameters:
  • number_rows (int) -- The fixed number of rows in device, needs to be the same for all layouts.

  • number_columns (int) -- Fixed number of tweezers in each row, needs to be the same for all layouts.

  • qubits_per_row (List[int]) -- Fixed number of occupied tweezer position in each row. At the moment assumes that number of qubits in the traps is fixed. No loading/unloading once device is created.

  • row_distance (float) -- Fixed distance between rows.

  • initial_layout (np.ndarray) -- The starting layout (always had the index 0).

  • controlled_z_phase_relation (Optional[Union[str, float]]) -- The relation to use for the PhaseShiftedControlledZ gate.

  • controlled_phase_phase_relation (Optional[Union[str, float]]) -- The relation to use for the PhaseShiftedControlledPhase gate.

  • allow_ccz_gate (Optional[bool]) -- Whether to allow ControlledControlledPauliZ operations in the device.

  • allow_ccp_gate (Optional[bool]) -- Whether to allow ControlledControlledPhaseShift operations in the device.

Raises:

PyValueError --

add_layout(layout, /)

Add a new layout to the device.

A layout is a two-dimensional representation of the y-positions of the tweezers in each row. The x-position is fixed by the row-distance.

Parameters:
  • layout_number (int) -- The number index that is assigned to the new layout

  • layout (List[float]) -- The new layout that is added

Raises:

PyValueError -- layout number is already in use

change_qubit_positions()

Change the positions of the qubits in their rows.

The occupation of the available tweezer positions can be changed. This allows us to change the positions of the qubits in each row.

Parameters:

new_positions (Dict[int, (int, int)]) -- The new column positions of the qubits, given as a map between qubits and new positions.

Raises:

ValueError -- trying to change the number of qubits in one row

static from_bincode(input, /)

Convert the bincode representation of the FirstDevice to a FirstDevice using the bincode crate.

Parameters:

input (ByteArray) -- The serialized FirstDevice (in bincode form).

Returns:

The deserialized FirstDevice.

Return type:

FirstDevice

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

  • ValueError -- Input cannot be deserialized to FirstDevice.

static from_json(input, /)

Convert the json representation of a FirstDevice to a FirstDevice.

Parameters:

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

Returns:

The deserialized FirstDevice.

Return type:

FirstDevice

Raises:

ValueError -- Input cannot be deserialized to FirstDevice.

gate_time_controlled_phase(control, target, phi, theta)

Returns the gate time of a PhaseShiftedControlledPhase operation with the given qubits and phi and theta angles.

gate_time_controlled_z(control, target, phi)

Returns the gate time of a PhaseShiftedControlledZ operation with the given qubits and phi angle.

generic_device()

Turns Device into GenericDevice

Can be used as a generic interface for devices when a boxed dyn trait object cannot be used (for example when the interface needs to be serialized)

Returns:

The device in generic representation

Return type:

GenericDevice

Note

GenericDevice uses nested HashMaps to represent the most general device connectivity. The memory usage will be inefficient for devices with large qubit numbers.

multi_qubit_gate_time(hqslang, qubits)

Returns the gate time of a multi qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

number_columns()

Return number of columns in device.

Returns:

The number of columns.

Return type:

int

number_qubits()

Return number of qubits in device.

Returns:

The number of qubits.

Return type:

int

number_rows()

Return the number of rows of optical tweezers in the two-dimensional grid of potential qubit positions.

Returns:

The number of rows.

Return type:

int

phase_shift_controlled_phase(theta)

Returns the PhaseShiftedControlledPhase phase shift according to the device's relation.

phase_shift_controlled_z()

Returns the PhaseShiftedControlledZ phase shift according to the device's relation.

qubit_positions()

Return the position of each qubit in the row-column grid of tweezer positions.

Returns:

Map between qubit number and row-column position

Return type:

Dict[int, (int, int)]

set_cutoff()

Set distance cutoff for two-qubit gate operations.

In the FirstQryd device the availability of two-qubit operations is determined by the physical distance between the involved qubits.

When the distance is larger than the cut-off the two-qubit gate is not available. The cutoff defaults to 1.0 but can be changed with the set_cutoff function.

Parameters:

cutoff (float) -- The new cutoff for interaction distance

single_qubit_gate_time(hqslang, qubit)

Returns the gate time of a single qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

switch_layout()

Switch to a different pre-defined layout.

Parameters:

layout_number (int) -- The number index of the new layout

Raises:

PyValueError --

three_qubit_gate_time(hqslang, control_0, control_1, target)

Returns the gate time of a three qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

to_bincode()

Return the bincode representation of the FirstDevice using the bincode crate.

Returns:

The serialized FirstDevice (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize FirstDevice to bytes.

to_json()

Return the json representation of the FirstDevice.

Returns:

The serialized form of FirstDevice.

Return type:

str

Raises:

ValueError -- Cannot serialize FirstDevice to json.

two_qubit_edges()

Return the list of pairs of qubits linked by a native two-qubit-gate in the device.

A pair of qubits is considered linked by a native two-qubit-gate if the device can implement a two-qubit-gate between the two qubits without decomposing it into a sequence of gates that involves a third qubit of the device. The two-qubit-gate also has to form a universal set together with the available single qubit gates.

The returned vectors is a simple, graph-library independent, representation of the undirected connectivity graph of the device. It can be used to construct the connectivity graph in a graph library of the user's choice from a list of edges and can be used for applications like routing in quantum algorithms.

Example

To construct a networkx graph from this output one can use

>>> import networkx as nx
... from qoqo_qryd import FirstDevice
...
... device = FirstDevice(number_rows=2,number_columns= 2 qubits_per_row=[2,2], row_distance=1.0)
... edges = device.two_qubit_edges()
... graph = nx.Graph()
... graph.add_edges_from(edges)
Returns:

List of two qubit edges in the undirected connectivity graph

Return type:

Sequence[(int, int)]

two_qubit_gate_time(hqslang, control, target)

Returns the gate time of a two qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

class qoqo_qryd.PragmaChangeQRydLayout(new_layout, /)

This PRAGMA operation changes the layout of a QRyd device.

Before running a circuit a number of layouts can be registered in the device with the add_layout method.

This PRAGMA operation switches between the predefined operations.

Parameters:

new_layout (int) -- The index of the new layout.

from_bincode(input)

Convert the bincode representation of the PragmaChangeQRydLayout to a PragmaChangeQRydLayout using the bincode crate.

Parameters:

input (ByteArray) -- The serialized PragmaChangeQRydLayout (in bincode form).

Returns:

The deserialized PragmaChangeQRydLayout.

Return type:

PragmaChangeQRydLayout

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

  • ValueError -- Input cannot be deserialized to PragmaChangeQRydLayout.

hqslang()

Return hqslang name of the operation.

Returns:

The hqslang name of the operation.

Return type:

str

involved_qubits()

List all involved qubits (here, all).

Returns:

The involved qubits of the PRAGMA operation.

Return type:

set[int]

is_parametrized()

Return true when the operation has symbolic parameters.

Returns:

True if the operation contains symbolic parameters, False if it does not.

Return type:

bool

new_layout()

Return the index of the new layout the Pragma changes the device to.

Returns:

The index of the layout.

Return type:

int

remap_qubits()

Remap qubits in a clone of the PRAGMA operation.

Parameters:

mapping (dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the PRAGMA operation.

Returns:

The PRAGMA operation with the qubits remapped.

Return type:

self

Raises:

RuntimeError -- The qubit remapping failed.

substitute_parameters()

Substitute the symbolic parameters in a clone of the PRAGMA operation according to the substitution_parameters input.

Parameters:

substitution_parameters (dict[str, float]) -- The dictionary containing the substitutions to use in the PRAGMA operation.

Returns:

The PRAGMA operation operation with the parameters substituted.

Return type:

self

Raises:

RuntimeError -- The parameter substitution failed.

tags()

Return tags classifying the type of the operation.

Used for the type based dispatch in ffi interfaces.

Returns:

The tags of the operation.

Return type:

list[str]

to_bincode()

Return the bincode representation of the PragmaChangeQRydLayout using the bincode crate.

Returns:

The serialized Circuit (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize PragmaChangeQRydLayout to bytes.

to_pragma_change_device()

Wrap PragmaChangeQRydLayout in PragmaChangeDevice operation

PragmaChangeQRydLayout is device specific and can not be directly added to a Circuit. Instead it is first wrapped in a PragmaChangeDevice operation that is in turn added to the circuit.

Example

>>> from qoqo import Circuit
... from qoqo_qryd.pragma_operations import PragmaChangeQRydLayout
... circuit = Circuit()
... circuit += PragmaChangeQRydLayout(new_layout=1).to_pragma_change_device()
Returns:

PragmaChangeDevice

class qoqo_qryd.PragmaDeactivateQRydQubit(qubit, /)

This PRAGMA Operation deactivates a qubit in a QRyd Experimental device.

In QRyd Experimental devices a quantum state is trapped within an optical tweezer. This Operation signals the device to drop the quantum state related to the given qubit.

Parameters:

qubit (int) -- The qubit to deactivate.

from_bincode()

Convert the bincode representation of the PragmaDeactivateQRydQubit to a PragmaDeactivateQRydQubit using the bincode crate.

Parameters:

input (ByteArray) -- The serialized PragmaDeactivateQRydQubit (in bincode form).

Returns:

The deserialized PragmaDeactivateQRydQubit.

Return type:

PragmaDeactivateQRydQubit

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

  • ValueError -- Input cannot be deserialized to PragmaDeactivateQRydQubit.

hqslang()

Return hqslang name of the operation.

Returns:

The hqslang name of the operation.

Return type:

str

involved_qubits()

List all involved qubits (here, all).

Returns:

The involved qubits of the PRAGMA operation.

Return type:

set[int]

is_parametrized()

Return true when the operation has symbolic parameters.

Returns:

True if the operation contains symbolic parameters, False if it does not.

Return type:

bool

qubit()

Return the qubit involved in the Operation.

Returns:

The qubit involved in the Operation.

Return type:

int

remap_qubits()

Remap qubits in a clone of the PRAGMA operation.

Parameters:

mapping (dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the PRAGMA operation.

Returns:

The PRAGMA operation with the qubits remapped.

Return type:

self

Raises:

RuntimeError -- The qubit remapping failed.

substitute_parameters()

Substitute the symbolic parameters in a clone of the PRAGMA operation according to the substitution_parameters input.

Parameters:

substitution_parameters (dict[str, float]) -- The dictionary containing the substitutions to use in the PRAGMA operation.

Returns:

The PRAGMA operation operation with the parameters substituted.

Return type:

self

Raises:

RuntimeError -- The parameter substitution failed.

tags()

Return tags classifying the type of the operation.

Used for the type based dispatch in ffi interfaces.

Returns:

The tags of the operation.

Return type:

list[str]

to_bincode()

Return the bincode representation of the PragmaDeactivateQRydQubit using the bincode crate.

Returns:

The serialized PragmaDeactivateQRydQubit (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize PragmaDeactivateQRydQubit to bytes.

to_pragma_change_device()

Wrap PragmaDeactivateQRydQubit in PragmaChangeDevice operation

PragmaDeactivateQRydQubit is device specific and can not be directly added to a Circuit. Instead it is first wrapped in a PragmaChangeDevice operation that is in turn added to the circuit.

Example

>>> from qoqo import Circuit
... from qoqo_qryd.pragma_operations import PragmaDeactivateQRydQubit
... circuit = Circuit()
... circuit += PragmaDeactivateQRydQubit(qubit=0).to_pragma_change_device()
Returns:

PragmaChangeDevice

class qoqo_qryd.PragmaShiftQRydQubit(new_positions, /)

This PRAGMA operation shifts qubits between tweezer positions.

The tweezer positions in a FirstQryd device do not all have to be occupied. In a partially occupied device the qubits can be shifted between positions inside a row. The shift is defined by giving a mapping of qubit number and new row-column positions.

Parameters:

new_positions (Dict[int, (int, int)]) -- The new positions of the qubits.

from_bincode()

Convert the bincode representation of the PragmaShiftQRydQubit to a PragmaShiftQRydQubit using the bincode crate.

Parameters:

input (ByteArray) -- The serialized PragmaShiftQRydQubit (in bincode form).

Returns:

The deserialized PragmaShiftQRydQubit.

Return type:

PragmaShiftQRydQubit

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

  • ValueError -- Input cannot be deserialized to PragmaShiftQRydQubit.

hqslang()

Return hqslang name of the operation.

Returns:

The hqslang name of the operation.

Return type:

str

involved_qubits()

List all involved qubits (here, all).

Returns:

The involved qubits of the PRAGMA operation.

Return type:

set[int]

is_parametrized()

Return true when the operation has symbolic parameters.

Returns:

True if the operation contains symbolic parameters, False if it does not.

Return type:

bool

new_positions()

Return the map of qubit numbers to new positions in the QRyd device.

The new positions are the

Returns:

Map of qubits to new positions in the 2d grid.

Return type:

Dict[int, (int, int)]

remap_qubits()

Remap qubits in a clone of the PRAGMA operation.

Parameters:

mapping (dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the PRAGMA operation.

Returns:

The PRAGMA operation with the qubits remapped.

Return type:

self

Raises:

RuntimeError -- The qubit remapping failed.

substitute_parameters()

Substitute the symbolic parameters in a clone of the PRAGMA operation according to the substitution_parameters input.

Parameters:

substitution_parameters (dict[str, float]) -- The dictionary containing the substitutions to use in the PRAGMA operation.

Returns:

The PRAGMA operation operation with the parameters substituted.

Return type:

self

Raises:

RuntimeError -- The parameter substitution failed.

tags()

Return tags classifying the type of the operation.

Used for the type based dispatch in ffi interfaces.

Returns:

The tags of the operation.

Return type:

list[str]

to_bincode()

Return the bincode representation of the PragmaShiftQRydQubit using the bincode crate.

Returns:

The serialized PragmaShiftQRydQubit (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize PragmaShiftQRydQubit to bytes.

to_pragma_change_device()

Wrap PragmaShiftQRydQubit in PragmaChangeDevice operation

PragmaShiftQRydQubit is device specific and can not be directly added to a Circuit. Instead it is first wrapped in a PragmaChangeDevice operation that is in turn added to the circuit.

Example

>>> from qoqo import Circuit
... from qoqo_qryd.pragma_operations import PragmaShiftQRydQubit
... circuit = Circuit()
... circuit += PragmaShiftQRydQubit(new_layout=1).to_pragma_change_device()
Returns:

PragmaChangeDevice

class qoqo_qryd.PragmaShiftQubitsTweezers(shifts, /)

This PRAGMA Operation lists the shift operations to be executed in a QRyd Tweezer device.

Each tuple contains first the starting tweezer identifier and second the ending tweezer identifier. Multiple instances indicate parallel operations.

Parameters:

shifts (list((int, int))) -- The list of shifts that can run in parallel.

from_bincode()

Convert the bincode representation of the PragmaShiftQubitsTweezers to a PragmaShiftQubitsTweezers using the bincode crate.

Parameters:

input (ByteArray) -- The serialized PragmaShiftQubitsTweezers (in bincode form).

Returns:

The deserialized PragmaShiftQubitsTweezers.

Return type:

PragmaShiftQubitsTweezers

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

  • ValueError -- Input cannot be deserialized to PragmaShiftQubitsTweezers.

hqslang()

Return hqslang name of the operation.

Returns:

The hqslang name of the operation.

Return type:

str

involved_qubits()

List all involved qubits (here, all).

Returns:

The involved qubits of the PRAGMA operation.

Return type:

set[int]

is_parametrized()

Return true when the operation has symbolic parameters.

Returns:

True if the operation contains symbolic parameters, False if it does not.

Return type:

bool

remap_qubits()

Remap qubits in a clone of the PRAGMA operation.

Parameters:

mapping (dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the PRAGMA operation.

Returns:

The PRAGMA operation with the qubits remapped.

Return type:

self

Raises:

RuntimeError -- The qubit remapping failed.

shifts()

Return the shifts involved in the Operation.

Returns:

The shifts involved in the Operation.

Return type:

list[Tuple[int, int]]

substitute_parameters()

Substitute the symbolic parameters in a clone of the PRAGMA operation according to the substitution_parameters input.

Parameters:

substitution_parameters (dict[str, float]) -- The dictionary containing the substitutions to use in the PRAGMA operation.

Returns:

The PRAGMA operation operation with the parameters substituted.

Return type:

self

Raises:

RuntimeError -- The parameter substitution failed.

tags()

Return tags classifying the type of the operation.

Used for the type based dispatch in ffi interfaces.

Returns:

The tags of the operation.

Return type:

list[str]

to_bincode()

Return the bincode representation of the PragmaShiftQubitsTweezers using the bincode crate.

Returns:

The serialized PragmaShiftQubitsTweezers (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize PragmaShiftQubitsTweezers to bytes.

to_pragma_change_device()

Wrap PragmaShiftQubitsTweezers in PragmaChangeDevice operation

PragmaShiftQubitsTweezers is device specific and can not be directly added to a Circuit. Instead it is first wrapped in a PragmaChangeDevice operation that is in turn added to the circuit.

Example

>>> from qoqo import Circuit
... from qoqo_qryd.pragma_operations import PragmaShiftQubitsTweezers
... circuit = Circuit()
... circuit += PragmaShiftQubitsTweezers(shifts=[(0, 1)]).to_pragma_change_device()
Returns:

PragmaChangeDevice

class qoqo_qryd.PragmaSwitchDeviceLayout(new_layout, /)

This PRAGMA operation changes the layout of a Tweezer device.

Before running a circuit a number of layouts can be registered in the device with the add_layout method.

This PRAGMA operation switches between the predefined operations.

Parameters:

new_layout (str) -- The name of the new layout.

from_bincode(input)

Convert the bincode representation of the PragmaSwitchDeviceLayout to a PragmaSwitchDeviceLayout using the bincode crate.

Parameters:

input (ByteArray) -- The serialized PragmaSwitchDeviceLayout (in bincode form).

Returns:

The deserialized PragmaSwitchDeviceLayout.

Return type:

PragmaSwitchDeviceLayout

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

  • ValueError -- Input cannot be deserialized to PragmaSwitchDeviceLayout.

hqslang()

Return hqslang name of the operation.

Returns:

The hqslang name of the operation.

Return type:

str

involved_qubits()

List all involved qubits (here, all).

Returns:

The involved qubits of the PRAGMA operation.

Return type:

set[int]

is_parametrized()

Return true when the operation has symbolic parameters.

Returns:

True if the operation contains symbolic parameters, False if it does not.

Return type:

bool

new_layout()

Return the name of the new layout the Pragma changes the device to.

Returns:

The name of the layout.

Return type:

int

remap_qubits()

Remap qubits in a clone of the PRAGMA operation.

Parameters:

mapping (dict[int, int]) -- The dictionary containing the {qubit: qubit} mapping to use in the PRAGMA operation.

Returns:

The PRAGMA operation with the qubits remapped.

Return type:

self

Raises:

RuntimeError -- The qubit remapping failed.

substitute_parameters()

Substitute the symbolic parameters in a clone of the PRAGMA operation according to the substitution_parameters input.

Parameters:

substitution_parameters (dict[str, float]) -- The dictionary containing the substitutions to use in the PRAGMA operation.

Returns:

The PRAGMA operation operation with the parameters substituted.

Return type:

self

Raises:

RuntimeError -- The parameter substitution failed.

tags()

Return tags classifying the type of the operation.

Used for the type based dispatch in ffi interfaces.

Returns:

The tags of the operation.

Return type:

list[str]

to_bincode()

Return the bincode representation of the PragmaSwitchDeviceLayout using the bincode crate.

Returns:

The serialized Circuit (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize PragmaSwitchDeviceLayout to bytes.

to_pragma_change_device()

Wrap PragmaSwitchDeviceLayout in PragmaChangeDevice operation

PragmaSwitchDeviceLayout is device specific and can not be directly added to a Circuit. Instead it is first wrapped in a PragmaChangeDevice operation that is in turn added to the circuit.

Example

>>> from qoqo import Circuit
... from qoqo_qryd.pragma_operations import PragmaSwitchDeviceLayout
... circuit = Circuit()
... circuit += PragmaSwitchDeviceLayout(new_layout="Square").to_pragma_change_device()
Returns:

PragmaChangeDevice

class qoqo_qryd.QrydEmuSquareDevice(seed, controlled_z_phase_relation, controlled_phase_phase_relation, /)

QRyd quantum device having a squared configuration.

Provides an emulated quantum computing device with up to 30 qubits that can be accessed via the QRyd WebAPI.

Parameters:
  • seed (int) -- Seed, if not provided will be set to 0 per default (not recommended!)

  • controlled_z_phase_relation (Optional[Union[str, float]]) -- The String used to choose what kind of phi-theta relation to use for the PhaseShiftedControlledZ gate

  • controlled_phase_phase_relation (Optional[Union[str, float]]) -- The String used to choose what kind of phi-theta relation to use for the PhaseShiftedControlledPhase gate

static from_bincode(input, /)

Convert the bincode representation of the QrydEmuSquareDevice to a QrydEmuSquareDevice using the bincode crate.

Parameters:

input (ByteArray) -- The serialized QrydEmuSquareDevice (in bincode form).

Returns:

The deserialized QrydEmuSquareDevice.

Return type:

QrydEmuSquareDevice

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

  • ValueError -- Input cannot be deserialized to QrydEmuSquareDevice.

static from_json(input, /)

Convert the json representation of a QrydEmuSquareDevice to a QrydEmuSquareDevice.

Parameters:

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

Returns:

The deserialized QrydEmuSquareDevice.

Return type:

QrydEmuSquareDevice

Raises:

ValueError -- Input cannot be deserialized to QrydEmuSquareDevice.

gate_time_controlled_phase(control, target, phi, theta)

Returns the gate time of a PhaseShiftedControlledPhase operation with the given qubits and phi and theta angles.

gate_time_controlled_z(control, target, phi)

Returns the gate time of a PhaseShiftedControlledZ operation with the given qubits and phi angle.

generic_device()

Turns Device into GenericDevice

Can be used as a generic interface for devices when a boxed dyn trait object cannot be used (for example when the interface needs to be serialized)

Returns:

The device in generic representation

Return type:

GenericDevice

Note

GenericDevice uses nested HashMaps to represent the most general device connectivity. The memory usage will be inefficient for devices with large qubit numbers.

multi_qubit_gate_time(hqslang, qubits)

Returns the gate time of a multi qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

number_qubits()

Return number of qubits in device.

Returns:

The number of qubits.

Return type:

int

phase_shift_controlled_phase(theta)

Returns the PhaseShiftedControlledPhase phase shift according to the device's relation.

phase_shift_controlled_z()

Returns the PhaseShiftedControlledZ phase shift according to the device's relation.

qrydbackend()

Returns the backend associated with the device.

seed()

Returns the seed usized for the API.

single_qubit_gate_time(hqslang, qubit)

Returns the gate time of a single qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

three_qubit_gate_time(hqslang, control_0, control_1, target)

Returns the gate time of a three qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

to_bincode()

Return the bincode representation of the QrydEmuSquareDevice using the bincode crate.

Returns:

The serialized QrydEmuSquareDevice (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize QrydEmuSquareDevice to bytes.

to_json()

Return the json representation of the QrydEmuSquareDevice.

Returns:

The serialized form of QrydEmuSquareDevice.

Return type:

str

Raises:

ValueError -- Cannot serialize QrydEmuSquareDevice to json.

two_qubit_edges()

Return the list of pairs of qubits linked by a native two-qubit-gate in the device.

A pair of qubits is considered linked by a native two-qubit-gate if the device can implement a two-qubit-gate between the two qubits without decomposing it into a sequence of gates that involves a third qubit of the device. The two-qubit-gate also has to form a universal set together with the available single qubit gates.

The returned vectors is a simple, graph-library independent, representation of the undirected connectivity graph of the device. It can be used to construct the connectivity graph in a graph library of the user's choice from a list of edges and can be used for applications like routing in quantum algorithms.

Example

To construct a networkx graph from this output one can use

>>> import networkx as nx
... from qoqo_qryd import QrydEmuSquareDevice
...
... device = QrydEmuSquareDevice(number_rows=2,number_columns= 2 qubits_per_row=[2,2], row_distance=1.0)
... edges = device.two_qubit_edges()
... graph = nx.Graph()
... graph.add_edges_from(edges)
Returns:

List of two qubit edges in the undirected connectivity graph

Return type:

Sequence[(int, int)]

two_qubit_gate_time(hqslang, control, target)

Returns the gate time of a two qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

class qoqo_qryd.QrydEmuTriangularDevice(seed, controlled_z_phase_relation, controlled_phase_phase_relation, allow_ccz_gate, allow_ccp_gate, /)

QRyd quantum device having a triangular configuration.

Provides an emulated quantum computing device with up to 30 qubits that can be accessed via the QRyd WebAPI.

Parameters:
  • seed (int) -- Seed, if not provided will be set to 0 per default (not recommended!)

  • controlled_z_phase_relation (Optional[Union[str, float]]) -- The String used to choose what kind of phi-theta relation to use for the PhaseShiftedControlledZ gate.

  • controlled_phase_phase_relation (Optional[Union[str, float]]) -- The String used to choose what kind of phi-theta relation to use for the PhaseShiftedControlledPhase gate.

  • allow_ccz_gate (Optional[bool]) -- Whether to allow ControlledControlledPauliZ operations in the device.

  • allow_ccp_gate (Optional[bool]) -- Whether to allow ControlledControlledPhaseShift operations in the device.

static from_bincode(input, /)

Convert the bincode representation of the QrydEmuTriangularDevice to a QrydEmuTriangularDevice the bincode crate.

Parameters:

input (ByteArray) -- The serialized QrydEmuTriangularDevice (in bincode form).

Returns:

The deserialized QrydEmuTriangularDevice.

Return type:

QrydEmuTriangularDevice

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

  • ValueError -- Input cannot be deserialized to QrydEmuTriangularDevice.

static from_json(input, /)

Convert the json representation of a QrydEmuTriangularDevice to a QrydEmuTriangularDevice.

Parameters:

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

Returns:

The deserialized QrydEmuTriangularDevice.

Return type:

QrydEmuTriangularDevice

Raises:

ValueError -- Input cannot be deserialized to QrydEmuTriangularDevice.

gate_time_controlled_phase(control, target, phi, theta)

Returns the gate time of a PhaseShiftedControlledPhase operation with the given qubits and phi and theta angles.

gate_time_controlled_z(control, target, phi)

Returns the gate time of a PhaseShiftedControlledZ operation with the given qubits and phi angle.

generic_device()

Turns Device into GenericDevice

Can be used as a generic interface for devices when a boxed dyn trait object cannot be used (for example when the interface needs to be serialized)

Returns:

The device in generic representation

Return type:

GenericDevice

Note

GenericDevice uses nested HashMaps to represent the most general device connectivity. The memory usage will be inefficient for devices with large qubit numbers.

multi_qubit_gate_time(hqslang, qubits)

Returns the gate time of a multi qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

number_qubits()

Return number of qubits in device.

Returns:

The number of qubits.

Return type:

int

phase_shift_controlled_phase(theta)

Returns the PhaseShiftedControlledPhase phase shift according to the device's relation.

phase_shift_controlled_z()

Returns the PhaseShiftedControlledZ phase shift according to the device's relation.

qrydbackend()

Returns the backend associated with the device.

seed()

Returns the seed usized for the API.

single_qubit_gate_time(hqslang, qubit)

Returns the gate time of a single qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

three_qubit_gate_time(hqslang, control_0, control_1, target)

Returns the gate time of a three qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

to_bincode()

Return the bincode representation of the QrydEmuTriangularDevice using the bincode crate.

Returns:

The serialized QrydEmuTriangularDevice (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize QrydEmuTriangularDevice to bytes.

to_json()

Return the json representation of the QrydEmuTriangularDevice.

Returns:

The serialized form of QrydEmuTriangularDevice.

Return type:

str

Raises:

ValueError -- Cannot serialize QrydEmuTriangularDevice to json.

two_qubit_edges()

Return the list of pairs of qubits linked by a native two-qubit-gate in the device.

A pair of qubits is considered linked by a native two-qubit-gate if the device can implement a two-qubit-gate between the two qubits without decomposing it into a sequence of gates that involves a third qubit of the device. The two-qubit-gate also has to form a universal set together with the available single qubit gates.

The returned vectors is a simple, graph-library independent, representation of the undirected connectivity graph of the device. It can be used to construct the connectivity graph in a graph library of the user's choice from a list of edges and can be used for applications like routing in quantum algorithms.

Example

To construct a networkx graph from this output one can use

>>> import networkx as nx
... from qoqo_qryd import QrydEmuTriangularDevice
...
... device = QrydEmuTriangularDevice(number_rows=2,number_columns= 2 qubits_per_row=[2,2], row_distance=1.0)
... edges = device.two_qubit_edges()
... graph = nx.Graph()
... graph.add_edges_from(edges)
Returns:

List of two qubit edges in the undirected connectivity graph

Return type:

Sequence[(int, int)]

two_qubit_gate_time(hqslang, control, target)

Returns the gate time of a two qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

class qoqo_qryd.SimulatorBackend(device, number_qubits, /)

Local simulator backend for Rydberg devices.

The QRyd simulator backend applies each operation in a circuit to a quantum register. The underlying simulator uses the QuEST library. Although the underlying simulator supports arbitrary unitary gates, the QRyd simulator only allows operations that are available on a device model of a QRyd device. This limitation is introduced by design to check the compatibility of circuits with a model of the QRyd hardware. For unrestricted simulations use the backend simulator of the roqoqo-quest crate.

The simulator backend implements the qoqo EvaluatingBackend interface and is compatible with running single circuits, running and evaluating measurements and running QuantumPrograms on simulated QRyd devices.

Parameters:

device (Union[QRydDevice,TweezerDevice]) -- The device providing information about the available operations.

Raises:

TypeError -- Device Parameter is not QRydDevice or TweezerDevice

from_bincode()

Convert the bincode representation of the SimulatorBackend to a SimulatorBackend using the bincode crate.

Parameters:

input (ByteArray) -- The serialized SimulatorBackend (in bincode form).

Returns:

The deserialized SimulatorBackend.

Return type:

SimulatorBackend

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

  • ValueError -- Input cannot be deserialized to SimulatorBackend.

from_json()

Convert the json representation of a SimulatorBackend to a SimulatorBackend.

Parameters:

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

Returns:

The deserialized SimulatorBackend.

Return type:

SimulatorBackend

Raises:

ValueError -- Input cannot be deserialized to SimulatorBackend.

run_circuit(circuit)

Run a circuit with the QRyd backend.

A circuit is passed to the backend and executed. During execution values are written to and read from classical registers (List[bool], List[float], List[complex]). To produce sufficient statistics for evaluating expectation values, circuits have to be run multiple times. The results of each repetition are concatenated in OutputRegisters (List[List[bool]], List[List[float]], List[List[complex]]).

Parameters:

circuit (Circuit) -- The circuit that is run on the backend.

Returns:

The output registers written by the evaluated circuits.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:
  • TypeError -- Circuit argument cannot be converted to qoqo Circuit

  • RuntimeError -- Running Circuit failed

run_measurement()

Evaluates expectation values of a measurement with the backend.

Parameters:

measurement (Measurement) -- The measurement that is run on the backend.

Returns:

The dictionary of expectation values.

Return type:

Optional[Dict[str, float]]

Raises:
  • TypeError -- Measurement evaluate function could not be used

  • RuntimeError -- Internal error measurement.evaluation returned unknown type

run_measurement_registers()

Run all circuits corresponding to one measurement with the QRyd backend.

An expectation value measurement in general involves several circuits. Each circuit is passed to the backend and executed separately. During execution values are written to and read from classical registers (List[bool], List[float], List[complex]). To produce sufficient statistics for evaluating expectation values, circuits have to be run multiple times. The results of each repetition are concatenated in OutputRegisters (List[List[bool]], List[List[float]], List[List[complex]]).

Parameters:

measurement (Measurement) -- The measurement that is run on the backend.

Returns:

The output registers written by the evaluated circuits.

Return type:

Tuple[Dict[str, List[List[bool]]], Dict[str, List[List[float]]], Dict[str, List[List[complex]]]]

Raises:
  • TypeError -- Circuit argument cannot be converted to qoqo Circuit

  • RuntimeError -- Running Circuit failed

to_bincode()

Return the bincode representation of the SimulatorBackend using the bincode crate.

Returns:

The serialized SimulatorBackend (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize SimulatorBackend to bytes.

to_json()

Return the json representation of the SimulatorBackend.

Returns:

The serialized form of SimulatorBackend.

Return type:

str

Raises:

ValueError -- Cannot serialize SimulatorBackend to json.

class qoqo_qryd.TweezerDevice(seed, controlled_z_phase_relation, controlled_phase_phase_relation, /)

Tweezer Device

This interface does not allow setting any piece of information about the device tweezers. This class is meant to be used by the end user.

Parameters:
  • seed ((Optional[int])) -- Optional seed, for simulation purposes.

  • controlled_z_phase_relation ((Optional[Union[str, float]])) -- The relation to use for the PhaseShiftedControlledZ gate. It can be hardcoded to a specific value if a float is passed in as String.

  • controlled_phase_phase_relation ((Optional[Union[str, float]])) -- The relation to use for the PhaseShiftedControlledPhase gate.

add_qubit_tweezer_mapping(tweezer, /)

Modifies the qubit -> tweezer mapping of the device.

If a qubit -> tweezer mapping is already present, it is overwritten.

Parameters:
  • qubit (int) -- The index of the qubit.

  • tweezer (int) -- The index of the tweezer.

Returns:

The updated qubit -> tweezer mapping.

Return type:

dict[int, int]

Raises:

ValueError -- The tweezer is not present in the device.

available_layouts()

Returns a list of all available Layout names.

Returns:

The list of all available Layout names.

Return type:

List[str]

current_layout()

Get the name of the current layout.

Returns:

The name of the current layout.

Return type:

str

deactivate_qubit()

Deactivate the given qubit in the device.

Parameters:

qubit (int) -- The input qubit identifier.

Returns:

The updated qubit -> tweezer mapping.

Return type:

dict[int, int]

Raises:

PyValueError -- If the given qubit identifier is not present in the mapping.

draw(pixel_per_point, file_save_path, /)

Creates a graph representing a TweezerDevice.

Parameters:
  • draw_shifts (Optional[bool]) -- Whether to draw shifts or not. Default: false

  • pixel_per_point (Optional[float]) -- The quality of the image.

  • file_save_path (Optional[str]) -- Path to save the image to. Default: output the image with the display method.

Raises:

PyValueError - if there is no layout, an error occurred during the compilation or and invalid path was provided. --

static from_api(device_name, access_token, mock_port, seed, api_version, /)

Creates a new TweezerDevice instance containing populated tweezer data.

This requires a valid QRYD_API_TOKEN. Visit https://thequantumlaend.de/get-access/ to get one.

Parameters:
  • device_name (Optional[str]) -- The name of the device to instantiate. Defaults to "qryd_emulator".

  • access_token (Optional[str]) --

    An access_token is required to access QRYD hardware and emulators. The access_token can either be given as an argument here

    or set via the environmental variable $QRYD_API_TOKEN.

  • mock_port (Optional[str]) -- Server port to be used for testing purposes.

  • seed (Optional[int]) -- Optionally overwrite seed value from downloaded device instance.

  • dev (Optional[bool]) -- The boolean to set the dev header to.

  • api_version (Optional[str]) -- The version of the QRYD API to use. Defaults to "v1_1".

Returns:

The new TweezerDevice instance with populated tweezer data.

Return type:

TweezerDevice

Raises:

RoqoqoBackendError --

static from_bincode(input, /)

Convert the bincode representation of the TweezerDevice to a TweezerDevice using the bincode crate.

Parameters:

input (ByteArray) -- The serialized TweezerDevice (in bincode form).

Returns:

The deserialized TweezerDevice.

Return type:

TweezerDevice

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

  • ValueError -- Input cannot be deserialized to TweezerDevice.

static from_json(input, /)

Convert the json representation of a TweezerDevice to a TweezerDevice.

If a default_layout is found in the input, a layout switch is executed. Additionally, a gate set check is performed.

Parameters:

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

Returns:

The deserialized TweezerDevice.

Return type:

TweezerDevice

Raises:

ValueError -- Input cannot be deserialized to TweezerDevice or the device does not have valid QRyd gates available.

static from_mutable(device, /)

Creates a new TweezerDevice instance from a TweezerMutableDevice instance.

Parameters:

device (TweezerMutableDevice) -- The TweezerMutableDevice instance.

Returns:

The new TweezerDevice instance.

Return type:

TweezerDevice

gate_time_controlled_phase(target, phi, theta, /)

Returns the gate time of a PhaseShiftedControlledPhase operation with the given qubits and phi and theta angles.

Parameters:
  • control (int) -- The control qubit the gate acts on

  • target (int) -- The target qubit the gate acts on

  • phi (float) -- The phi angle to be checked.

  • theta (float) -- The theta angle to be checked.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available on the device.

gate_time_controlled_z(target, phi, /)

Returns the gate time of a PhaseShiftedControlledZ operation with the given qubits and phi angle.

Parameters:
  • control (int) -- The control qubit the gate acts on

  • target (int) -- The target qubit the gate acts on

  • phi (float) -- The phi angle to be checked.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available on the device.

generic_device()

Turns Device into GenericDevice

Can be used as a generic interface for devices when a boxed dyn trait object cannot be used (for example when the interface needs to be serialized)

Returns:

The device in generic representation

Return type:

GenericDevice

Note

GenericDevice uses nested HashMaps to represent the most general device connectivity. The memory usage will be inefficient for devices with large qubit numbers.

get_allow_reset()

Get whether the device allows PragmaActiveReset operations or not.

Returns:

Whether the device allows PragmaActiveReset operations or not.

Return type:

bool

get_available_gates_names()

Get the names of the available gates in the given layout.

Parameters:

layout_name (Optional[str]) -- The name of the layout. Defaults to the current Layout.

Returns:

List of the names of the available gates in the given layout.

Return type:

list[str]

Raises:

ValueError -- No layout name provided and no current layout set.

get_qubit_to_tweezer_mapping()

Get the qubit -> tweezer mapping of the device.

Returns:

The qubit -> tweezer mapping. None: The mapping is empty.

Return type:

dict[int, int]

multi_qubit_gate_time(qubits, /)

Returns the gate time of a multi qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

number_qubits()

Return number of qubits in device.

Returns:

The number of qubits.

Return type:

int

number_tweezer_positions()

Returns the number of total tweezer positions in the device.

Parameters:

layout_name (Optional[str]) -- The name of the layout to reference. Defaults to the current layout.

Returns:

The number of tweezer positions in the device.

Return type:

int

phase_shift_controlled_phase()

Returns the PhaseShiftedControlledPhase phase shift according to the device's relation.

Returns:

The PhaseShiftedControlledPhase phase shift.

Return type:

float

Raises:

ValueError -- Error in relation selection.

phase_shift_controlled_z()

Returns the PhaseShiftedControlledZ phase shift according to the device's relation.

Returns:

The PhaseShiftedControlledZ phase shift.

Return type:

float

Raises:

ValueError -- Error in relation selection.

qrydbackend()

Returns the backend associated with the device.

seed()

Returns the seed usized for the API.

single_qubit_gate_time(qubit, /)

Returns the gate time of a single qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

switch_layout(with_trivial_map, /)

Switch to a different pre-defined Layout.

It is updated only if the given Layout name is present in the device's Layout register. If the qubit -> tweezer mapping is empty, it is trivially populated by default.

Parameters:
  • layout_number (str) -- The number index of the new Layout.

  • with_trivial_map (bool) -- Whether the qubit -> tweezer mapping should be trivially populated. Defaults to true.

Raises:

PyValueError --

three_qubit_gate_time(control_0, control_1, target, /)

Returns the gate time of a three qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

to_bincode()

Return the bincode representation of the TweezerDevice using the bincode crate.

Returns:

The serialized TweezerDevice (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize TweezerDevice to bytes.

to_json()

Return the json representation of the TweezerDevice.

Additionally, a gate set check is performed.

Returns:

The serialized form of TweezerDevice.

Return type:

str

Raises:

ValueError -- Cannot serialize TweezerDevice to json or the device does not have valid QRyd gates available.

two_qubit_edges()

Return the list of pairs of qubits linked by a native two-qubit-gate in the device.

A pair of qubits is considered linked by a native two-qubit-gate if the device can implement a two-qubit-gate between the two qubits without decomposing it into a sequence of gates that involves a third qubit of the device. The two-qubit-gate also has to form a universal set together with the available single qubit gates.

The returned vectors is a simple, graph-library independent, representation of the undirected connectivity graph of the device. It can be used to construct the connectivity graph in a graph library of the user's choice from a list of edges and can be used for applications like routing in quantum algorithms.

Returns:

List of two qubit edges in the undirected connectivity graph

Return type:

Sequence[(int, int)]

two_qubit_gate_time(control, target, /)

Returns the gate time of a two qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

two_tweezer_edges()

Returns the two tweezer edges of the device.

And edge between two tweezer is valid only if the PhaseShiftedControlledPhase gate can be performed.

Returns:

List of two tweezer edges

Return type:

Sequence[(int, int)]

class qoqo_qryd.TweezerMutableDevice(seed, controlled_z_phase_relation, controlled_phase_phase_relation, /)

Tweezer Mutable Device

This interface allows setting any piece of information about the device tweezer.

Parameters:
  • controlled_z_phase_relation ((Optional[Union[str, float]])) -- The relation to use for the PhaseShiftedControlledZ gate. It can be hardcoded to a specific value if a float is passed in as String.

  • controlled_phase_phase_relation ((Optional[Union[str, float]])) -- The relation to use for the PhaseShiftedControlledPhase gate.

add_layout()

Add a new layout to the device.

Parameters:

name (str) -- The name that is assigned to the new Layout.

add_qubit_tweezer_mapping(tweezer, /)

Modifies the qubit -> tweezer mapping of the device.

If a qubit -> tweezer mapping is already present, it is overwritten.

Parameters:
  • qubit (int) -- The index of the qubit.

  • tweezer (int) -- The index of the tweezer.

Returns:

The updated qubit -> tweezer mapping.

Return type:

dict[int, int]

Raises:

ValueError -- The tweezer is not present in the device.

available_layouts()

Returns a list of all available Layout names.

Returns:

The list of all available Layout names.

Return type:

List[str]

current_layout()

Get the name of the current layout.

Returns:

The name of the current layout.

Return type:

str

deactivate_qubit()

Deactivate the given qubit in the device.

Parameters:

qubit (int) -- The input qubit identifier.

Returns:

The updated qubit -> tweezer mapping.

Return type:

dict[int, int]

Raises:

PyValueError -- If the given qubit identifier is not present in the mapping.

draw(pixel_per_point, file_save_path, /)

Creates a graph representing a TweezerDevice.

Parameters:
  • draw_shifts (Optional[bool]) -- Whether to draw shifts or not. Default: false

  • pixel_per_point (Optional[float]) -- The quality of the image.

  • file_save_path (Optional[str]) -- Path to save the image to. Default: output the image with the display method.

Raises:

PyValueError - if there is no layout, an error occurred during the compilation or and invalid path was provided. --

static from_bincode(input, /)

Convert the bincode representation of the TweezerMutableDevice to an TweezerMutableDevice using the bincode crate.

Parameters:

input (ByteArray) -- The serialized TweezerMutableDevice (in bincode form).

Returns:

The deserialized TweezerMutableDevice.

Return type:

TweezerMutableDevice

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

  • ValueError -- Input cannot be deserialized to TweezerMutableDevice.

static from_json(input, /)

Convert the json representation of a TweezerMutableDevice to an TweezerMutableDevice.

Additionally, a gate set check is performed.

Parameters:

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

Returns:

The deserialized TweezerMutableDevice.

Return type:

TweezerMutableDevice

Raises:

ValueError -- Input cannot be deserialized to TweezerMutableDevice or the device does not have valid QRyd gates available.

gate_time_controlled_phase(target, phi, theta, /)

Returns the gate time of a PhaseShiftedControlledPhase operation with the given qubits and phi and theta angles.

Parameters:
  • control (int) -- The control qubit the gate acts on

  • target (int) -- The target qubit the gate acts on

  • phi (float) -- The phi angle to be checked.

  • theta (float) -- The theta angle to be checked.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available on the device.

gate_time_controlled_z(target, phi, /)

Returns the gate time of a PhaseShiftedControlledZ operation with the given qubits and phi angle.

Parameters:
  • control (int) -- The control qubit the gate acts on

  • target (int) -- The target qubit the gate acts on

  • phi (float) -- The phi angle to be checked.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available on the device.

generic_device()

Turns Device into GenericDevice

Can be used as a generic interface for devices when a boxed dyn trait object cannot be used (for example when the interface needs to be serialized)

Returns:

The device in generic representation

Return type:

GenericDevice

Note

GenericDevice uses nested HashMaps to represent the most general device connectivity. The memory usage will be inefficient for devices with large qubit numbers.

get_allow_reset()

Get whether the device allows PragmaActiveReset operations or not.

Returns:

Whether the device allows PragmaActiveReset operations or not.

Return type:

bool

get_available_gates_names()

Get the names of the available gates in the given layout.

Parameters:

layout_name (Optional[str]) -- The name of the layout. Defaults to the current Layout.

Returns:

List of the names of the available gates in the given layout.

Return type:

list[str]

Raises:

ValueError -- No layout name provided and no current layout set.

get_qubit_to_tweezer_mapping()

Get the qubit -> tweezer mapping of the device.

Returns:

The qubit -> tweezer mapping. None: The mapping is empty.

Return type:

dict[int, int]

multi_qubit_gate_time(qubits, /)

Returns the gate time of a multi qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

number_qubits()

Return number of qubits in device.

Returns:

The number of qubits.

Return type:

int

number_tweezer_positions()

Returns the number of total tweezer positions in the device.

Parameters:

layout_name (Optional[str]) -- The name of the layout to reference. Defaults to the current layout.

Returns:

The number of tweezer positions in the device.

Return type:

int

phase_shift_controlled_phase()

Returns the PhaseShiftedControlledPhase phase shift according to the device's relation.

Returns:

The PhaseShiftedControlledPhase phase shift.

Return type:

float

Raises:

ValueError -- Error in relation selection.

phase_shift_controlled_z()

Returns the PhaseShiftedControlledZ phase shift according to the device's relation.

Returns:

The PhaseShiftedControlledZ phase shift.

Return type:

float

Raises:

ValueError -- Error in relation selection.

qrydbackend()

Returns the backend associated with the device.

seed()

Returns the seed usized for the API.

set_allow_reset()

Set whether the device allows PragmaActiveReset operations or not.

Parameters:

allow_reset (bool) -- Whether the device should allow PragmaActiveReset operations or not.

Raises:

ValueError -- The device isn't compatible with PragmaActiveReset.

set_allowed_tweezer_shifts(allowed_shifts, layout_name, /)

Set the allowed Tweezer shifts of a specified Tweezer.

The tweezer give the tweezer a qubit can be shifted out of. The values are lists over the directions the qubit in the tweezer can be shifted into. The items in the list give the allowed tweezers the qubit can be shifted into in order. For a list 1,2,3 the qubit can be shifted into tweezer 1, into tweezer 2 if tweezer 1 is not occupied, and into tweezer 3 if tweezer 1 and 2 are not occupied.

Parameters:
  • tweezer (int) -- The index of the tweezer.

  • allowed_shifts (list[list[int]]) -- The allowed tweezer shifts.

  • layout_name (Optional[str]) -- The name of the Layout to apply the allowed shifts in. Defaults to the current Layout.

Raises:

ValueError -- The tweezer or shifts are not present in the device or the given tweezer is contained in the shift list.

set_allowed_tweezer_shifts_from_rows(layout_name, /)

Set the allowed Tweezer shifts from a list of tweezers.

The items in the rows give the allowed tweezers that qubit can be shifted into. For a row defined as 1,2,3, a qubit in tweezer 1 can be shifted into tweezer 2, and into tweezer 3 if tweezer 2 is not occupied by a qubit.

Parameters:
  • row_shifts (list[list[int]]) -- A list of lists, each representing a row of tweezers.

  • layout_name (Optional[str]) -- The name of the Layout to apply the allowed shifts in. Defaults to the current Layout.

Raises:

ValueError -- The involved tweezers are not present in the device.

set_default_layout()

Set the name of the default layout to use and switch to it.

Parameters:

layout (str) -- The name of the layout to use.

Raises:

ValueError -- The given layout name is not present in the layout register.

set_tweezer_multi_qubit_gate_time(tweezers, gate_time, layout_name, /)

Set the time of a multi-qubit gate for a list of tweezers in a given Layout.

Parameters:
  • hqslang (str) -- The hqslang name of a multi-qubit gate.

  • tweezers (List[int]) -- The list of tweezer indexes.

  • gate_time (float) -- The the gate time for the given gate.

  • layout_name (Optional[str]) -- The name of the Layout to apply the gate time in. Defaults to the current Layout.

Raises:

ValueError -- No layout name provided and no current layout set.

set_tweezer_single_qubit_gate_time(tweezer, gate_time, layout_name, /)

Set the time of a single-qubit gate for a tweezer in a given Layout.

Parameters:
  • hqslang (str) -- The hqslang name of a single-qubit gate.

  • tweezer (int) -- The index of the tweezer.

  • gate_time (float) -- The the gate time for the given gate.

  • layout_name (Optional[str]) -- The name of the Layout to apply the gate time in. Defaults to the current Layout.

Raises:

ValueError -- No layout name provided and no current layout set.

set_tweezer_three_qubit_gate_time(tweezer0, tweezer1, tweezer2, gate_time, layout_name, /)

Set the time of a three-qubit gate for a tweezer trio in a given Layout.

Parameters:
  • hqslang (str) -- The hqslang name of a three-qubit gate.

  • tweezer0 (int) -- The index of the first tweezer.

  • tweezer1 (int) -- The index of the second tweezer.

  • tweezer2 (int) -- The index of the third tweezer.

  • gate_time (float) -- The the gate time for the given gate.

  • layout_name (Optional[str]) -- The name of the Layout to apply the gate time in. Defaults to the current Layout.

Raises:

ValueError -- No layout name provided and no current layout set.

set_tweezer_two_qubit_gate_time(tweezer0, tweezer1, gate_time, layout_name, /)

Set the time of a two-qubit gate for a tweezer couple in a given Layout.

Parameters:
  • hqslang (str) -- The hqslang name of a single-qubit gate.

  • tweezer0 (int) -- The index of the first tweezer.

  • tweezer1 (int) -- The index of the second tweezer.

  • gate_time (float) -- The the gate time for the given gate.

  • layout_name (Optional[str]) -- The name of the Layout to apply the gate time in. Defaults to the current Layout.

Raises:

ValueError -- No layout name provided and no current layout set.

set_tweezers_per_row(layout_name, /)

Set the tweezer per row value for a given Layout.

This is needed for dynamically switching layouts during circuit execution. Only switching between layouts having the same tweezer per row value is supported.

Parameters:
  • tweezers_per_row (List[int]) -- Vector containing the number of tweezers per row to set.

  • layout_name (Optional[str]) -- The name of the Layout to set the tweezer per row for. Defaults to the current Layout.

Raises:

ValueError -- No layout name provided and no current layout set.

single_qubit_gate_time(qubit, /)

Returns the gate time of a single qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

switch_layout(with_trivial_map, /)

Switch to a different pre-defined Layout.

It is updated only if the given Layout name is present in the device's Layout register. If the qubit -> tweezer mapping is empty, it is trivially populated by default.

Parameters:
  • layout_number (str) -- The number index of the new Layout.

  • with_trivial_map (bool) -- Whether the qubit -> tweezer mapping should be trivially populated. Defaults to true.

Raises:

PyValueError --

three_qubit_gate_time(control_0, control_1, target, /)

Returns the gate time of a three qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

to_bincode()

Return the bincode representation of the TweezerMutableDevice using the bincode crate.

Returns:

The serialized TweezerMutableDevice (in bincode form).

Return type:

ByteArray

Raises:

ValueError -- Cannot serialize TweezerMutableDevice to bytes.

to_json()

Return the json representation of the TweezerMutableDevice.

Additionally, a gate set check is performed.

Returns:

The serialized form of TweezerMutableDevice.

Return type:

str

Raises:

ValueError -- Cannot serialize TweezerMutableDevice to json or the device does not have valid QRyd gates available.

two_qubit_edges()

Return the list of pairs of qubits linked by a native two-qubit-gate in the device.

A pair of qubits is considered linked by a native two-qubit-gate if the device can implement a two-qubit-gate between the two qubits without decomposing it into a sequence of gates that involves a third qubit of the device. The two-qubit-gate also has to form a universal set together with the available single qubit gates.

The returned vectors is a simple, graph-library independent, representation of the undirected connectivity graph of the device. It can be used to construct the connectivity graph in a graph library of the user's choice from a list of edges and can be used for applications like routing in quantum algorithms.

Returns:

List of two qubit edges in the undirected connectivity graph

Return type:

Sequence[(int, int)]

two_qubit_gate_time(control, target, /)

Returns the gate time of a two qubit operation on this device.

Returns:

The gate time.

Return type:

float

Raises:

ValueError -- The gate is not available in the device.

two_tweezer_edges()

Returns the two tweezer edges of the device.

And edge between two tweezer is valid only if the PhaseShiftedControlledPhase gate can be performed.

Returns:

List of two tweezer edges

Return type:

Sequence[(int, int)]

qoqo_qryd.device_from_api(device_name=None, access_token=None, seed=None, dev=None, api_version=None)

Creates a new TweezerDevice instance containing populated tweezer data or EmulatorDevice instance.

This requires a valid QRYD_API_TOKEN. Visit https://thequantumlaend.de/get-access/ to get one.

Args

device_name (Optional[str]): The name of the device to instantiate. Defaults to "qryd_emulator". access_token (Optional[str]): An access_token is required to access QRYD hardware and emulators.

The access_token can either be given as an argument here

or set via the environmental variable $QRYD_API_TOKEN.

seed (Optional[int]): Optionally overwrite seed value from downloaded device instance. dev (Optional[bool]): The boolean to set the dev header to. api_version (Optional[str]): The version of the QRYD API to use. Defaults to "v1_1".

Returns
Union[TweezerDevice, EmulatorDevice]: Either the TweezerDevice or EmulatorDevice instance

depending on the pulled information.

Raises:

RoqoqoBackendError --