__init__.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. This file contains the main circuit implementation/representation class
  3. """
  4. class Instruction:
  5. def __init__(self, name, qubits, parameters=None):
  6. self.name = name
  7. self.qubits = qubits
  8. self.parameters = parameters
  9. def __repr__(self):
  10. if self.parameters:
  11. return "{} ({}) {};".format(self.name, self.parameters, self.qubits)
  12. return "{} {};".format(self.name, self.qubits)
  13. class Circuit:
  14. """
  15. Represents a Quantum Circuit.
  16. The number of qubits is inferred from
  17. the instructions provided
  18. """
  19. def __init__(self):
  20. self.num_qubits = 0
  21. # Represents the instructions that are given to
  22. # the quantum circuit
  23. self.instructions = []
  24. # Represent the numerical remapping in the circuit,
  25. # to avoid badly labelled registers.
  26. self.idx_map = {}
  27. # TODO:
  28. # - Mirror
  29. # - Invert
  30. # - Combine multiple circuits
  31. # - Multiple register handling
  32. def add_instruction(self, gate_name, *qubits):
  33. # instruction
  34. pass
  35. def __repr__(self):
  36. return str(vars(self))
  37. if __name__ == "__main__":
  38. circuit = Circuit(3)
  39. print(circuit)
  40. h = Instruction('h', [0])
  41. print(h)