Пример #1
0
    def test_simple_circuits(self):

        default_qubit = qml.device('default.qubit', wires=4)

        for dev in self.devices:
            gates = [
                qml.PauliX(wires=0),
                qml.PauliY(wires=1),
                qml.PauliZ(wires=2),
                qml.S(wires=3),
                qml.T(wires=0),
                qml.RX(2.3, wires=1),
                qml.RY(1.3, wires=2),
                qml.RZ(3.3, wires=3),
                qml.Hadamard(wires=0),
                qml.Rot(0.1, 0.2, 0.3, wires=1),
                qml.CRot(0.1, 0.2, 0.3, wires=[2, 3]),
                qml.Toffoli(wires=[0, 1, 2]),
                qml.SWAP(wires=[1, 2]),
                qml.CSWAP(wires=[1, 2, 3]),
                qml.U1(1.0, wires=0),
                qml.U2(1.0, 2.0, wires=2),
                qml.U3(1.0, 2.0, 3.0, wires=3),
                qml.CRX(0.1, wires=[1, 2]),
                qml.CRY(0.2, wires=[2, 3]),
                qml.CRZ(0.3, wires=[3, 1]),
                qml.CZ(wires=[2, 3]),
                qml.QubitUnitary(np.array([[1, 0], [0, 1]]), wires=2),
            ]

            layers = 3
            np.random.seed(1967)
            gates_per_layers = [
                np.random.permutation(gates).numpy() for _ in range(layers)
            ]

            for obs in {
                    qml.PauliX(wires=0),
                    qml.PauliY(wires=0),
                    qml.PauliZ(wires=0),
                    qml.Identity(wires=0),
                    qml.Hadamard(wires=0)
            }:
                if obs.name in dev.observables:

                    def circuit():
                        """4-qubit circuit with layers of randomly selected gates and random connections for
                        multi-qubit gates."""
                        qml.BasisState(np.array([1, 0, 0, 0]),
                                       wires=[0, 1, 2, 3])
                        for gates in gates_per_layers:
                            for gate in gates:
                                if gate.name in dev.operations:
                                    qml.apply(gate)
                        return qml.expval(obs)

                    qnode_default = qml.QNode(circuit, default_qubit)
                    qnode = qml.QNode(circuit, dev)

                    assert np.allclose(qnode(), qnode_default(), atol=1e-3)
 def circuit(x, y, z):
     qml.Rot(x, y, z, wires=[0])
     return qml.expval.PauliZ(0)
Пример #3
0
 def circuit2(weights):
     qml.QubitStateVector(np.array([1, 0, 1, 1]) / np.sqrt(3), [0, 1])
     qml.Rot(weights[0], weights[1], 0.3, 0)
     qml.CNOT([0, 1])
     return qml.expval.PauliZ(0), qml.expval.PauliY(1)
Пример #4
0
 def circuit(x, y, z):
     qml.QubitStateVector(np.array([1, 0, 1, 1]) / np.sqrt(3), [0, 1])
     qml.Rot(x, y, z, 0)
     qml.CNOT([0, 1])
     return qml.expval.PauliZ(0), qml.expval.PauliY(1)
Пример #5
0
 def qf(x, y):
     qml.RX(np.pi / 4, [0])
     qml.Rot(y, x, 2 * x, [0])
     return qml.expval.PauliX(0)
Пример #6
0
 def qf(x, y, z):
     qml.RX(0.4, [0])
     qml.Rot(x, y, z, [0])
     qml.RY(-0.2, [0])
     return qml.expval.PauliZ(0)
Пример #7
0
 def qf_ok(x):
     qml.Rot(0.3, x, -0.2, [0])
     return qml.expval.PauliZ(0)
Пример #8
0
 def ansatz(x, y, z):
     qml.QubitStateVector(np.array([1, 0, 1, 1])/np.sqrt(3), wires=[0, 1])
     qml.Rot(x, y, z, wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
Пример #9
0
 def circuit1(weights, x=0.3):
     qml.QubitStateVector(np.array([1, 0, 1, 1]) / np.sqrt(3),
                          wires=[0, 1])
     qml.Rot(weights[0], weights[1], x, wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
Пример #10
0
 def qf(x, y):
     qml.RX(np.pi / 4, wires=[0])
     qml.Rot(y, x, 2 * x, wires=[0])
     return qml.expval(qml.PauliX(0))
Пример #11
0
 def qf(x, y, z):
     qml.RX(0.4, wires=[0])
     qml.Rot(x, y, z, wires=[0])
     qml.RY(-0.2, wires=[0])
     return qml.expval(qml.PauliZ(0))
Пример #12
0
 def qf_ok(x):
     qml.Rot(0.3, x, -0.2, wires=[0])
     return qml.expval(qml.PauliZ(0))