def circuit2_MPS(weights, wires): SELWeights1 = np.array([[ [weights[0][0], weights[0][1], weights[0][2]], [weights[0][0], weights[0][1], weights[0][2]], ]]) SELWeights2 = np.array([[ [weights[1][0], weights[1][1], weights[1][2]], [weights[1][0], weights[1][1], weights[1][2]], ]]) qml.StronglyEntanglingLayers(SELWeights1, wires=wires[0:2]) qml.StronglyEntanglingLayers(SELWeights2, wires=wires[1:3])
def circuit3_TTN(weights, wires): SELWeights1 = np.array([[ [weights[0][0], weights[0][1], weights[0][2]], [weights[0][0], weights[0][1], weights[0][2]], ]]) SELWeights2 = np.array([[ [weights[1][0], weights[1][1], weights[1][2]], [weights[1][0], weights[1][1], weights[1][2]], ]]) SELWeights3 = np.array([[ [weights[2][0], weights[2][1], weights[2][2]], [weights[2][0], weights[2][1], weights[2][2]], ]]) qml.StronglyEntanglingLayers(SELWeights1, wires=wires[0:2]) qml.StronglyEntanglingLayers(SELWeights2, wires=wires[2:4]) qml.StronglyEntanglingLayers(SELWeights3, wires=[wires[1], wires[3]])
def test_uses_correct_imprimitive(self, n_layers, n_wires): """Test that correct number of entanglers are used in the circuit.""" weights = np.random.randn(n_layers, n_wires, 3) op = qml.StronglyEntanglingLayers(weights=weights, wires=range(n_wires), imprimitive=qml.CZ) ops = op.expand().operations gate_names = [gate.name for gate in ops] assert gate_names.count("CZ") == n_wires * n_layers
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) op = qml.StronglyEntanglingLayers(weights, wires=range(n_wires)) tape = op.expand() for i, gate in enumerate(tape.operations): assert gate.name == expected_names[i] assert gate.wires.labels == tuple(expected_wires[i])
def test_custom_range_sequence(self, n_layers, n_wires, ranges): """Test that correct sequence of custom ranges are used in the circuit.""" weights = np.random.randn(n_layers, n_wires, 3) op = qml.StronglyEntanglingLayers(weights=weights, wires=range(n_wires), ranges=ranges) ops = op.expand().operations gate_wires = [gate.wires.labels for gate in ops] range_idx = 0 for idx, i in enumerate(gate_wires): if idx % (n_wires * 2) // n_wires == 1: expected_wire = ( idx % n_wires, (ranges[range_idx % len(ranges)] + idx % n_wires) % n_wires, ) assert i == expected_wire if idx % n_wires == n_wires - 1: range_idx += 1
def circuit2_block(weights, wires): SELWeights = np.array([[[weights[0], weights[1], weights[2]], [weights[0], weights[1], weights[2]]]]) qml.StronglyEntanglingLayers(SELWeights, wires)
def circuit(): """Prepares the equal superposition state and then applies StronglyEntanglingLayers and concludes with a simple PauliZ measurement""" qml.QubitStateVector(vec, wires=range(wires)) qml.StronglyEntanglingLayers(w, wires=range(wires)) return qml.expval(qml.PauliZ(0))
def circuit2(): qml.StronglyEntanglingLayers(weights, wires=["z", "a", "k"]) return qml.expval(qml.Identity("z"))
def circuit(): qml.StronglyEntanglingLayers(weights, wires=range(3)) return qml.expval(qml.Identity(0))
def circuit_template(weights): qml.StronglyEntanglingLayers(weights, range(3)) return qml.expval(qml.PauliZ(0))
def test_id(self): """Tests that the id attribute can be set.""" template = qml.StronglyEntanglingLayers(np.array([[[1, 2, 3]]]), wires=[0], id="a") assert template.id == "a"
def circuit(weights, ranges=None): qml.StronglyEntanglingLayers(weights, wires=range(2), ranges=ranges) return qml.expval(qml.PauliZ(0))