def initialize(self): """ Sets the statevector according to the current state of qubits """ self.Statevec = Sparse.Vector(np.array([1], dtype=complex)) for qbit in self.Qbits[::-1]: self.Statevec = self.Statevec.outer(qbit.vals)
def setStateVec(self, newVec): """ Allows the user to set the state vector to a new vector. Automatically normalises the vector. :param newVec: (list) The new vector to become the state vector """ newVec = np.array(newVec, dtype=complex) assert self.Statevec.Dimension == newVec.size, 'Wrong dimensions for new statevector' normal_const = np.sqrt((newVec * newVec.conj()).sum()) self.Statevec = Sparse.Vector(newVec / normal_const)
def setQbits(self, qbits, vals): """ Sets the initial values of the qubits if required, although it is preferred to use gates for this step. Automatically normalizes the Qbit :param qbits: (list) qubts to be set :param vals: (list) The values that the qubits should be set to. Each entry containing two values """ for qbit in qbits: self.Qbits[qbit].vals = Sparse.Vector( np.array(vals[qbit]) / np.linalg.norm(vals[qbit])) self.initialize()
def __init__(self): self.vals = Sparse.Vector(np.array([1. + 0.j, 0. + 0.j]))