コード例 #1
0
    def test_three_qubit_no_parameters(self, init_state, analytic, shots, name,
                                       mat, tol):
        dev = SimulatorDevice(3, analytic=analytic, shots=shots)
        state = init_state(3)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0, 1, 2]),
                qml.__getattribute__(name)(wires=[0, 1, 2]),
            ])

        res = dev._state
        expected = mat @ state
        assert np.allclose(res, expected, **tol)
コード例 #2
0
    def test_two_qubit_no_parameters(self, init_state, shots, name, mat, tol):
        """Test PauliX application"""
        dev = SimulatorDevice(2, shots=shots)
        state = init_state(2)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0, 1]),
                qml.__getattribute__(name)(wires=[0, 1]),
            ])

        res = dev._state
        expected = mat @ state
        assert np.allclose(res, expected, **tol)
コード例 #3
0
    def test_two_qubits_parameters(self, init_state, analytic, shots, name,
                                   func, theta, tol):
        """Test application of two qubit gates with parameters"""
        dev = SimulatorDevice(2, analytic=analytic, shots=shots)
        state = init_state(2)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0, 1]),
                qml.__getattribute__(name)(theta, wires=[0, 1]),
            ])

        res = dev._state
        expected = func(theta) @ state
        assert np.allclose(res, expected, **tol)
コード例 #4
0
    def test_single_qubit_no_parameters(self, init_state, analytic, shots,
                                        name, mat, tol):
        """Test application of single qubit gates without parameters"""
        dev = SimulatorDevice(1, analytic=analytic, shots=shots)
        state = init_state(1)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0]),
                qml.__getattribute__(name)(wires=[0]),
            ])

        res = dev._state
        expected = mat @ state
        assert np.allclose(res, expected, **tol)
コード例 #5
0
    def test_three_qubit_no_parameters(self, init_state, shots, name, mat,
                                       tol):
        dev = MixedStateSimulatorDevice(3, shots=shots)
        state = init_state(3)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0, 1, 2]),
                qml.__getattribute__(name)(wires=[0, 1, 2]),
            ])

        res = dev._state
        expected = mat @ state
        expected = np.kron(expected, expected.conj()).reshape([8, 8])
        assert np.allclose(res, expected, **tol)
コード例 #6
0
    def test_single_qubit_parameters(self, init_state, analytic, shots, name,
                                     func, theta, tol):
        """Test application of single qubit gates with parameters"""
        dev = MixedStateSimulatorDevice(1, analytic=analytic, shots=shots)
        state = init_state(1)

        with mimic_execution_for_apply(dev):
            dev.apply([
                qml.QubitStateVector(state, wires=[0]),
                qml.__getattribute__(name)(theta, wires=[0]),
            ])

        res = dev._state
        expected = func(theta) @ state
        expected = np.kron(expected, expected.conj()).reshape([2, 2])
        assert np.allclose(res, expected, **tol)