예제 #1
0
    def test_fswap_adjacent_identity(self):
        fswap_adjacent(self.reg, 0)
        self.eng.flush()

        ordered_wvfn = numpy.array(ordered_wavefunction(self.eng))
        expected = numpy.array([1.0] + [0.0] * 7)
        self.assertTrue(numpy.allclose(numpy.abs(ordered_wvfn),
                                       numpy.abs(expected)))
예제 #2
0
    def test_fswap_adjacent_001(self):
        X | self.reg[2]
        fswap_adjacent(self.reg, 0)
        self.eng.flush()

        ordered_wvfn = numpy.array(ordered_wavefunction(self.eng))
        expected = numpy.array([0.0] * 4 + [1.0] + [0.0] * 3)
        self.assertTrue(numpy.allclose(numpy.abs(ordered_wvfn),
                                       numpy.abs(expected)))
예제 #3
0
    def test_fswap_adjacent_superposition(self):
        All(H) | self.reg
        fswap_adjacent(self.reg, 0)
        self.eng.flush()

        ordered_wvfn = numpy.array(ordered_wavefunction(self.eng))
        expected = numpy.array([2. ** -1.5] * 8)
        expected[3] *= -1  # bitstring 110 gets sign-flipped by fermionic swap
        expected[7] *= -1  # bitstring 111 gets sign-flipped by fermionic swap
        self.assertTrue(numpy.allclose(ordered_wvfn, expected * -1j))