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 theScheduling
environment.- __init__(n_qubits)[source]
Init of the MachineProperties class.
- Parameters:
n_qubits (
int
) – Number of qubits of the machine.
- 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:
- 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:
- Returns:
The
MachineProperties
with an updatednot_in_same_cycle
property. Thenot_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:
- Returns:
The
MachineProperties
with the same start gates.
- encode()[source]
Encode the gates in the machine properties to integer values.
- Return type:
- Returns:
The
GateEncoder
used to encode the gates. ThisGateEncoder
can be used to decode the gates or encode quantum circuits containing the same gate names as in thisMachineProperties
object.
- classmethod from_file(filename)[source]
Load MachineProperties from a JSON file. Not implemented.
- Return type:
- classmethod from_mapping(machine_properties)[source]
Initialize the
MachineProperties
class from aMapping
containing valid machines properties.- Parameters:
machine_properties (
Mapping
[str
,Any
]) –Mapping
containing valid machine properties.- Return type:
- Returns:
Initialized
MachineProperties
object with the properties described in the machine_propertiesMapping
.
- 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.