def test_uses_correct_weights(self, n_subsystems): """Test that correct weights are used in the circuit.""" np.random.seed(12) n_layers = 2 num_wires = n_subsystems weights = np.random.randn(n_layers, num_wires, 3) with pennylane._queuing.OperationRecorder() as rec: StronglyEntanglingLayers(weights, wires=range(num_wires)) # Test that gates appear in the right order exp_gates = [qml.Rot] * num_wires + [qml.CNOT] * num_wires exp_gates *= n_layers res_gates = rec.queue for op1, op2 in zip(res_gates, exp_gates): assert isinstance(op1, op2) # test the device parameters for l in range(n_layers): layer_ops = rec.queue[2 * l * num_wires:2 * (l + 1) * num_wires] # check each rotation gate parameter for n in range(num_wires): res_params = layer_ops[n].parameters exp_params = weights[l, n, :] assert sum([r == e for r, e in zip(res_params, exp_params)])
def circuit(weights, *, features=None): """Mutable quantum circuit.""" n_wires = len(features) AngleEmbedding(features, wires=range(n_wires)) StronglyEntanglingLayers(weights, wires=range(n_wires)) return qml.expval(qml.PauliZ(0))
def circuit(params0, state=None, obs=None): QubitStateVector(state, wires=list(range(self.req_qub_out))) StronglyEntanglingLayers(params0, list(range(self.req_qub_in)), ranges=[1]) return qml.expval.Hermitian(obs, wires=list(range(self.req_qub_out)))
def test_single_qubit(self, n_layers): weights = np.zeros((n_layers, 1, 3)) with pennylane._queuing.OperationRecorder() as rec: StronglyEntanglingLayers(weights, wires=range(1)) assert len(rec.queue) == n_layers assert all([isinstance(q, qml.Rot) for q in rec.queue]) assert all([q._wires[0] == 0 for q in rec.queue])
def test_strong_ent_layers_uses_correct_number_of_imprimitives(self, n_layers, n_subsystems): """Test that StronglyEntanglingLayers uses the correct number of imprimitives.""" imprimitive = CZ weights = np.random.randn(n_layers, n_subsystems, 3) with qml.utils.OperationRecorder() as rec: StronglyEntanglingLayers(weights=weights, wires=range(n_subsystems), imprimitive=imprimitive) types = [type(q) for q in rec.queue] assert types.count(imprimitive) == n_subsystems*n_layers
def test_uses_correct_number_of_imprimitives(self, n_layers, n_subsystems): """Test that correct number of imprimitives are used in the circuit.""" imprimitive = CZ weights = np.random.randn(n_layers, n_subsystems, 3) with pennylane._queuing.OperationRecorder() as rec: StronglyEntanglingLayers(weights=weights, wires=range(n_subsystems), imprimitive=imprimitive) types = [type(q) for q in rec.queue] assert types.count(imprimitive) == n_subsystems * n_layers
def circuit(weights): StronglyEntanglingLayers(weights, wires=range(2)) return qml.expval(qml.PauliZ(0))
def circuit(params, n=None): StronglyEntanglingLayers(weights=params, wires=[0, 1]) idx = np.random.choice(np.arange(5), size=n, replace=False) A = np.sum(terms[idx], axis=0) return expval(qml.Hermitian(A, wires=[0, 1]))
def circuit(weights, x=None): qml.BasisState(x, wires=range(num_wires)) StronglyEntanglingLayers(weights, wires=range(num_wires)) return qml.expval(qml.PauliZ(0))
def circuit(params): StronglyEntanglingLayers(weights=params, wires=[0, 1]) return expval(qml.Hermitian(H, wires=[0, 1]))
def circuit(weights, x=None): AngleEmbedding(x, [0, 1]) StronglyEntanglingLayers(weights, wires=[0, 1]) return qml.expval(qml.PauliZ(0))
def circuit(weights): StronglyEntanglingLayers(weights=weights, wires=range(n_wires), ranges=["a", "a"]) return qml.expval(qml.PauliZ(0))
def circuit(inputs, weights): for k in range(0, 15, 3): qml.templates.AngleEmbedding(inputs[k:k + 3], wires=range(NUM_WIRES)) StronglyEntanglingLayers(init_weights, wires=[k for k in range(NUM_WIRES)]) return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval( qml.PauliZ(2))
def circuit(weights): StronglyEntanglingLayers(weights=weights, wires=range(n_subsystems), imprimitive=imprimitive) return qml.expval(qml.PauliZ(0))
def circuit(weights): StronglyEntanglingLayers(*weights, wires=range(n_subsystems)) return qml.expval.Identity(0)
def circuit(weights, x=None): AngleEmbedding(x, wires=range(n_qubits)) StronglyEntanglingLayers(weights, wires=range(n_qubits)) return qml.expval(qml.PauliZ(0))
def circuit(params, obs): StronglyEntanglingLayers(params, list(range(self.req_qub_in)), ranges=[1]) return qml.expval.Hermitian(obs, wires=list(range(self.req_qub_out)))