Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 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)