Exemplo n.º 1
0
    def test_controlled_rotation(self, init_state, tol):
        """Test three axis controlled-rotation gate"""
        dev = DefaultQubitTF(wires=2)
        state = init_state(2)

        a = 0.542
        b = 1.3432
        c = -0.654

        queue = [qml.QubitStateVector(state, wires=[0, 1])]
        queue += [qml.CRot(a, b, c, wires=[0, 1])]
        dev.apply(queue)

        res = dev.state
        expected = CRot3(a, b, c) @ state
        assert np.allclose(res, expected, atol=tol, rtol=0)
Exemplo n.º 2
0
    def test_controlled_rotation_integration(self, init_state, tol):
        """Test the integration of the two-qubit controlled rotation by passing
        a TF data structure as a parameter"""
        dev = qml.device("default.qubit.tf", wires=2)
        a = 1.7
        b = 1.3432
        c = -0.654
        state = init_state(2)

        @qml.qnode(dev, interface='tf')
        def circuit(params):
            qml.QubitStateVector(state, wires=[0, 1])
            qml.CRot(params[0], params[1], params[2], wires=[0, 1])
            return qml.expval(qml.PauliZ(0))

        # Pass a TF Variable to the qfunc
        params = tf.Variable(np.array([a, b, c]))
        circuit(params)
        res = dev.state
        expected = CRot3(a, b, c) @ state
        assert np.allclose(res.numpy(), expected, atol=tol, rtol=0)