code
stringlengths
3
6.57k
torch.random.manual_seed(123)
np.random.choice(ntest, 10)
print(test.iloc[ind])
print(test["y"].values[ind])
print(ypred)
name2tensor(name)
rnn.init_hidden()
torch.no_grad()
range(input.shape[0])
rnn(input[s], hidden)
output.item()
print(f"namae: {name}, P(female)
pytest.mark.parametrize("d", pldevices)
test_load_device(self, d, backend)
qml.device(d[0], wires=2, backend=backend, shots=1024)
test_incorrect_backend(self)
pytest.raises(ValueError, match="Backend 'none' does not exist")
qml.device("qiskit.aer", wires=2, backend="none")
test_incorrect_backend_wires(self)
pytest.raises(ValueError, match=r"Backend 'statevector\_simulator' supports maximum")
qml.device("qiskit.aer", wires=100, backend="statevector_simulator")
test_args(self)
pytest.raises(TypeError, match="missing 1 required positional argument")
qml.device("qiskit.aer")
pytest.raises(qml.DeviceError, match="specified number of shots needs to be at least 1")
qml.device("qiskit.aer", backend="qasm_simulator", wires=1, shots=0)
pytest.mark.parametrize("d", pldevices)
pytest.mark.parametrize("analytic", [True, False])
pytest.mark.parametrize("shots", [8192])
test_one_qubit_circuit(self, shots, analytic, d, backend, tol)
pytest.skip("Hardware simulators do not support analytic mode")
qml.device(d[0], wires=1, backend=backend, shots=shots, analytic=analytic)
qml.qnode(dev)
circuit(x, y, z)
qml.BasisState(np.array([1])
qml.Hadamard(wires=0)
qml.Rot(x, y, z, wires=0)
qml.expval(qml.PauliZ(0)
np.allclose(circuit(a, b, c)
np.cos(a)
np.sin(b)
pytest.mark.parametrize("d", pldevices)
pytest.mark.parametrize("analytic", [False])
pytest.mark.parametrize("shots", [8192])
test_one_qubit_circuit(self, shots, analytic, d, backend, tol)
qml.device(d[0], wires=1, backend=backend, shots=shots, analytic=analytic)
qml.qnode(dev)
circuit(x, y, z)
qml.BasisState(np.array([0])
qml.Rot(x, y, z, wires=0)
qml.expval(qml.PauliZ(0)
np.allclose(circuit(a, b, c)
test_gradient_for_tensor_product(self)
ansatz(weights)
weights.reshape(depth, n_qubits)
qml.RX(weights[0][0], wires=[0])
qml.RZ(weights[0][1], wires=[0])
qml.RX(weights[1][0], wires=[0])
qml.RZ(weights[1][1], wires=[0])
qml.expval(qml.PauliZ(0)
qml.PauliZ(1)
np.random.random((depth, n_qubits)
flatten()
qml.QNode(ansatz, dev_qsk, diff_method="parameter-shift")
qml.grad(exp_sampled, argnum=0)
exp_sampled(weights)
grad_shift(weights)
pytest.mark.parametrize("d", pldevices)
test_compile_backend(self, d)
qml.device(d[0], wires=2, compile_backend="test value")
test_noise_model(self)
qml.device("qiskit.aer", wires=2, noise_model="test value")
test_invalid_noise_model(self)
pytest.raises(ValueError, match="does not support noisy simulations")
qml.device("qiskit.basicaer", wires=2, noise_model="test value")
test_overflow_kwargs(self)
qml.device('qiskit.aer', wires=2, k1="v1", k2="v2")
test_load_qiskit_circuit(self)
qiskit.circuit.Parameter('θ')
qiskit.QuantumCircuit(2)
qc.rx(theta, 0)
qml.load(qc, format='qiskit')
qml.device('default.qubit', wires=2)
np.array([0.53896774, 0.79503606, 0.27826503, 0.])
qml.qnode(dev)
loaded_quantum_circuit(angle)
my_template({theta: angle})
qml.expval(qml.PauliZ(0)
qml.qnode(dev)
quantum_circuit(angle)
qml.RX(angle, wires=[0])
qml.expval(qml.PauliZ(0)
np.allclose(loaded_quantum_circuit(x)
quantum_circuit(x)
test_load_from_qasm_string(self)
qml.device('default.qubit', wires=2)
qml.qnode(dev)
loaded_quantum_circuit()
qml.from_qasm(TestLoadIntegration.hadamard_qasm)
qml.expval(qml.PauliZ(0)