Skip to content

Instantly share code, notes, and snippets.

@eddieschoute
Last active April 2, 2018 14:30
Show Gist options
  • Save eddieschoute/9586c4a4734764e35492602cf1c3f030 to your computer and use it in GitHub Desktop.
Save eddieschoute/9586c4a4734764e35492602cf1c3f030 to your computer and use it in GitHub Desktop.
Gate hierarchy for qiskit
class Gate:
def apply(self, circuit: BaseQuantumCircuit) -> None
def qasm(self) -> String
class InvertibleGate(Gate):
def inverse(self) -> InvertibleGate
class HGate(InvertibleGate):
implementation...
class CNotGate(InvertibleGate):
etc...
class HGateMixin(BaseQuantumCircuit):
def h(self, params):
gate = HGate(...) # Construct hgate
gate.apply(self) # Apply hgate. The types add up since self inherits from BaseQuantumCircuit
class CNotMixin:
etc...
class StandardGateMixins(HGateMixin, CNotMixin, ...(all standard gate-mixins)):
"""Repackage all standard mixins into one for exporting."""
class QuantumCircuit(StandardGateMixins):
"""Would want to inherit from BaseQuantumCircuit and StandardGateMixins for clarity but cannot,
because of multiple inheritance conflict.
Still, QuantumCircuit inherits from BaseQuantumCircuit through the mixins."""
implementation...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment