Ejemplo n.º 1
0
    def test_apply_cphase(self, tol, par, input, shots):
        """Tests that applying the CPhase gate yields the expected output."""
        device = SimulatorDevice(2, shots=shots)

        cphase_mat = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                               [0, 0, 0, np.exp(1j * par)]])

        expected = cphase_mat @ input

        device.reset()
        device._initial_state = np.array(input, dtype=np.complex64)
        device.apply([ops.CPhase(par, wires=[0, 1])])

        assert np.allclose(device.state, expected, **tol)
Ejemplo n.º 2
0
    def test_apply_iswap(self, tol, input, shots):
        """Tests that applying the iSWAP gate yields the expected output."""
        device = SimulatorDevice(2, shots=shots)

        iswap_mat = np.array([[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0],
                              [0, 0, 0, 1]])

        expected = iswap_mat @ input

        device.reset()
        device._initial_state = np.array(input, dtype=np.complex64)
        device.apply([ops.ISWAP(wires=[0, 1])])

        assert np.allclose(device.state, expected, **tol)