-
Notifications
You must be signed in to change notification settings - Fork 56
/
testStaticGate.py
61 lines (38 loc) · 1.5 KB
/
testStaticGate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
import pygsti
import numpy as np
from pygsti.objects import StaticDenseOp
from ..testutils import BaseTestCase, compare_files, temp_files
class StaticGateTestCase(BaseTestCase):
def setUp(self):
super(StaticGateTestCase, self).setUp()
self.gate = StaticDenseOp([[0,0], [0,0]])
def test_bad(self):
gate = self.gate.copy()
with self.assertRaises(ValueError):
gate.set_value([])
with self.assertRaises(ValueError):
gate.set_value([[1, 2],[1, 2]])
gate.dim = 'adfadsflkj'
with self.assertRaises(ValueError):
gate.set_value([[1, 2],[1, 2]])
with self.assertRaises(ValueError):
gate.set_value([[[1, 2]],[], []])
self.assertEqual(gate.num_params(), 0)
self.assertArraysAlmostEqual(gate.to_vector(), np.array([], 'd'))
with self.assertRaises(AssertionError):
gate.from_vector([1])
def test_deriv_wrt_params(self):
self.assertArraysAlmostEqual(self.gate.deriv_wrt_params(), np.array([]))
def test_transform(self):
with self.assertRaises(ValueError):
elT = pygsti.objects.FullGaugeGroupElement([[1,0],[0,1]])
self.gate.transform(elT) # can't transform a static gate - no params!
def test_compose(self):
self.gate.compose(self.gate)
def test_str(self):
str(self.gate)
def test_reduce(self):
self.gate.__reduce__()
if __name__ == '__main__':
unittest.main(verbosity=2)