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
MachinePropertieswhich 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:
objectMachinePropertiesis a class to conveniently setup machine properties for theSchedulingenvironment.- __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]) –Mappingof gates that the machine can perform as keys, and the number of machine cycles (time) as values.- Return type:
- Returns:
The
MachinePropertieswith 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]]) –Iterableof tuples of gate names that should not start in the same cycle.- Return type:
- Returns:
The
MachinePropertieswith an updatednot_in_same_cycleproperty. Thenot_in_same_cycleproperty 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]) –Iterableof gate names that should start in the same cycle.- Return type:
- Returns:
The
MachinePropertieswith the same start gates.
- encode()[source]
Encode the gates in the machine properties to integer values.
- Return type:
- Returns:
The
GateEncoderused to encode the gates. ThisGateEncodercan be used to decode the gates or encode quantum circuits containing the same gate names as in thisMachinePropertiesobject.
- classmethod from_file(filename)[source]
Load MachineProperties from a JSON file. Not implemented.
- Return type:
- classmethod from_mapping(machine_properties)[source]
Initialize the
MachinePropertiesclass from aMappingcontaining valid machines properties.- Parameters:
machine_properties (
Mapping[str,Any]) –Mappingcontaining valid machine properties.- Return type:
- Returns:
Initialized
MachinePropertiesobject 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.