-
Notifications
You must be signed in to change notification settings - Fork 55
/
test_replib.py
46 lines (36 loc) · 1.37 KB
/
test_replib.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
import numpy as np
import unittest
from ..util import BaseCase
from pygsti.modelpacks.legacy import std1Q_XYI as std
from pygsti.objects.replib import slowreplib
try:
from pygsti.objects.replib import fastreplib
_FASTREPLIB_LOADED = True
except ImportError:
_FASTREPLIB_LOADED = False
class ReplibBase(object):
def test_DMStateRep(self):
x = np.zeros(4, 'd')
staterep = self.replib.DMStateRep(x) # state rep
# TODO assert correctness
def test_DMEffectRepDense(self):
x = np.zeros(4, 'd')
staterep = self.replib.DMStateRep(x)
erep = self.replib.DMEffectRepDense(x)
self.assertAlmostEqual(erep.probability(staterep), 0.0)
def test_DMOpRepDense(self):
x = np.zeros(4, 'd')
staterep = self.replib.DMStateRep(x)
g = np.zeros((4, 4), 'd')
grep = self.replib.DMOpRepDense(g)
staterep2 = grep.acton(staterep)
self.assertEqual(type(staterep2), self.replib.DMStateRep)
class SlowReplibTester(ReplibBase, BaseCase):
replib = slowreplib
@unittest.skipUnless(_FASTREPLIB_LOADED, "`pygsti.objects.replib.fastreplib` not built")
class FastReplibTester(ReplibBase, BaseCase):
@classmethod
def setUpClass(cls):
# bind replib during test setup
# class should still be defined without fastreplib, so it can be shown as skipped
cls.replib = fastreplib