Parameters¶
Overview¶
QuantumRingsLib supports parameterized quantum circuits (PQCs). In a parameterized circuit, gate arguments can be defined using symbols and later assigned concrete values before execution.
This page shows:
how to create parameters (
ParameterandParameterVector)how to use them in a
QuantumCircuithow to assign values using
QuantumCircuit.assign_parameters(...)
For the end-to-end workflow (provider → backend → circuit → run), see Circuits.
Parameter objects¶
Named parameters¶
Use Parameter(name) to create a named symbolic parameter.
from QuantumRingsLib import Parameter
theta = Parameter("theta")
Parameter vectors¶
Use ParameterVector(name, length) to create a vector of named parameters.
Access individual parameters using subscripts (myparamvec[i]).
from QuantumRingsLib import ParameterVector
myparamvec = ParameterVector("test", 6)
# Example: test[0], test[1], ... test[5]
p0 = myparamvec[0]
Using parameters in a circuit¶
Parameters can be used as arguments to parameterized gates.
import math
from QuantumRingsLib import QuantumRegister, ClassicalRegister, QuantumCircuit
from QuantumRingsLib import Parameter, ParameterVector
q = QuantumRegister(5, "q")
c = ClassicalRegister(5, "c")
qc = QuantumCircuit(q, c)
myparamvec = ParameterVector("test", 6)
theta = Parameter("theta")
phi = Parameter("phi")
qc.h(q[0])
qc.mcp(theta, [q[0], q[1], q[3]], q[2])
qc.rx(phi, 3)
qc.rz(myparamvec[5], 0)
qc.u(myparamvec[0], myparamvec[1], myparamvec[2], 1)
Assigning values¶
Use qc.assign_parameters(dict_parameters, inplace=...) to replace symbolic parameters
with numeric values.
Quantum Rings documentation notes:
all required parameter values must be provided together in a single dictionary
if
inplaceisTrue, the existing circuit is updatedif
inplaceisFalse, a circuit with applied parameters is returned
Example:
import math
values = {
"test[0]": math.pi,
"test[1]": math.pi / 2,
"test[2]": math.pi / 3,
"test[5]": math.pi / 7,
"theta": math.pi / 8,
"phi": math.pi / 9,
}
qc.assign_parameters(values, inplace=True)
After assignment, the circuit can be executed using the same workflow as any other circuit. See Circuits.
Notes¶
The
QuantumCircuit.assign_parameters(...)API also includesflat_inputandstrictparameters in its signature; Quantum Rings documentation describes these as unused.QuantumCircuit.num_parametersexists but is documented as “currently not used”.
See also¶
Return to Quantum Rings SDK Documentation.