|
14 | 14 | import numpy as _np
|
15 | 15 |
|
16 | 16 | from pygsti.baseobjs import Basis as _Basis
|
| 17 | +from pygsti.baseobjs import statespace as _statespace |
17 | 18 | from pygsti.modelmembers.states.densestate import DenseState as _DenseState
|
18 | 19 | from pygsti.modelmembers.states.state import State as _State
|
19 | 20 | from pygsti.baseobjs.protectedarray import ProtectedArray as _ProtectedArray
|
@@ -53,12 +54,13 @@ class TPState(_DenseState):
|
53 | 54 | # alpha = 1/sqrt(d) = 1/(len(vec)**0.25).
|
54 | 55 | def __init__(self, vec, basis="pp", evotype="default", state_space=None):
|
55 | 56 | vector = _State._to_vector(vec)
|
56 |
| - if not isinstance(basis, _Basis): |
57 |
| - basis = _Basis.cast(basis, len(vector)) # don't perform this cast if we're given a basis |
58 |
| - firstEl = basis.elsize**-0.25 # not dim, as the dimension of the vector space may be less |
59 |
| - if not _np.isclose(vector[0], firstEl): |
60 |
| - raise ValueError("Cannot create TPState: " |
61 |
| - "first element must equal %g!" % firstEl) |
| 57 | + if basis is not None: |
| 58 | + if not isinstance(basis, _Basis): |
| 59 | + basis = _Basis.cast(basis, len(vector)) # don't perform this cast if we're given a basis |
| 60 | + firstEl = basis.elsize**-0.25 # not dim, as the dimension of the vector space may be less |
| 61 | + if not _np.isclose(vector[0], firstEl): |
| 62 | + raise ValueError("Cannot create TPState: first element must equal %g!" % firstEl) |
| 63 | + # if basis is None, don't check first element (hackfor de-serialization, so we don't need to store basis) |
62 | 64 |
|
63 | 65 | _DenseState.__init__(self, vector, evotype, state_space)
|
64 | 66 | assert(isinstance(self.columnvec, _ProtectedArray))
|
@@ -188,3 +190,9 @@ def has_nonzero_hessian(self):
|
188 | 190 | bool
|
189 | 191 | """
|
190 | 192 | return False
|
| 193 | + |
| 194 | + @classmethod |
| 195 | + def _from_memoized_dict(cls, mm_dict, serial_memo): |
| 196 | + vec = cls._decodemx(mm_dict['dense_superket_vector']) |
| 197 | + state_space = _statespace.StateSpace.from_nice_serialization(mm_dict['state_space']) |
| 198 | + return cls(vec, None, mm_dict['evotype'], state_space) # use basis=None to skip 1st element check |
0 commit comments