test_gate.py 792 B

1234567891011121314151617181920212223242526272829303132333435
  1. import pytest
  2. from qcgpu.gate import Gate, h, x, y, z, s, t, sqrt_x
  3. import numpy as np
  4. def test_gate_creation():
  5. Gate(np.array([[0, 1], [1, 0]])) # A clearly unitary gate
  6. h()
  7. x()
  8. y()
  9. z()
  10. s()
  11. t()
  12. sqrt_x()
  13. def test_using_list():
  14. return Gate([[1, 0], [0, 1]])
  15. def test_non_unitary_gate_creation_fails():
  16. # A clearly non unitary gate
  17. with pytest.raises(Exception):
  18. return Gate(np.array([[12, 33], [-7j, 1]]))
  19. def test_large_gate_creation_fails():
  20. # A gate that is not 2x2
  21. with pytest.raises(Exception):
  22. return Gate(np.ones(4))
  23. def test_using_scalar_fails():
  24. with pytest.raises(Exception):
  25. return Gate(2)
  26. def test_using_string_fails():
  27. with pytest.raises(Exception):
  28. return Gate("this should fail")