qgym.envs.scheduling.rulebook module
This module contains the CommutationRulebook
class together with basic
commutation rules used in the Scheduling
environment.
Example
The code block below shows how to set up a CommutationRulebook
, with the
additional commutation rule that two C-NOT gates with the same control qubit
commute.
from qgym.env.scheduling.rulebook import CommutationRulebook
# cnot gates with the same control qubit commute
def cnot_commutation(gate1, gate2):
if gate1[0] == "cnot" and gate2[0] == "cnot":
if gate1[1] == gate2[1]:
return True
return False
# init the rulebook and add the commutation rule
rulebook = CommutationRulebook()
rulebook.add_rule(rulebook)
- class qgym.envs.scheduling.rulebook.CommutationRulebook(default_rules=True)[source]
Bases:
object
Commutation rulebook used in the
Scheduling
environment.- __init__(default_rules=True)[source]
Init of the
CommutationRulebook
.- Parameters:
default_rules (
bool
) – IfTrue
, default rules are used. Default rules dictate that gates with disjoint qubits commute and that gates that are exactly the same commute. IfFalse
, then no rules will be initialized.
- __repr__()[source]
Create a string representation of the
CommutationRulebook
.- Return type:
- commutes(gate1, gate2)[source]
Check if gate1 and gate2 commute according to the rules in the rulebook.