def circuit(p): qml.RX(3 * p[0], wires=0) qml.RY(p[1], wires=0) qml.RX(p[2] / 2, wires=0) return qml.expval(qml.PauliZ(0))
def circuit_template(weights): qml.BasicEntanglerLayers(weights, range(3)) return qml.expval(qml.PauliZ(0))
def circuit(): qml.BasicEntanglerLayers(weights, wires=range(3)) return qml.expval(qml.Identity(0))
def circuit(): qml.Hadamard(wires=0) qml.Hadamard(wires=1) return qml.expval(qml.PauliY(0)), qml.expval(qml.PauliY(1))
def circuit(p, *, aux=0): """A very simple, lightweight mutable quantum circuit.""" qml.RX(p[aux][2], wires=[0]) return qml.expval(qml.PauliZ(0))
def circuit(x=None): qml.AmplitudeEmbedding(x, list(range(num_qubits)), pad_with=0.0, normalize=True) return qml.expval(qml.PauliZ(0))
def circuit(): qml.AmplitudeEmbedding(features, wires=range(3)) return qml.expval(qml.Identity(0))
def circuit(weights): qml.templates.StronglyEntanglingLayers(weights, wires=[0, 1]) return qml.expval(qml.PauliZ(0))
def circuit(param): qml.RY(param, wires=0).inv() return qml.expval(qml.PauliX(0))
def circuit(x, weights, w): """In this example, a mixture of scalar arguments, array arguments, and keyword arguments are used.""" qml.QubitStateVector(state, wires=w) operation(x, weights[0], weights[1], wires=w) return qml.expval(qml.PauliX(w))
def circuit(x, w=None): qml.RZ(x, wires=w) return qml.expval(qml.PauliX(w))
def circuit(a, b): qml.RX(a, wires=0) qml.CRX(b, wires=[0, 1]) return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
def circuit(a): qml.RY(a, wires=0) return qml.expval(qml.PauliZ(0))
def circuit(x): qml.RX(x[1], wires=0) qml.Rot(x[0], x[1], x[2], wires=0) return qml.expval(qml.PauliZ(0))
def circuit(x, y, z): """Reference QNode""" qml.BasisState(np.array([1]), wires=0) qml.Hadamard(wires=0) qml.Rot(x, y, z, wires=0) return qml.expval(qml.PauliZ(0))
def circuit(x): qml.RX(x, wires=0) return qml.expval(qml.PauliY(0))
def circuit(x=None): qml.AmplitudeEmbedding(features=x, wires=range(n_qubits)) return qml.expval(qml.PauliZ(0))
def circuit(): qml.Hadamard(wires=0) qml.RZ(np.pi / 4, wires=0) return qml.expval(qml.PauliZ(0))
def circuit(x=None): qml.AmplitudeEmbedding(features=x, wires=range(n_qubits), pad_with=pad, normalize=False) return [qml.expval(qml.PauliZ(i)) for i in range(n_qubits)]
def test_apply(self, gate, apply_unitary, shots, qvm, compiler): """Test the application of gates""" dev = plf.QVMDevice(device="3q-qvm", shots=shots) try: # get the equivalent pennylane operation class op = getattr(qml.ops, gate) except AttributeError: # get the equivalent pennylane-forest operation class op = getattr(plf, gate) # the list of wires to apply the operation to w = list(range(op.num_wires)) obs = qml.expval(qml.PauliZ(0)) if op.par_domain == "A": # the parameter is an array if gate == "QubitUnitary": p = np.array(U) w = [0] state = apply_unitary(U, 3) elif gate == "BasisState": p = np.array([1, 1, 1]) state = np.array([0, 0, 0, 0, 0, 0, 0, 1]) w = list(range(dev.num_wires)) circuit_graph = CircuitGraph([op(p, wires=w)] + [obs], {}, dev.wires) else: p = [0.432_423, 2, 0.324][:op.num_params] fn = test_operation_map[gate] if callable(fn): # if the default.qubit is an operation accepting parameters, # initialise it using the parameters generated above. O = fn(*p) else: # otherwise, the operation is simply an array. O = fn # calculate the expected output state = apply_unitary(O, 3) # Creating the circuit graph using a parametrized operation if p: circuit_graph = CircuitGraph([op(*p, wires=w)] + [obs], {}, dev.wires) # Creating the circuit graph using an operation that take no parameters else: circuit_graph = CircuitGraph([op(wires=w)] + [obs], {}, dev.wires) dev.apply(circuit_graph.operations, rotations=circuit_graph.diagonalizing_gates) dev._samples = dev.generate_samples() res = dev.expval(obs) expected = np.vdot(state, np.kron(np.kron(Z, I), I) @ state) # verify the device is now in the expected state # Note we have increased the tolerance here, since we are only # performing 1024 shots. self.assertAllAlmostEqual(res, expected, delta=3 / np.sqrt(shots))
def circuit2(): qml.AmplitudeEmbedding(features, wires=["z", "a", "k"]) return qml.expval(qml.Identity("z"))
def circuit(): """Reference QNode""" qml.Hadamard(wires=0) qml.CNOT(wires=[0, 1]) qml.QubitUnitary(U2, wires=[0, 1]) return qml.expval(qml.PauliZ(0))
def circuit_Y(var): ansatz(var) return qml.expval(qml.PauliY(1))
def circuit(): qml.RY(np.pi / 2, wires=[0]) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0) @ qml.Identity(1))
def circuit2(): qml.BasicEntanglerLayers(weights, wires=["z", "a", "k"]) return qml.expval(qml.Identity("z"))
def circuit(): qml.Hadamard(0) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
def circuit(weights): qml.BasicEntanglerLayers(weights, wires=range(n_wires)) return [qml.expval(qml.PauliZ(i)) for i in range(n_wires)]
def circuit(): qml.RX(0.5, wires=wires[0 % n_wires]) qml.RY(2.0, wires=wires[1 % n_wires]) if n_wires > 1: qml.CNOT(wires=[wires[0], wires[1]]) return [qml.expval(qml.PauliZ(wires=w)) for w in wires]
def circuit_X(): ansatz() return qml.expval(qml.PauliX(1))
def circuit_from_architecture(params): for d, component in enumerate(architecture): string_to_layer_mapping[component](list(range(nqubits)), params[:, d]) return qml.expval(qml.PauliZ(0)), qml.expval( qml.PauliZ(1)), qml.expval(qml.PauliZ(2))