Exemplo n.º 1
0
    def test_qft(self):
        N = 4
        q = QubitSystem(N)
        # put q into a non-uniform mixed state
        hadamard_gate(N) * q
        tensor_power(phase_shift_gate(pi), N) * q

        # classical FFT of coefficients, normalized to be unitary like the QFT
        yhat = fft(q._QubitSystem__coeffs) / sqrt(2 ** N)
        qft(q)
        self.assertTrue(numpy.max(numpy.abs(q._QubitSystem__coeffs - yhat)) < EPS)
Exemplo n.º 2
0
def hadamard_gate(n=1):
    """Factory method for Hadamard gate.

    Args:
        n: Number of qubits the gate operates on. Default is 1.
    """
    return tensor_power(QuantumGate(array([[1./sqrt(2), 1./sqrt(2)],
                                            [1./sqrt(2), -1./sqrt(2)]])), n)