How to create a single shared parameter for multiple gates within a circuit directly using Yao.jl?

nethaji8
Fri, 06 Oct 2023 07:01:56 +0000
Performance

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)

4 posts - 3 participants