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): """Test quantum function""" qml.RX(x, wires=0) return qml.expval(qml.Identity(0))
def circuit(x): """Test quantum function""" qml.Displacement(x, 0, wires=0) return qml.expval(qml.Identity(0))