I am trying to parameterize a circuit using a single variable θ in the code below but the output is: Number of parameters in the circuit: 4
.
Can someone please help me create a single shared parameter for multiple gates within a circuit directly?
using Yao
using YaoPlots
# Define the number of qubits
n = 5
# Define a single parameter for all Rz gates
θ = π/4 # replace this with your desired angle
# Create a chain block to hold our circuit
circuit = chain(n)
# Apply controlled Rz gates with the shared parameter gate
for i in 1:n-1
push!(circuit, control(i, i+1 => Rz(θ)))
end
# Check the number of parameters in the circuit
println("Number of parameters in the circuit: ", length(parameters(circuit)))
plot(circuit)