def circuit(params, **kwargs): # for w in range(NODES): # qml.Hadamard(wires=w) # print(params[0][1]) # for i in range(N_LAYERS): qml.layer(qaoa_layer, 10, params[0], params[1]) return qml.probs(wires=range(NODES))
def circuit(params, **kwargs): #for w in range(NODES): # qml.Hadamard(wires=w) qml.layer(qaoa_layer, N_LAYERS, params[0, :], params[1, :]) return qml.probs(wires=[0, 1, 2, 3, 4, 5])
def qaoa_circuit(params, wires, layers): cost_params, mixer_params = np.split(params, 2) cost_h = qml.qaoa.bit_driver(wires, b=1) mixer_h = qml.qaoa.x_mixer(wires) def qaoa_layer(gamma, alpha): qml.qaoa.cost_layer(gamma, cost_h) qml.qaoa.mixer_layer(alpha, mixer_h) qml.layer(qaoa_layer, layers, cost_params, mixer_params)
def ansatz(beta, **kwargs): layers = len(beta) for w in dev.wires: qml.Hadamard(wires=w) qml.layer(falqon_layer, layers, beta, cost_h=cost_h, driver_h=driver_h, delta_t=delta_t)
def test_depth_error(self): """Tests that the correct error is thrown when depth is not an integer""" depth = 1.5 def unitary(wires): qml.PauliX(wires=wires) with pytest.raises(ValueError, match=r"'depth' must be of type int"): layer(unitary, depth, wires=[0])
def test_layer(self, unitary, depth, arguments, keywords, gates): """Tests that the layering function is yielding the correct sequence of gates""" with qml.tape.OperationRecorder() as rec: layer(unitary, depth, *arguments, **keywords) for i, gate in enumerate(rec.operations): prep = [gate.name, gate.parameters, gate.wires] target = [gates[i].name, gates[i].parameters, gates[i].wires] assert prep == target
def test_args_length(self): """Tests that the correct error is thrown when the length of an argument is incorrect""" params = [1, 1] def unitary(param, wire): qml.RX(param, wires=wire) with pytest.raises( ValueError, match= r"Each positional argument must have length matching 'depth'; expected 3", ): layer(unitary, 3, params, wires=[0])
def test_layer_tf(self): """Tests that the layering function accepts Tensorflow variables.""" tf = pytest.importorskip("tensorflow") def unitary(param): qml.RX(param, wires=0) x = tf.Variable([0.1, 0.2, 0.3]) with qml.tape.OperationRecorder() as rec: layer(unitary, 3, x) assert len(rec.operations) == 3 for ii, op in enumerate(rec.operations): assert qml.math.allclose(op.parameters[0], x[ii]) assert isinstance(op, qml.RX)
def circuit(params_, **kwargs): qml.layer(qaoa_layer, N_LAYERS, params_[0], params_[1])
def circuit(params, **kwargs): qml.layer(qaoa_layer, 10, params[0], params[1])
def circuit(params, **kwargs): for w in wires: qml.Hadamard(wires=w) qml.layer(qaoa_layer, 2, params[0], params[1])
def qaoa_circuit(params, **kwargs): for w in dev.wires: qml.Hadamard(wires=w) qml.layer(qaoa_layer, depth, params[0], params[1])
def circuit(params, **kwargs): for i in range(n_wires): # Prepare an equal superposition over all qubits qml.Hadamard(wires=i) qml.layer(qaoa_layer, n_layers, params[0], params[1])
def circuit(params, **kwargs): #for i in range(10): qml.layer(qaoa_layer, depth, params[0], params[1])
def circuit(params, **kwargs): qml.layer(circ, 3, params) return [qml.expval(qml.PauliZ(i)) for i in range(n)]
def circuit(params): for w in range(n_wires): qml.Hadamard(wires=w) qml.layer(qaoa_layer, n_layers, params[0], params[1]) return [qml.sample(qml.PauliZ(i)) for i in range(n_wires)]
def circuit(params, **kwargs): #for w in wires: # qml.Hadamard(wires=w) qml.layer(qaoa_layer, N_LAYERS, params[0], params[1])
def circuit(params): qml.layer(qaoa_layer, N_LAYERS, params[0], params[1]) return qml.probs(wires=range(NODES))
def circuit(params, **kwargs): for w in range(NODES): qml.Hadamard(wires=w) qml.layer(qaoa_layer, N_LAYERS, params[0], params[1])