Some questions about qml.StronglyEntanglingLayers

How can I apply a noise channel to each quantum gate in the qml.StronglyEntanglingLayers template?

Hi @sun ,

Since this template only has two types of gates, Rot gates and CNOT gates, you could easily create a noise function for each and then join them in a noise model that you can add to a circuit. I show a code example below. Note however that under my implementation below, if you had additional occurrences of these gates then they would also get noise added to them.

There are a ton of customizations that you can do to your noise models so I would recommend that you check out the noise module in the documentation, as well as the demo on how to use noise models. My code below has been largely based on this demo.

import pennylane as qml
import numpy as np
from matplotlib import pyplot as plt

# Define the error you want to add
depol_error = qml.noise.partial_wires(qml.DepolarizingChannel, 0.01)

# Define the operations you want to add noise to
op1 = qml.Rot('phi','theta','omega','wire') 
op2 = qml.CNOT(['wire_0','wire_1']) 

# Create conditionals for the operations you want to add noise to
fcond1, noise1 = qml.noise.op_eq(op1), depol_error
fcond2, noise2 = qml.noise.op_eq(op2), depol_error

# Create a noise model that joins all your conditionals and noises
noise_model = qml.NoiseModel(
    {fcond1: noise1, fcond2: noise2}
)
print(noise_model)

# Create your QNode without noise
dev = qml.device("default.mixed", wires=3)
init_state = np.random.RandomState(42).rand(2 ** len(dev.wires))
init_state /= np.linalg.norm(init_state)

def circuit(parameters):
    # State preparation
    qml.StatePrep(init_state, wires=[0, 1, 2])
    # SEL
    qml.StronglyEntanglingLayers(weights=parameters, wires=range(4))
    return qml.state()

shape = qml.StronglyEntanglingLayers.shape(n_layers=2, n_wires=4)
weights = np.random.random(size=shape)
ideal_circuit = qml.QNode(circuit, dev)

# Draw your circuit
qml.drawer.use_style("pennylane")
qml.draw_mpl(ideal_circuit)(weights)
plt.show()

# Create a noisy circuit by adding your noise model to your ideal circuit
noisy_circuit = qml.add_noise(ideal_circuit, noise_model)
qml.draw_mpl(noisy_circuit)(weights)
plt.show()

Here you see where those errors have been added.

I hope this helps!