def cost(x, device): with QuantumTape() as tape: qml.Hadamard(wires=[0]) qml.CNOT(wires=[0, 1]) sample(qml.PauliZ(0)) sample(qml.PauliX(1)) return tape.execute(device)
def cost(x, device): with AutogradInterface.apply(QuantumTape()) as tape: qml.Hadamard(wires=[0]) qml.CNOT(wires=[0, 1]) sample(qml.PauliZ(0)) sample(qml.PauliX(1)) return tape.execute(device)
def test_sampling(self): """Test that the tape correctly marks itself as returning samples""" with QuantumTape() as tape: expval(qml.PauliZ(wires=1)) assert not tape.is_sampled with QuantumTape() as tape: sample(qml.PauliZ(wires=0)) assert tape.is_sampled
def test_sampling(self): """Test sampling works as expected""" dev = qml.device("default.qubit", wires=2, shots=10) with TorchInterface.apply(QuantumTape()) as tape: qml.Hadamard(wires=[0]) qml.CNOT(wires=[0, 1]) sample(qml.PauliZ(0)) sample(qml.PauliX(1)) res = tape.execute(dev) assert res.shape == (2, 10) assert isinstance(res, torch.Tensor)
def test_sampling(self): """Test sampling works as expected""" dev = qml.device("default.qubit.tf", wires=2, shots=10) with tf.GradientTape() as tape: with QuantumTape() as qtape: qml.Hadamard(wires=[0]) qml.CNOT(wires=[0, 1]) sample(qml.PauliZ(0)) sample(qml.PauliX(1)) res = qtape.execute(dev) assert res.shape == (2, 10) assert isinstance(res, tf.Tensor)
def circuit(): qml.Hadamard(wires=[0]) qml.CNOT(wires=[0, 1]) return [sample(qml.PauliZ(0)), sample(qml.PauliX(1))]