def evolve(self, rho: Density) -> Density: """Apply the action of this channel upon a density""" N = rho.qubit_nb qubits = rho.qubits indices = list([qubits.index(q) for q in self.qubits]) + \ list([qubits.index(q) + N for q in self.qubits]) tensor = bk.tensormul(self.tensor, rho.tensor, indices) return Density(tensor, qubits, rho.memory)
def __matmul__(self, other: 'Gate') -> 'Gate': """Apply the action of this gate upon another gate Note that gate1 must contain all the qubits of qate0 """ if not isinstance(other, Gate): raise NotImplementedError() gate0 = self gate1 = other indices = [gate1.qubits.index(q) for q in gate0.qubits] tensor = bk.tensormul(gate0.tensor, gate1.tensor, indices) return Gate(tensor=tensor, qubits=gate1.qubits)
def __matmul__(self, other: 'Channel') -> 'Channel': if not isinstance(other, Channel): raise NotImplementedError() chan0 = self chan1 = other N = chan1.qubit_nb qubits = chan1.qubits indices = list([chan1.qubits.index(q) for q in chan0.qubits]) + \ list([chan1.qubits.index(q) + N for q in chan0.qubits]) tensor = bk.tensormul(chan0.tensor, chan1.tensor, indices) return Channel(tensor, qubits)
def run(self, ket: State) -> State: """Apply the action of this gate upon a state""" qubits = self.qubits indices = [ket.qubits.index(q) for q in qubits] tensor = bk.tensormul(self.tensor, ket.tensor, indices) return State(tensor, ket.qubits, ket.memory)