qgym.envs.scheduling.machine_properties module

This module contains the MachineProperties class, which helps with conveniently setting up machine properties for the scheduling environment.

Usage:

The code below will create MachineProperties which will have the following properties:

  • The machine has two qubits.

  • The machine supports the X, Y, C-NOT and Measure gates.

  • Multiple Measure gates should start in the same cycle, or wait till the previous one is done.

  • The X and Y gates cannot be performed in the same cycle.

from qgym.envs.scheduling import MachineProperties

hardware_spec = MachineProperties(n_qubits=2)
hardware_spec.add_gates({"x": 2, "y": 2, "cnot": 4, "measure": 10})
hardware_spec.add_same_start(["measure"])
hardware_spec.add_not_in_same_cycle([("x", "y")])
class qgym.envs.scheduling.machine_properties.MachineProperties(n_qubits)[source]

Bases: object

MachineProperties is a class to conveniently setup machine properties for the Scheduling environment.

__init__(n_qubits)[source]

Init of the MachineProperties class.

Parameters:

n_qubits (int) – Number of qubits of the machine.

__repr__()[source]

Make a string representation without endline characters.

Return type:

str

__str__()[source]

Make a string representation of the machine properties.

Return type:

str

add_gates(gates)[source]

Add gates to the machine properties that should be supported.

Parameters:

gates (Mapping[str, int]) – Mapping of gates that the machine can perform as keys, and the number of machine cycles (time) as values.

Return type:

MachineProperties

Returns:

The MachineProperties with the added gates.

add_not_in_same_cycle(gates)[source]

Add gates that should not start in the same cycle.

Parameters:

gates (Iterable[tuple[str, str]]) – Iterable of tuples of gate names that should not start in the same cycle.

Return type:

MachineProperties

Returns:

The MachineProperties with an updated not_in_same_cycle property. The not_in_same_cycle property is updated according to the input gates.

add_same_start(gates)[source]

Add gates that should start in the same cycle, or wait till the previous gate is done.

Parameters:

gates (Iterable[str]) – Iterable of gate names that should start in the same cycle.

Return type:

MachineProperties

Returns:

The MachineProperties with the same start gates.

encode()[source]

Encode the gates in the machine properties to integer values.

Return type:

GateEncoder

Returns:

The GateEncoder used to encode the gates. This GateEncoder can be used to decode the gates or encode quantum circuits containing the same gate names as in this MachineProperties object.

classmethod from_file(filename)[source]

Load MachineProperties from a JSON file. Not implemented.

Return type:

MachineProperties

classmethod from_mapping(machine_properties)[source]

Initialize the MachineProperties class from a Mapping containing valid machines properties.

Parameters:

machine_properties (Mapping[str, Any]) – Mapping containing valid machine properties.

Return type:

MachineProperties

Returns:

Initialized MachineProperties object with the properties described in the machine_properties Mapping.

property gates: dict[str, int] | dict[int, int]

Return a``Dict`` with the gate names the machine can perform as keys, and the number of machine cycles (time) as values.

property n_gates: int

Return the number of supported gates.

property n_qubits: int

Return the number of qubits of the machine.

property not_in_same_cycle: dict[str, set[str]] | dict[int, set[int]]

Gates that can not start in the same cycle.

property same_start: set[str] | set[int]

Set of gate names that should start in the same cycle, or wait till the previous gate is done.