def __init__(self, static_state, errormap): evotype = errormap._evotype #from .operation import LindbladOp as _LPGMap #assert(evotype in ("densitymx", "svterm", "cterm")), \ # "Invalid evotype: %s for %s" % (evotype, self.__class__.__name__) if not isinstance(static_state, _State): static_state = _StaticState( static_state, evotype) # assume spamvec is just a vector assert(static_state._evotype == evotype), \ "`static_state` evotype must match `errormap` ('%s' != '%s')" % (static_state._evotype, evotype) assert (static_state.num_params == 0 ), "`static_state` 'reference' must have *zero* parameters!" #d2 = static_state.dim self.state_vec = static_state self.error_map = errormap self.terms = {} self.local_term_poly_coeffs = {} #Create representation rep = evotype.create_composed_state_rep(self.state_vec._rep, self.error_map._rep, static_state.state_space) _State.__init__(self, rep, evotype) _ErrorMapContainer.__init__(self, self.error_map) self.init_gpindices() # initialize our gpindices based on sub-members
def __init__(self, purevec, basis, evotype, state_space): purevec = _State._to_vector(purevec) purevec = purevec.astype(complex) state_space = _statespace.default_space_for_udim(purevec.shape[0]) if (state_space is None) \ else _statespace.StateSpace.cast(state_space) evotype = _Evotype.cast(evotype) basis = _Basis.cast( basis, state_space.dim) # basis for Hilbert-Schmidt (superop) space #Try to create a dense pure rep. If this fails, see if a dense superkey rep # can be created, as this type of rep can also hold arbitrary pure states. try: rep = evotype.create_pure_state_rep(purevec, basis, state_space) self._reptype = 'pure' self._purevec = self._basis = None except Exception: if len(purevec) == basis.dim and _np.linalg.norm( purevec.imag) < 1e-10: # Special case when a *superket* was provided instead of a purevec superket_vec = purevec.real # used as a convenience case that really shouldn't be used else: superket_vec = _bt.change_basis(_ot.state_to_dmvec(purevec), 'std', basis) rep = evotype.create_dense_state_rep(superket_vec, state_space) self._reptype = 'superket' self._purevec = purevec self._basis = basis _State.__init__(self, rep, evotype) DenseStateInterface.__init__(self)
def __init__(self, vec, evotype, state_space): vec = _State._to_vector(vec) state_space = _statespace.default_space_for_dim(vec.shape[0]) if (state_space is None) \ else _statespace.StateSpace.cast(state_space) evotype = _Evotype.cast(evotype) rep = evotype.create_dense_state_rep(vec, state_space) _State.__init__(self, rep, evotype) DenseStateInterface.__init__(self)
def __init__(self, factors, state_space): assert(len(factors) > 0), "Must have at least one factor!" self.factors = factors # do *not* copy - needs to reference common objects evotype = self.factors[0]._evotype rep = evotype.create_tensorproduct_state_rep([f._rep for f in factors], state_space) _State.__init__(self, rep, evotype) self.init_gpindices() # initialize our gpindices based on sub-members self._update_rep() # initializes rep data
def __init__(self, zvals, basis='pp', evotype="default", state_space=None): self._zvals = _np.ascontiguousarray(_np.array(zvals, _np.int64)) state_space = _statespace.default_space_for_num_qubits(len(self._zvals)) if (state_space is None) \ else _statespace.StateSpace.cast(state_space) basis = _Basis.cast( basis, state_space.dim) # basis for Hilbert-Schmidt (superop) space evotype = _Evotype.cast(evotype) self._evotype = evotype # set this before call to _State.__init__ so self.to_dense() can work... rep = evotype.create_computational_state_rep(self._zvals, basis, state_space) _State.__init__(self, rep, evotype)
def __init__(self, vec, basis, truncate=False, evotype="default", state_space=None): vector = _State._to_vector(vec) basis = _Basis.cast(basis, len(vector)) self.basis = basis self.basis_mxs = basis.elements # shape (len(vec), dmDim, dmDim) self.basis_mxs = _np.rollaxis(self.basis_mxs, 0, 3) # shape (dmDim, dmDim, len(vec)) assert(self.basis_mxs.shape[-1] == len(vector)) # set self.params and self.dmDim self._set_params_from_vector(vector, truncate) #parameter labels (parameter encode the Cholesky Lmx) labels = [] for i, ilbl in enumerate(basis.labels[1:]): for j, jlbl in enumerate(basis.labels[1:]): if i == j: labels.append("%s diagonal element of density matrix Cholesky decomp" % ilbl) elif j < i: labels.append("Re[(%s,%s) element of density matrix Cholesky decomp]" % (ilbl, jlbl)) else: labels.append("Im[(%s,%s) element of density matrix Cholesky decomp]" % (ilbl, jlbl)) #scratch space self.Lmx = _np.zeros((self.dmDim, self.dmDim), 'complex') state_space = _statespace.default_space_for_dim(len(vector)) if (state_space is None) \ else _statespace.StateSpace.cast(state_space) evotype = _Evotype.cast(evotype) _DenseState.__init__(self, vector, evotype, state_space) self._paramlbls = _np.array(labels, dtype=object)
def set_dense(self, vec): """ Set the dense-vector value of this state vector. Attempts to modify this state vector's parameters so that the raw state vector becomes `vec`. Will raise ValueError if this operation is not possible. Parameters ---------- vec : array_like or State A numpy array representing a state vector, or a State object. Returns ------- None """ vec = _State._to_vector(vec) firstEl = (self.dim)**-0.25 if (vec.size != self.dim): raise ValueError("Argument must be length %d" % self.dim) if not _np.isclose(vec[0], firstEl): raise ValueError("Cannot create TPState: " "first element must equal %g!" % firstEl) self._ptr[1:] = vec[1:] self._ptr_has_changed() self.dirty = True
def __init__(self, pure_state, evotype='default', dm_basis='pp'): if not isinstance(pure_state, _State): pure_state = _StaticState(_State._to_vector(pure_state), 'statevec') self.pure_state = pure_state self.basis = dm_basis # only used for dense conversion evotype = _Evotype.cast(evotype) #rep = evotype.create_state_rep() #rep.init_from_dense_purevec(pure_state) raise NotImplementedError( "Maybe this class isn't even needed, or need to create a static pure state class?" )
def __init__(self, identity, other_effects): evotype = other_effects[0]._evotype state_space = other_effects[0].state_space self.identity = _FullState( _State._to_vector(identity), evotype, state_space) # so easy to transform or depolarize by parent POVM self.other_effects = other_effects #Note: we assume that our parent will do the following: # 1) set our gpindices to indicate how many parameters we have # 2) set the gpindices of the elements of other_spamvecs so # that they index into our local parameter vector. _ConjugatedStatePOVMEffect.__init__(self, self.identity.copy()) self.init_gpindices() # initialize our gpindices based on sub-members self._construct_vector() # reset's self.base
def __init__(self, vec, basis="pp", evotype="default", state_space=None): vector = _State._to_vector(vec) if basis is not None: if not isinstance(basis, _Basis): basis = _Basis.cast(basis, len( vector)) # don't perform this cast if we're given a basis firstEl = basis.elsize**-0.25 # not dim, as the dimension of the vector space may be less if not _np.isclose(vector[0], firstEl): raise ValueError( "Cannot create TPState: first element must equal %g!" % firstEl) # if basis is None, don't check first element (hackfor de-serialization, so we don't need to store basis) _DenseState.__init__(self, vector, evotype, state_space) assert (isinstance(self.columnvec, _ProtectedArray)) self._paramlbls = _np.array( ["VecElement %d" % i for i in range(1, self.dim)], dtype=object)
def set_dense(self, vec): """ Set the dense-vector value of this SPAM vector. Attempts to modify this SPAM vector's parameters so that the raw SPAM vector becomes `vec`. Will raise ValueError if this operation is not possible. Parameters ---------- vec : array_like or SPAMVec A numpy array representing a SPAM vector, or a SPAMVec object. Returns ------- None """ vec = _State._to_vector(vec) if (vec.size != self.dim): raise ValueError("Argument must be length %d" % self.dim) self._ptr[:] = vec self._ptr_has_changed() self.dirty = True