def test_circuit_parameters(self, n_wires, n_layers, shape_weights): """Tests the parameter values in the circuit.""" np.random.seed(42) initial_layer = np.random.randn(n_wires) weights = np.random.randn(*shape_weights) with pennylane._queuing.OperationRecorder() as rec: SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires)) # test the device parameters for l in range(n_layers): # only select the rotation gates ops = [gate for gate in rec.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_circuit_queue(self, n_wires, n_layers, shape_weights): """Tests the gate types in the circuit.""" np.random.seed(42) initial_layer = np.random.randn(n_wires) weights = np.random.randn(*shape_weights) with pennylane._queuing.OperationRecorder() as rec: SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires)) # Test that gates appear in the right order exp_gates = [qml.CZ, qml.RY, qml.RY] * ((n_wires // 2) + (n_wires - 1) // 2) exp_gates *= n_layers exp_gates = [qml.RY] * n_wires + exp_gates res_gates = rec.queue for op1, op2 in zip(res_gates, exp_gates): assert isinstance(op1, op2)
def circuit(initial_layer, weights): SimplifiedTwoDesign(initial_layer, weights, wires=range(2)) return qml.expval(qml.PauliZ(0))
def circuit(initial_layer, weights): 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)]