Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 line
1.6KB

  1. """
  2. Mock graphs used for testing
  3. """
  4. import numpy as np
  5. import abp
  6. from abp import GraphState, clifford, qi
  7. from numpy import random
  8. import pytest
  9. from anders_briegel import graphsim
  10. # We always run with A&B's CZ table when we are testing
  11. clifford.use_old_cz()
  12. class AndersWrapper(graphsim.GraphRegister):
  13. """ A wrapper for A&B to make the interface identical and enable equality testing """
  14. def __init__(self, nodes):
  15. assert list(nodes) == list(range(len(nodes)))
  16. super(AndersWrapper, self).__init__(len(nodes))
  17. def act_local_rotation(self, qubit, operation):
  18. operation = clifford.by_name[str(operation)]
  19. op = graphsim.LocCliffOp(operation)
  20. super(AndersWrapper, self).local_op(qubit, op)
  21. def act_cz(self, a, b):
  22. super(AndersWrapper, self).cphase(a, b)
  23. def measure(self, qubit, basis, force):
  24. basis = {1: graphsim.lco_X,
  25. 2: graphsim.lco_Y,
  26. 3: graphsim.lco_Z}[clifford.by_name[str(basis)]]
  27. return super(AndersWrapper, self).measure(qubit, basis, None, force)
  28. def __eq__(self, other):
  29. return self.to_json() == other.to_json()
  30. def act_circuit(self, circuit):
  31. for operation, node in circuit:
  32. if operation == "cz":
  33. self.act_cz(*node)
  34. else:
  35. self.act_local_rotation(node, operation)
  36. def test_circuit(circuit, n):
  37. """ Check that two classes exhibit the same behaviour for a given circuit """
  38. a = circuit_to_state(ABPWrapper, n, circuit)
  39. b = circuit_to_state(AndersWrapper, n, circuit)
  40. assert a == b