def test_circuit_parameters(self, n_wires, n_layers, shape_weights): """Tests the parameter values in the circuit.""" initial_layer = np.random.randn(n_wires) weights = np.random.randn(*shape_weights) op = qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires)) queue = op.expand().operations # test the device parameters for l in range(n_layers): # only select the rotation gates ops = [gate for gate in queue if isinstance(gate, qml.RY)] # check each initial_layer gate parameters for n in range(n_wires): res_param = ops[n].parameters[0] exp_param = initial_layer[n] assert res_param == exp_param # check layer gate parameters ops = ops[n_wires:] exp_params = weights.flatten() for o, exp_param in zip(ops, exp_params): res_param = o.parameters[0] assert res_param == exp_param
def test_expansion(self, n_wires, weight_shape, expected_names, expected_wires): """Checks the queue for the default settings.""" weights = np.random.random(size=weight_shape) initial_layer = np.random.randn(n_wires) op = qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires)) queue = op.expand().operations for i, gate in enumerate(queue): assert gate.name == expected_names[i] assert gate.wires.labels == tuple(expected_wires[i])
def mitigated_circuit(w1, w2): qml.SimplifiedTwoDesign(w1, w2, wires=range(2)) return qml.expval(qml.PauliZ(0))
def mitigated_qnode(w1, w2): qml.SimplifiedTwoDesign(w1, w2, wires=range(2)) qml.adjoint(qml.SimplifiedTwoDesign)(w1, w2, wires=range(2)) return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
def circuit(w1, w2): qml.SimplifiedTwoDesign(w1, w2, wires=range(2)) qml.adjoint(qml.SimplifiedTwoDesign)(w1, w2, wires=range(2)) return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
def ideal_circuit(w1, w2): qml.SimplifiedTwoDesign(w1, w2, wires=range(2)) return qml.expval(qml.PauliZ(0)), qml.expval(qml.Hadamard(1))
def circuit_template(initial_weights, weights): qml.SimplifiedTwoDesign(initial_weights, weights, range(3)) return qml.expval(qml.PauliZ(0))
def test_id(self): """Tests that the id attribute can be set.""" weights = np.random.random(size=(1, 2, 2)) initial_layer = np.random.randn(3) template = qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(3), id="a") assert template.id == "a"
def circuit(initial_layer, weights): qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(2)) return qml.expval(qml.PauliZ(0))
def circuit2(): qml.SimplifiedTwoDesign(initial_layer, weights, wires=["z", "a", "k"]) return qml.expval(qml.Identity("z"))
def circuit(): qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(3)) return qml.expval(qml.Identity(0))
def circuit(initial_layer, weights): qml.SimplifiedTwoDesign( initial_layer_weights=initial_layer, weights=weights, wires=range(n_wires) ) return [qml.expval(qml.PauliZ(wires=i)) for i in range(n_wires)]