Parametric programs
Qadence base Parameter
type is a subtype of sympy.Symbol
. There are three kinds of parameter subtypes used:
Fixed Parameter : A constant with a fixed, non-trainable value (e.g. \(\dfrac{\pi}{2}\) ).
Variational Parameter : A trainable parameter which can be optimized.
Feature Parameter : A non-trainable parameter which can be used to encode classical data into a quantum state.
Fixed Parameters
To pass a fixed parameter to a gate (or any parametrizable block), one can simply use either Python numeric types or wrapped in
a torch.Tensor
.
from qadence import RX , run , PI
# Let's use a torch type.
block = RX ( 0 , PI )
wf = run ( block )
# Let's pass a simple float.
block = RX ( 0 , 1. )
wf = run ( block )
w f = tens or( [[ 6.1232e-17+0. j , 0.0000e+00-1. j ]] )
w f = tens or( [[ 0.8776+0.0000 j , 0.0000-0.4794 j ]] )
Variational Parameters
To parametrize a block by an angle theta
, either a Python string
or an instance of VariationalParameter
can be passed instead of a numeric type to the gate constructor:
from qadence import RX , run , VariationalParameter
block = RX ( 0 , "theta" )
# This is equivalent to:
block = RX ( 0 , VariationalParameter ( "theta" ))
wf = run ( block )
w f = tens or( [[ 0.9882+0.0000 j , 0.0000-0.1531 j ]] )
In the first case in the above example, theta
is automatically inferred as a VariationalParameter
(i.e. trainable). It is initialized to a random value for the purposes of execution. In the context of a QuantumModel
, there is no need to pass a value for theta
to the run
method since it is stored within the underlying model parameter dictionary.
Feature Parameters
FeatureParameter
types (i.e. inputs), always need to be provided with a value or a batch of values as a dictionary:
from torch import tensor
from qadence import RX , run , FeatureParameter
block = RX ( 0 , FeatureParameter ( "phi" ))
wf = run ( block , values = { "phi" : tensor ([ 1. , 2. ])})
w f = tens or( [[ 0.8776+0.0000 j , 0.0000-0.4794 j ],
[ 0.5403+0.0000 j , 0.0000-0.8415 j ]] )
Now, run
returns a batch of states, one for every provided angle which coincides with the value of the particular FeatureParameter
.
Multiparameter Expressions
However, an angle can itself be an expression Parameter
types of any kind.
As such, any sympy expression expr: sympy.Basic
consisting of a combination of free symbols (i.e. sympy
types) and Qadence Parameter
can
be passed to a block, including trigonometric functions.
from torch import tensor
from qadence import RX , Parameter , run , FeatureParameter
from sympy import sin
theta , phi = Parameter ( "theta" ), FeatureParameter ( "phi" )
block = RX ( 0 , sin ( theta + phi ))
# Remember, to run the block, only FeatureParameter values have to be provided:
values = { "phi" : tensor ([ 1.0 , 2.0 ])}
wf = run ( block , values = values )
w f = tens or( [[ 0.8785+0.0000 j , 0.0000-0.4778 j ],
[ 0.9538+0.0000 j , 0.0000-0.3006 j ]] )
Parameters Redundancy
Parameters are uniquely defined by their name and redundancy is allowed in composite blocks to
assign the same value to different blocks.
import torch
from qadence import RX , RY , run , chain , kron
block = chain (
kron ( RX ( 0 , "phi" ), RY ( 1 , "theta" )),
kron ( RX ( 0 , "phi" ), RY ( 1 , "theta" )),
)
wf = run ( block ) # Same random initialization for all instances of phi and theta.
w f = tens or( [[ 0.5500+0.0000 j , 0.5257+0.0000 j , 0.0000-0.4691 j , 0.0000-0.4484 j ]] )
Parametrized Circuits
Now, let's have a look at the construction of a variational ansatz which composes FeatureParameter
and VariationalParameter
types:
import sympy
from qadence import RX , RY , RZ , CNOT , Z , run , chain , kron , FeatureParameter , VariationalParameter
phi = FeatureParameter ( "phi" )
theta = VariationalParameter ( "theta" )
block = chain (
kron (
RX ( 0 , phi / theta ),
RY ( 1 , theta * 2 ),
RZ ( 2 , sympy . cos ( phi )),
),
kron (
RX ( 0 , phi ),
RY ( 1 , theta ),
RZ ( 2 , phi ),
),
kron (
RX ( 0 , phi ),
RY ( 1 , theta ),
RZ ( 2 , phi ),
),
kron (
RX ( 0 , phi + theta ),
RY ( 1 , theta ** 2 ),
RZ ( 2 , sympy . cos ( phi )),
),
chain ( CNOT ( 0 , 1 ), CNOT ( 1 , 2 ))
)
block . tag = "Rotations"
obs = 2 * kron ( * map ( Z , range ( 3 )))
block = chain ( block , obs )
%3
cluster_7766e30eb7c94044bc0c2eb2033d7dd4
[* 2]
cluster_c1cab03caa174af99d3e0e0c4ca04371
Rotations
1b55bfce698145c680551c79dc317565
0
02ac6e2deb7a4aa89397c66dd5ff94e9
RX(phi/theta)
1b55bfce698145c680551c79dc317565--02ac6e2deb7a4aa89397c66dd5ff94e9
0dc61918f4e747088d31a2114e632135
1
0ec2cc881f4d4b2da5e550e4fa0d1adb
RX(phi)
02ac6e2deb7a4aa89397c66dd5ff94e9--0ec2cc881f4d4b2da5e550e4fa0d1adb
fdb42da5a14b43ba80b17b87c3a07535
RX(phi)
0ec2cc881f4d4b2da5e550e4fa0d1adb--fdb42da5a14b43ba80b17b87c3a07535
979e5eba5b2b4f179a5ea8f491e82650
RX(phi + theta)
fdb42da5a14b43ba80b17b87c3a07535--979e5eba5b2b4f179a5ea8f491e82650
0f2808d8b36945929defa92a7ee7d2cc
979e5eba5b2b4f179a5ea8f491e82650--0f2808d8b36945929defa92a7ee7d2cc
a57811606da24cf9a670a14838eab846
0f2808d8b36945929defa92a7ee7d2cc--a57811606da24cf9a670a14838eab846
52eb9e880193414fa9a6d6475b1d3b44
Z
a57811606da24cf9a670a14838eab846--52eb9e880193414fa9a6d6475b1d3b44
4b94ecb9858c4bb6ac163ba37ba3b758
52eb9e880193414fa9a6d6475b1d3b44--4b94ecb9858c4bb6ac163ba37ba3b758
479dce178b2f41b29b7416ab8004ab08
1187460ae73b48c4a793565478a6e789
RY(2*theta)
0dc61918f4e747088d31a2114e632135--1187460ae73b48c4a793565478a6e789
ec30d31ae9ab489f887c4d485a5f455d
2
893fad5854374d6aa4464b83ae991904
RY(theta)
1187460ae73b48c4a793565478a6e789--893fad5854374d6aa4464b83ae991904
e2dd7ed112d24015b17c146104f98611
RY(theta)
893fad5854374d6aa4464b83ae991904--e2dd7ed112d24015b17c146104f98611
7a883668ce52401cb6d2270625e86569
RY(theta**2)
e2dd7ed112d24015b17c146104f98611--7a883668ce52401cb6d2270625e86569
5e74b2134b0244d599673668408e5577
X
7a883668ce52401cb6d2270625e86569--5e74b2134b0244d599673668408e5577
5e74b2134b0244d599673668408e5577--0f2808d8b36945929defa92a7ee7d2cc
55ae1c4cafa646789a340c31bf9dacac
5e74b2134b0244d599673668408e5577--55ae1c4cafa646789a340c31bf9dacac
f4c1ee4864994e1b96a8cce4e81a5716
Z
55ae1c4cafa646789a340c31bf9dacac--f4c1ee4864994e1b96a8cce4e81a5716
f4c1ee4864994e1b96a8cce4e81a5716--479dce178b2f41b29b7416ab8004ab08
17086273f83e4ec28aef398a4ea830e1
f6305faf71a441418161774607a7b1b0
RZ(cos(phi))
ec30d31ae9ab489f887c4d485a5f455d--f6305faf71a441418161774607a7b1b0
a42985d0f0cb4d1d8fbd9aabb39040e7
RZ(phi)
f6305faf71a441418161774607a7b1b0--a42985d0f0cb4d1d8fbd9aabb39040e7
a92707afc0374ac4b816de36c22a36f9
RZ(phi)
a42985d0f0cb4d1d8fbd9aabb39040e7--a92707afc0374ac4b816de36c22a36f9
ffa28904589f4579aa5fe3f08584766c
RZ(cos(phi))
a92707afc0374ac4b816de36c22a36f9--ffa28904589f4579aa5fe3f08584766c
00a34d323e9c4c6fa6d5a0ec824cf606
ffa28904589f4579aa5fe3f08584766c--00a34d323e9c4c6fa6d5a0ec824cf606
5d3826b0488541af94425bf7378b1df9
X
00a34d323e9c4c6fa6d5a0ec824cf606--5d3826b0488541af94425bf7378b1df9
5d3826b0488541af94425bf7378b1df9--55ae1c4cafa646789a340c31bf9dacac
4c3987b3211642e0a396f79a5c048962
Z
5d3826b0488541af94425bf7378b1df9--4c3987b3211642e0a396f79a5c048962
4c3987b3211642e0a396f79a5c048962--17086273f83e4ec28aef398a4ea830e1
Please note the different colors for the parametrization with different types. The default palette assigns light blue for VariationalParameter
, light green for FeatureParameter
and shaded red for observables.
Parametrized QuantumModels
As a quick reminder: FeatureParameter
are used for data input and data encoding into a quantum state.
VariationalParameter
are trainable parameters in a variational ansatz. When used within a QuantumModel
, an abstract quantum circuit is made differentiable with respect to both variational and feature
parameters which are uniquely identified by their name.
from qadence import FeatureParameter , Parameter , VariationalParameter
# Feature parameters are non-trainable parameters.
# Their primary use is input data encoding.
fp = FeatureParameter ( "x" )
assert fp == Parameter ( "x" , trainable = False )
# Variational parameters are trainable parameters.
# Their primary use is for optimization.
vp = VariationalParameter ( "y" )
assert vp == Parameter ( "y" , trainable = True )
Let's construct a parametric quantum circuit.
from qadence import QuantumCircuit , RX , RY , chain , kron
theta = VariationalParameter ( "theta" )
phi = FeatureParameter ( "phi" )
block = chain (
kron ( RX ( 0 , theta ), RY ( 1 , theta )),
kron ( RX ( 0 , phi ), RY ( 1 , phi )),
)
circuit = QuantumCircuit ( 2 , block )
unique_params = circuit . unique_parameters
u n ique_params = [ t he ta , phi ]
In the circuit above, four parameters are defined but only two unique names. Therefore, there will be only one
variational parameter to be optimized.
The QuantumModel
class also provides convenience methods to manipulate parameters.
from qadence import QuantumModel , BackendName , DiffMode
model = QuantumModel ( circuit , backend = BackendName . PYQTORCH , diff_mode = DiffMode . AD )
num_vparams = model . num_vparams # get the number of variational parameters
vparams_values = model . vparams
nu m_vparams = 1
vparams_values = OrderedDic t ( [ (' t he ta ' , tens or( [ 0.2054 ] )) ] )
Only provide feature parameter values to the quantum model
In order to run
the variational circuit only feature parameter values have to be provided.
Variational parameters are stored in the model itself. If multiple feature parameters are present,
values must be provided in batches of same length.
import torch
values = { "phi" : torch . rand ( 3 )} # theta does not appear here
wf = model . run ( values )
w f = tens or( [[ 0.9677+0.0000 j , 0.1768+0.0000 j , 0.0000-0.1768 j , 0.0000-0.0323 j ],
[ 0.9856+0.0000 j , 0.1193+0.0000 j , 0.0000-0.1193 j , 0.0000-0.0144 j ],
[ 0.8356+0.0000 j , 0.3706+0.0000 j , 0.0000-0.3706 j , 0.0000-0.1644 j ]],
grad_ fn =<TBackward 0 >)
Standard constructors
The unique parameter identification is relevant when using built-in Qadence block
constructors in the qadence.constructors
module such as feature maps and hardware
efficient ansatze (HEA).
from qadence import QuantumCircuit , hea
n_qubits = 4
depth = 2
hea1 = hea ( n_qubits = n_qubits , depth = depth )
circuit = QuantumCircuit ( n_qubits , hea1 )
num_unique_parameters = circuit . num_unique_parameters
U n ique parame ters wi t h a si n gle HEA : 24
%3
7b809944850d494c9669aa021b3beeff
0
fc2b9db356e442a8a53b1568d6d3c6c4
RX(theta₀)
7b809944850d494c9669aa021b3beeff--fc2b9db356e442a8a53b1568d6d3c6c4
18c2037306624c1cad60dca225c7c66c
1
e7daa625b1054a8eb7852f4f704deb52
RY(theta₄)
fc2b9db356e442a8a53b1568d6d3c6c4--e7daa625b1054a8eb7852f4f704deb52
91a3ef37c7464628868d6f06a15e27a9
RX(theta₈)
e7daa625b1054a8eb7852f4f704deb52--91a3ef37c7464628868d6f06a15e27a9
97dd8f303e8d4481827282613bc9c5e8
91a3ef37c7464628868d6f06a15e27a9--97dd8f303e8d4481827282613bc9c5e8
a4da65b94b3049d78687b00c888605f2
97dd8f303e8d4481827282613bc9c5e8--a4da65b94b3049d78687b00c888605f2
cca4fccc8cd54a8d8d08dfd241fbbe58
RX(theta₁₂)
a4da65b94b3049d78687b00c888605f2--cca4fccc8cd54a8d8d08dfd241fbbe58
5565b2e182074ea985fcbcbde150dd25
RY(theta₁₆)
cca4fccc8cd54a8d8d08dfd241fbbe58--5565b2e182074ea985fcbcbde150dd25
c3acf86ca41c46a693b6a25393e67db9
RX(theta₂₀)
5565b2e182074ea985fcbcbde150dd25--c3acf86ca41c46a693b6a25393e67db9
ee1bab3997224b2995cf2b310dc721ab
c3acf86ca41c46a693b6a25393e67db9--ee1bab3997224b2995cf2b310dc721ab
cc632271682b4c73b35a2c4d5a6404b5
ee1bab3997224b2995cf2b310dc721ab--cc632271682b4c73b35a2c4d5a6404b5
9c5c9ed77cae46b88d6411429dd2e1ff
cc632271682b4c73b35a2c4d5a6404b5--9c5c9ed77cae46b88d6411429dd2e1ff
3ff979de819a480cbc351c45a5b8d9cc
4002cf4c369c48059ac94f4c620e3f58
RX(theta₁)
18c2037306624c1cad60dca225c7c66c--4002cf4c369c48059ac94f4c620e3f58
7cc47b1b5a67466b854f1160980c6d24
2
bc87048335554d9e84314d18e387677c
RY(theta₅)
4002cf4c369c48059ac94f4c620e3f58--bc87048335554d9e84314d18e387677c
2c710212cb144990bf790f99cabe0704
RX(theta₉)
bc87048335554d9e84314d18e387677c--2c710212cb144990bf790f99cabe0704
29d08d15ef8e43eeb243745c7c486afd
X
2c710212cb144990bf790f99cabe0704--29d08d15ef8e43eeb243745c7c486afd
29d08d15ef8e43eeb243745c7c486afd--97dd8f303e8d4481827282613bc9c5e8
fb4a7175b4f64d99b7e3bd77aa43ec9d
29d08d15ef8e43eeb243745c7c486afd--fb4a7175b4f64d99b7e3bd77aa43ec9d
9927d0917ff34d90ba0a23e1d9441570
RX(theta₁₃)
fb4a7175b4f64d99b7e3bd77aa43ec9d--9927d0917ff34d90ba0a23e1d9441570
fc2f116591ef42cf8e9733d88dfd52b0
RY(theta₁₇)
9927d0917ff34d90ba0a23e1d9441570--fc2f116591ef42cf8e9733d88dfd52b0
613fd059c08744cc9c010833e4a5cfd0
RX(theta₂₁)
fc2f116591ef42cf8e9733d88dfd52b0--613fd059c08744cc9c010833e4a5cfd0
f48f0e173f43480eb00f8a589ec9306f
X
613fd059c08744cc9c010833e4a5cfd0--f48f0e173f43480eb00f8a589ec9306f
f48f0e173f43480eb00f8a589ec9306f--ee1bab3997224b2995cf2b310dc721ab
3fda0e3b94004cb092fcddd9fe10d676
f48f0e173f43480eb00f8a589ec9306f--3fda0e3b94004cb092fcddd9fe10d676
3fda0e3b94004cb092fcddd9fe10d676--3ff979de819a480cbc351c45a5b8d9cc
68a55a2d7ab1416097b83fe24dfb4602
690e3af4eca348eb9cd2077fe33e19ba
RX(theta₂)
7cc47b1b5a67466b854f1160980c6d24--690e3af4eca348eb9cd2077fe33e19ba
c872aaead3564b87a228373129572600
3
066994e236de496bafac9d996b705cfa
RY(theta₆)
690e3af4eca348eb9cd2077fe33e19ba--066994e236de496bafac9d996b705cfa
9a6c67bd91db4005ab632a3fd52c0b21
RX(theta₁₀)
066994e236de496bafac9d996b705cfa--9a6c67bd91db4005ab632a3fd52c0b21
92d3caafb59f4004801fe08d7fe9f535
9a6c67bd91db4005ab632a3fd52c0b21--92d3caafb59f4004801fe08d7fe9f535
415270b2beb54898b4a210a069620649
X
92d3caafb59f4004801fe08d7fe9f535--415270b2beb54898b4a210a069620649
415270b2beb54898b4a210a069620649--fb4a7175b4f64d99b7e3bd77aa43ec9d
246eb9593d1f4e188440267e81d2c34a
RX(theta₁₄)
415270b2beb54898b4a210a069620649--246eb9593d1f4e188440267e81d2c34a
b325a657fc134bc6a19cae4ffcdf2a86
RY(theta₁₈)
246eb9593d1f4e188440267e81d2c34a--b325a657fc134bc6a19cae4ffcdf2a86
803de011d0054d9480890d096031ac64
RX(theta₂₂)
b325a657fc134bc6a19cae4ffcdf2a86--803de011d0054d9480890d096031ac64
d8ec017a6d904e79b4a9c00a9a3fa938
803de011d0054d9480890d096031ac64--d8ec017a6d904e79b4a9c00a9a3fa938
1fc4565a2084435a8da5fd226108f3b8
X
d8ec017a6d904e79b4a9c00a9a3fa938--1fc4565a2084435a8da5fd226108f3b8
1fc4565a2084435a8da5fd226108f3b8--3fda0e3b94004cb092fcddd9fe10d676
1fc4565a2084435a8da5fd226108f3b8--68a55a2d7ab1416097b83fe24dfb4602
0f8b9cbb2e804118b17b8df2ba16f9b1
94b69f9000b74e7fbfd2e65719077846
RX(theta₃)
c872aaead3564b87a228373129572600--94b69f9000b74e7fbfd2e65719077846
5ad4d6c7e27a4f89a1264a6fc4b1fed5
RY(theta₇)
94b69f9000b74e7fbfd2e65719077846--5ad4d6c7e27a4f89a1264a6fc4b1fed5
22558d3ba7bd4308afde5aeb9a227273
RX(theta₁₁)
5ad4d6c7e27a4f89a1264a6fc4b1fed5--22558d3ba7bd4308afde5aeb9a227273
fcad59013cf44e529fddb41ec7da58f4
X
22558d3ba7bd4308afde5aeb9a227273--fcad59013cf44e529fddb41ec7da58f4
fcad59013cf44e529fddb41ec7da58f4--92d3caafb59f4004801fe08d7fe9f535
580b61c9a3bc448985dad8fda6b5d64c
fcad59013cf44e529fddb41ec7da58f4--580b61c9a3bc448985dad8fda6b5d64c
266afb3c354a42a68e0e4cb268997642
RX(theta₁₅)
580b61c9a3bc448985dad8fda6b5d64c--266afb3c354a42a68e0e4cb268997642
b2f148c08e2049b086d2203d43f91a79
RY(theta₁₉)
266afb3c354a42a68e0e4cb268997642--b2f148c08e2049b086d2203d43f91a79
0fbc467213a4489c9bcc1cda2a5ab74e
RX(theta₂₃)
b2f148c08e2049b086d2203d43f91a79--0fbc467213a4489c9bcc1cda2a5ab74e
84605c3537f24d89af175ee1624987ff
X
0fbc467213a4489c9bcc1cda2a5ab74e--84605c3537f24d89af175ee1624987ff
84605c3537f24d89af175ee1624987ff--d8ec017a6d904e79b4a9c00a9a3fa938
3582ffb648064e7dbd5af9ac435e2297
84605c3537f24d89af175ee1624987ff--3582ffb648064e7dbd5af9ac435e2297
3582ffb648064e7dbd5af9ac435e2297--0f8b9cbb2e804118b17b8df2ba16f9b1
A new circuit can be created by adding another identical HEA. As expected, the number of unique parameters
is the same.
hea2 = hea ( n_qubits = n_qubits , depth = depth )
circuit = QuantumCircuit ( n_qubits , hea1 , hea2 )
num_unique_params_two_heas = circuit . num_unique_parameters
U n ique parame ters wi t h t wo s ta cked HEAs : 24
%3
cluster_dc0ad7728df643bba06cd5c4855ea819
HEA
cluster_be1a2b0603a142c6b4f1175912baf663
HEA
498907a923764baeb83776ac1891b290
0
bc1125bfe42d49f99157482d77cce4f5
RX(theta₀)
498907a923764baeb83776ac1891b290--bc1125bfe42d49f99157482d77cce4f5
4cddfa71f0ff41bfb68e950192d9f38e
1
6e3018d0ca6146cb8909f9b1f445d2b0
RY(theta₄)
bc1125bfe42d49f99157482d77cce4f5--6e3018d0ca6146cb8909f9b1f445d2b0
97ad8af2f110429e89f63ad8ff753d3a
RX(theta₈)
6e3018d0ca6146cb8909f9b1f445d2b0--97ad8af2f110429e89f63ad8ff753d3a
8b9d11c4a52741d3835ebeae49282e16
97ad8af2f110429e89f63ad8ff753d3a--8b9d11c4a52741d3835ebeae49282e16
520ddfa9c7064e1a8b4949abd3dbc368
8b9d11c4a52741d3835ebeae49282e16--520ddfa9c7064e1a8b4949abd3dbc368
95a3e9f2568347d99d53fc8a03ee3b00
RX(theta₁₂)
520ddfa9c7064e1a8b4949abd3dbc368--95a3e9f2568347d99d53fc8a03ee3b00
93b504b947044a3db4435dd819eb260f
RY(theta₁₆)
95a3e9f2568347d99d53fc8a03ee3b00--93b504b947044a3db4435dd819eb260f
aa5abf4ad6304e42b89eff92219b20a5
RX(theta₂₀)
93b504b947044a3db4435dd819eb260f--aa5abf4ad6304e42b89eff92219b20a5
cb7342ac84ba46af8c13ae49fe2f80cb
aa5abf4ad6304e42b89eff92219b20a5--cb7342ac84ba46af8c13ae49fe2f80cb
e09ee059d03145deb88046e8c18c7566
cb7342ac84ba46af8c13ae49fe2f80cb--e09ee059d03145deb88046e8c18c7566
bc46189310fd46dc9d99d93d50f434c2
RX(theta₀)
e09ee059d03145deb88046e8c18c7566--bc46189310fd46dc9d99d93d50f434c2
89b3937dbbc3465a8f869fb6f511a78c
RY(theta₄)
bc46189310fd46dc9d99d93d50f434c2--89b3937dbbc3465a8f869fb6f511a78c
a77911c23c534c28a477bda7c921d7b9
RX(theta₈)
89b3937dbbc3465a8f869fb6f511a78c--a77911c23c534c28a477bda7c921d7b9
bc96a613564f4489a38a114f4d4dadbc
a77911c23c534c28a477bda7c921d7b9--bc96a613564f4489a38a114f4d4dadbc
258cffc2c0c24caa91476518bba16fa9
bc96a613564f4489a38a114f4d4dadbc--258cffc2c0c24caa91476518bba16fa9
686c1e967ef2484a986fbee3ba378d2d
RX(theta₁₂)
258cffc2c0c24caa91476518bba16fa9--686c1e967ef2484a986fbee3ba378d2d
0a0015ae7b8747a3806c467c4636a55e
RY(theta₁₆)
686c1e967ef2484a986fbee3ba378d2d--0a0015ae7b8747a3806c467c4636a55e
99d98b58f8bc4c35b2f8337a7ee4a069
RX(theta₂₀)
0a0015ae7b8747a3806c467c4636a55e--99d98b58f8bc4c35b2f8337a7ee4a069
3042a280debe47d69c3d3df9ac358932
99d98b58f8bc4c35b2f8337a7ee4a069--3042a280debe47d69c3d3df9ac358932
aea136db2f034d209ab3e0c39870bced
3042a280debe47d69c3d3df9ac358932--aea136db2f034d209ab3e0c39870bced
2e8b285e42f34e9fa48e3cc965d3fbfa
aea136db2f034d209ab3e0c39870bced--2e8b285e42f34e9fa48e3cc965d3fbfa
9d5d00c333b948318ea44c8dc11c5dac
bb7511a31e314f1f91c2980ce134b0df
RX(theta₁)
4cddfa71f0ff41bfb68e950192d9f38e--bb7511a31e314f1f91c2980ce134b0df
f8d15fb6728047f3813736de8d0fe406
2
9f5caf95af324f6bbae0abeb1ad1979c
RY(theta₅)
bb7511a31e314f1f91c2980ce134b0df--9f5caf95af324f6bbae0abeb1ad1979c
84b7078c7db34a4abb15a3d0108f4641
RX(theta₉)
9f5caf95af324f6bbae0abeb1ad1979c--84b7078c7db34a4abb15a3d0108f4641
16af3194a8134c9080f2d5eb9d525c87
X
84b7078c7db34a4abb15a3d0108f4641--16af3194a8134c9080f2d5eb9d525c87
16af3194a8134c9080f2d5eb9d525c87--8b9d11c4a52741d3835ebeae49282e16
1dbdbeb9d36248a8b77c55b22e1017bf
16af3194a8134c9080f2d5eb9d525c87--1dbdbeb9d36248a8b77c55b22e1017bf
2aa47204c68a4149aa3c53e45b9931d7
RX(theta₁₃)
1dbdbeb9d36248a8b77c55b22e1017bf--2aa47204c68a4149aa3c53e45b9931d7
066350eafaa14503a5ff33776788c9a8
RY(theta₁₇)
2aa47204c68a4149aa3c53e45b9931d7--066350eafaa14503a5ff33776788c9a8
f9db5fd9a5d94a969213a1ea30f74913
RX(theta₂₁)
066350eafaa14503a5ff33776788c9a8--f9db5fd9a5d94a969213a1ea30f74913
1d551c8f3b0e4bacb4ebbf4c609410ac
X
f9db5fd9a5d94a969213a1ea30f74913--1d551c8f3b0e4bacb4ebbf4c609410ac
1d551c8f3b0e4bacb4ebbf4c609410ac--cb7342ac84ba46af8c13ae49fe2f80cb
aeb5c801283342ba9e78fe87b67816a4
1d551c8f3b0e4bacb4ebbf4c609410ac--aeb5c801283342ba9e78fe87b67816a4
f4cd526bf3564684a5d845d6e5861182
RX(theta₁)
aeb5c801283342ba9e78fe87b67816a4--f4cd526bf3564684a5d845d6e5861182
8d376a679c6348ee8dad1caa2e8320cd
RY(theta₅)
f4cd526bf3564684a5d845d6e5861182--8d376a679c6348ee8dad1caa2e8320cd
a25ab5d2027248b1a714fd2f01a47a2b
RX(theta₉)
8d376a679c6348ee8dad1caa2e8320cd--a25ab5d2027248b1a714fd2f01a47a2b
608305643abb41d29948dc37746eae46
X
a25ab5d2027248b1a714fd2f01a47a2b--608305643abb41d29948dc37746eae46
608305643abb41d29948dc37746eae46--bc96a613564f4489a38a114f4d4dadbc
0a8ea2a57ba745a2ae4f7d9649daf3f9
608305643abb41d29948dc37746eae46--0a8ea2a57ba745a2ae4f7d9649daf3f9
174c704ce41b415f95eec482a00030ae
RX(theta₁₃)
0a8ea2a57ba745a2ae4f7d9649daf3f9--174c704ce41b415f95eec482a00030ae
0d52e6d90ec349ab9399d0e7602a62a6
RY(theta₁₇)
174c704ce41b415f95eec482a00030ae--0d52e6d90ec349ab9399d0e7602a62a6
e549419850b3495b86c2a224aff5830f
RX(theta₂₁)
0d52e6d90ec349ab9399d0e7602a62a6--e549419850b3495b86c2a224aff5830f
54590370841e4ae9894e8b8be4181166
X
e549419850b3495b86c2a224aff5830f--54590370841e4ae9894e8b8be4181166
54590370841e4ae9894e8b8be4181166--3042a280debe47d69c3d3df9ac358932
1b5248b33737475588a7b707ba6ec292
54590370841e4ae9894e8b8be4181166--1b5248b33737475588a7b707ba6ec292
1b5248b33737475588a7b707ba6ec292--9d5d00c333b948318ea44c8dc11c5dac
6f734492e97c477f838a3b8f0afb4036
74695b6a8673437eb64d23bd720c0cb8
RX(theta₂)
f8d15fb6728047f3813736de8d0fe406--74695b6a8673437eb64d23bd720c0cb8
015db55b7e004fe4837967a3b229b0dd
3
534792b6912f46c18dfddf912a37edf2
RY(theta₆)
74695b6a8673437eb64d23bd720c0cb8--534792b6912f46c18dfddf912a37edf2
5f5a76472ccb440192348552bf3ccb68
RX(theta₁₀)
534792b6912f46c18dfddf912a37edf2--5f5a76472ccb440192348552bf3ccb68
05402d0ecb0e47899e8a5ea80038ca99
5f5a76472ccb440192348552bf3ccb68--05402d0ecb0e47899e8a5ea80038ca99
c91ae091f20b4d3b8afc01a006732a1f
X
05402d0ecb0e47899e8a5ea80038ca99--c91ae091f20b4d3b8afc01a006732a1f
c91ae091f20b4d3b8afc01a006732a1f--1dbdbeb9d36248a8b77c55b22e1017bf
6a1a02896a404e79a544b2f2e95fc1b4
RX(theta₁₄)
c91ae091f20b4d3b8afc01a006732a1f--6a1a02896a404e79a544b2f2e95fc1b4
0adda69356344c178d7aa0d0855024a7
RY(theta₁₈)
6a1a02896a404e79a544b2f2e95fc1b4--0adda69356344c178d7aa0d0855024a7
de137f552d654af6b4bc657b6929a149
RX(theta₂₂)
0adda69356344c178d7aa0d0855024a7--de137f552d654af6b4bc657b6929a149
fc844d6192464166b5c419adf539d137
de137f552d654af6b4bc657b6929a149--fc844d6192464166b5c419adf539d137
e0ad8e5943ec4ceab041af2da9270003
X
fc844d6192464166b5c419adf539d137--e0ad8e5943ec4ceab041af2da9270003
e0ad8e5943ec4ceab041af2da9270003--aeb5c801283342ba9e78fe87b67816a4
af8a88caa7e344e9b2c0c316acb25638
RX(theta₂)
e0ad8e5943ec4ceab041af2da9270003--af8a88caa7e344e9b2c0c316acb25638
f0d573aa6551448f99681bb0e8820254
RY(theta₆)
af8a88caa7e344e9b2c0c316acb25638--f0d573aa6551448f99681bb0e8820254
d7d8c103665c4d1ba7dbe2ac538a32cf
RX(theta₁₀)
f0d573aa6551448f99681bb0e8820254--d7d8c103665c4d1ba7dbe2ac538a32cf
1b55589f46e74958819f61c5f1fe7e38
d7d8c103665c4d1ba7dbe2ac538a32cf--1b55589f46e74958819f61c5f1fe7e38
0d2c5e3ab66f42ec8879e56b510ef8da
X
1b55589f46e74958819f61c5f1fe7e38--0d2c5e3ab66f42ec8879e56b510ef8da
0d2c5e3ab66f42ec8879e56b510ef8da--0a8ea2a57ba745a2ae4f7d9649daf3f9
28d00c936a654d35bbd35129292a7e5a
RX(theta₁₄)
0d2c5e3ab66f42ec8879e56b510ef8da--28d00c936a654d35bbd35129292a7e5a
46e2ee7b2843463b9291c01c8c4f5f7d
RY(theta₁₈)
28d00c936a654d35bbd35129292a7e5a--46e2ee7b2843463b9291c01c8c4f5f7d
385ce545676d4367bc0f2d2a4eba1df3
RX(theta₂₂)
46e2ee7b2843463b9291c01c8c4f5f7d--385ce545676d4367bc0f2d2a4eba1df3
859f0f31183c467ebaec61e508504e65
385ce545676d4367bc0f2d2a4eba1df3--859f0f31183c467ebaec61e508504e65
cc5bc77fae054c158c4752ad0a9788b0
X
859f0f31183c467ebaec61e508504e65--cc5bc77fae054c158c4752ad0a9788b0
cc5bc77fae054c158c4752ad0a9788b0--1b5248b33737475588a7b707ba6ec292
cc5bc77fae054c158c4752ad0a9788b0--6f734492e97c477f838a3b8f0afb4036
f850c68270054ff781851d62de672ca6
e323d899284f4495a642fa1fe42164bd
RX(theta₃)
015db55b7e004fe4837967a3b229b0dd--e323d899284f4495a642fa1fe42164bd
b55aef16bfa6436c8bf808732476ab73
RY(theta₇)
e323d899284f4495a642fa1fe42164bd--b55aef16bfa6436c8bf808732476ab73
82d11dc4be954825904d2ff31923150b
RX(theta₁₁)
b55aef16bfa6436c8bf808732476ab73--82d11dc4be954825904d2ff31923150b
7013df92350245b799be8cb749b84a2f
X
82d11dc4be954825904d2ff31923150b--7013df92350245b799be8cb749b84a2f
7013df92350245b799be8cb749b84a2f--05402d0ecb0e47899e8a5ea80038ca99
388a9076433d4b67ae5f4f3c63c4cf86
7013df92350245b799be8cb749b84a2f--388a9076433d4b67ae5f4f3c63c4cf86
4e72fd8f1fb34c159248ff090fb25de3
RX(theta₁₅)
388a9076433d4b67ae5f4f3c63c4cf86--4e72fd8f1fb34c159248ff090fb25de3
2ab9438e291b45eea109f9e86fc256a8
RY(theta₁₉)
4e72fd8f1fb34c159248ff090fb25de3--2ab9438e291b45eea109f9e86fc256a8
5b44a713e015408e9455c31bb60c2d14
RX(theta₂₃)
2ab9438e291b45eea109f9e86fc256a8--5b44a713e015408e9455c31bb60c2d14
96010140bf8349b99c2cce91fa7dc361
X
5b44a713e015408e9455c31bb60c2d14--96010140bf8349b99c2cce91fa7dc361
96010140bf8349b99c2cce91fa7dc361--fc844d6192464166b5c419adf539d137
931354c35e82400ca4ba60873aae5d34
96010140bf8349b99c2cce91fa7dc361--931354c35e82400ca4ba60873aae5d34
7d4527e4ee9d4cc0bfbb67a5b0646a72
RX(theta₃)
931354c35e82400ca4ba60873aae5d34--7d4527e4ee9d4cc0bfbb67a5b0646a72
f47bdfc2379248a4b4d501aed29f84a8
RY(theta₇)
7d4527e4ee9d4cc0bfbb67a5b0646a72--f47bdfc2379248a4b4d501aed29f84a8
b0ccac41c28849908bcb99891ab4f76c
RX(theta₁₁)
f47bdfc2379248a4b4d501aed29f84a8--b0ccac41c28849908bcb99891ab4f76c
35771bea370b4da4aa4e6cd399611187
X
b0ccac41c28849908bcb99891ab4f76c--35771bea370b4da4aa4e6cd399611187
35771bea370b4da4aa4e6cd399611187--1b55589f46e74958819f61c5f1fe7e38
6d56dfa946bf4359aea859e2a6ca7d83
35771bea370b4da4aa4e6cd399611187--6d56dfa946bf4359aea859e2a6ca7d83
77692966a7fd4edda232d6ada94afe01
RX(theta₁₅)
6d56dfa946bf4359aea859e2a6ca7d83--77692966a7fd4edda232d6ada94afe01
79f589b7c8c045e2a4ec62857eb6c7d7
RY(theta₁₉)
77692966a7fd4edda232d6ada94afe01--79f589b7c8c045e2a4ec62857eb6c7d7
e1b6b982f355467bb5a4230b6f353ebe
RX(theta₂₃)
79f589b7c8c045e2a4ec62857eb6c7d7--e1b6b982f355467bb5a4230b6f353ebe
08f3e735690b4315ade0fe1842b29a0f
X
e1b6b982f355467bb5a4230b6f353ebe--08f3e735690b4315ade0fe1842b29a0f
08f3e735690b4315ade0fe1842b29a0f--859f0f31183c467ebaec61e508504e65
4b0af3272b8345e89255eab80ba0e711
08f3e735690b4315ade0fe1842b29a0f--4b0af3272b8345e89255eab80ba0e711
4b0af3272b8345e89255eab80ba0e711--f850c68270054ff781851d62de672ca6
Avoid non-unique names by prefixing
A parameter prefix for each HEA can be passed as follows:
hea1 = hea ( n_qubits = n_qubits , depth = depth , param_prefix = "p1" )
hea2 = hea ( n_qubits = n_qubits , depth = depth , param_prefix = "p2" )
circuit = QuantumCircuit ( n_qubits , hea1 , hea2 )
n_params_two_heas = circuit . num_unique_parameters
U n ique parame ters wi t h t wo s ta cked HEAs : 48
%3
cluster_abda15422666475796f4c83070cc81cb
HEA
cluster_b0906d263336440b884381bc109900b8
HEA
78c00d7322fa4953a243a01f996d061c
0
209287695634457197b21aad4b7a74ce
RX(p1₀)
78c00d7322fa4953a243a01f996d061c--209287695634457197b21aad4b7a74ce
b8168f84e0a34fe9ad0f286c6e01592d
1
70c273e6cfdc4e918f0c1b383ba0e28e
RY(p1₄)
209287695634457197b21aad4b7a74ce--70c273e6cfdc4e918f0c1b383ba0e28e
7169fd11c2a74c60973c27a12a548725
RX(p1₈)
70c273e6cfdc4e918f0c1b383ba0e28e--7169fd11c2a74c60973c27a12a548725
c647f603462f4a00afcc9dd25cfc440f
7169fd11c2a74c60973c27a12a548725--c647f603462f4a00afcc9dd25cfc440f
1a2fb03f9c074d7b92492f406e27897b
c647f603462f4a00afcc9dd25cfc440f--1a2fb03f9c074d7b92492f406e27897b
acc5692cbfcc436284bd08a512658a7b
RX(p1₁₂)
1a2fb03f9c074d7b92492f406e27897b--acc5692cbfcc436284bd08a512658a7b
12ed446d15324fa5ab8b8efec33185f0
RY(p1₁₆)
acc5692cbfcc436284bd08a512658a7b--12ed446d15324fa5ab8b8efec33185f0
8f4077d55b6c4a57b0409f1e2e8f7268
RX(p1₂₀)
12ed446d15324fa5ab8b8efec33185f0--8f4077d55b6c4a57b0409f1e2e8f7268
8a8845fd19db49a19c354935718c4636
8f4077d55b6c4a57b0409f1e2e8f7268--8a8845fd19db49a19c354935718c4636
dd259464dbfc444abae9fcf85ed3f7d8
8a8845fd19db49a19c354935718c4636--dd259464dbfc444abae9fcf85ed3f7d8
aea0b1a2dfc5408ab988d067fc57f007
RX(p2₀)
dd259464dbfc444abae9fcf85ed3f7d8--aea0b1a2dfc5408ab988d067fc57f007
2690d2d2ab7b43988a7e3b95443edcd6
RY(p2₄)
aea0b1a2dfc5408ab988d067fc57f007--2690d2d2ab7b43988a7e3b95443edcd6
58a0afee205949cea26b365295e2687b
RX(p2₈)
2690d2d2ab7b43988a7e3b95443edcd6--58a0afee205949cea26b365295e2687b
8990dd3d93824c6c9dee14d8d74a765c
58a0afee205949cea26b365295e2687b--8990dd3d93824c6c9dee14d8d74a765c
23650ee47eb34806a9f6324deeb80421
8990dd3d93824c6c9dee14d8d74a765c--23650ee47eb34806a9f6324deeb80421
acabcbf9282f4639898c2ff504d9fe41
RX(p2₁₂)
23650ee47eb34806a9f6324deeb80421--acabcbf9282f4639898c2ff504d9fe41
ce659d798e784f4c8bb2c19ce8bf8880
RY(p2₁₆)
acabcbf9282f4639898c2ff504d9fe41--ce659d798e784f4c8bb2c19ce8bf8880
1de79d7cf12e45b1bf897647c489da48
RX(p2₂₀)
ce659d798e784f4c8bb2c19ce8bf8880--1de79d7cf12e45b1bf897647c489da48
4b6ec971dca54585b5732784b7bbec36
1de79d7cf12e45b1bf897647c489da48--4b6ec971dca54585b5732784b7bbec36
1198465f2e064349bb55b323de9d9adb
4b6ec971dca54585b5732784b7bbec36--1198465f2e064349bb55b323de9d9adb
0f79529eb22d48f98d342143bff10276
1198465f2e064349bb55b323de9d9adb--0f79529eb22d48f98d342143bff10276
8745d6949db948379ef0c5b2d0c168d2
fbb28c3c1cde4b20bcd7da904bb446b2
RX(p1₁)
b8168f84e0a34fe9ad0f286c6e01592d--fbb28c3c1cde4b20bcd7da904bb446b2
d656394d88914745a66bb84501ff4fcb
2
0dbba14373a147b09ec598900a637931
RY(p1₅)
fbb28c3c1cde4b20bcd7da904bb446b2--0dbba14373a147b09ec598900a637931
d846eb43654449939970209a1d87447d
RX(p1₉)
0dbba14373a147b09ec598900a637931--d846eb43654449939970209a1d87447d
ffaa8a08d9b743b8a52f65ca5fa173ee
X
d846eb43654449939970209a1d87447d--ffaa8a08d9b743b8a52f65ca5fa173ee
ffaa8a08d9b743b8a52f65ca5fa173ee--c647f603462f4a00afcc9dd25cfc440f
e26fa38028bc4aedb0b217bf00da4313
ffaa8a08d9b743b8a52f65ca5fa173ee--e26fa38028bc4aedb0b217bf00da4313
b6c912ddb39741d8bec22933979b5d09
RX(p1₁₃)
e26fa38028bc4aedb0b217bf00da4313--b6c912ddb39741d8bec22933979b5d09
c7931ca6faae4f06b4c46fdba6bf293c
RY(p1₁₇)
b6c912ddb39741d8bec22933979b5d09--c7931ca6faae4f06b4c46fdba6bf293c
435b186eca3e434294632911b55832f9
RX(p1₂₁)
c7931ca6faae4f06b4c46fdba6bf293c--435b186eca3e434294632911b55832f9
933cf568e64f4542b3e146a7db172926
X
435b186eca3e434294632911b55832f9--933cf568e64f4542b3e146a7db172926
933cf568e64f4542b3e146a7db172926--8a8845fd19db49a19c354935718c4636
6284eb7fec7b4e4da3039f39e4da81fd
933cf568e64f4542b3e146a7db172926--6284eb7fec7b4e4da3039f39e4da81fd
296057333c114f209ac5109cd4470ce0
RX(p2₁)
6284eb7fec7b4e4da3039f39e4da81fd--296057333c114f209ac5109cd4470ce0
12d94f4fc79f4e4e894138ef969857fc
RY(p2₅)
296057333c114f209ac5109cd4470ce0--12d94f4fc79f4e4e894138ef969857fc
9af53df0b7d34283832d285ec881ce8f
RX(p2₉)
12d94f4fc79f4e4e894138ef969857fc--9af53df0b7d34283832d285ec881ce8f
35edc9b8ee5b4fa38a1c5c36f1384c18
X
9af53df0b7d34283832d285ec881ce8f--35edc9b8ee5b4fa38a1c5c36f1384c18
35edc9b8ee5b4fa38a1c5c36f1384c18--8990dd3d93824c6c9dee14d8d74a765c
269c12abe49249a78cb1a19c590b7c27
35edc9b8ee5b4fa38a1c5c36f1384c18--269c12abe49249a78cb1a19c590b7c27
4b5640815b0743ae813364fdf5fa050e
RX(p2₁₃)
269c12abe49249a78cb1a19c590b7c27--4b5640815b0743ae813364fdf5fa050e
afb3fe2d2792480cb8ca174ff7f576b0
RY(p2₁₇)
4b5640815b0743ae813364fdf5fa050e--afb3fe2d2792480cb8ca174ff7f576b0
55c7055abb854f45a989623dc2151fcd
RX(p2₂₁)
afb3fe2d2792480cb8ca174ff7f576b0--55c7055abb854f45a989623dc2151fcd
9c77397599034231a18e2a15eedff696
X
55c7055abb854f45a989623dc2151fcd--9c77397599034231a18e2a15eedff696
9c77397599034231a18e2a15eedff696--4b6ec971dca54585b5732784b7bbec36
6dbf7bcd7a8f48d4901ee13f9c94f0f5
9c77397599034231a18e2a15eedff696--6dbf7bcd7a8f48d4901ee13f9c94f0f5
6dbf7bcd7a8f48d4901ee13f9c94f0f5--8745d6949db948379ef0c5b2d0c168d2
929c64c0c75c411b97bf43be7fe6338a
da0c92c0051e47919005c952e5c62bad
RX(p1₂)
d656394d88914745a66bb84501ff4fcb--da0c92c0051e47919005c952e5c62bad
4aaad3da46564675ba58b6564bd49af6
3
200bce13b58347149dd2cda3a0c6ee57
RY(p1₆)
da0c92c0051e47919005c952e5c62bad--200bce13b58347149dd2cda3a0c6ee57
d7d263cdfca24332b5c24e40918b78ab
RX(p1₁₀)
200bce13b58347149dd2cda3a0c6ee57--d7d263cdfca24332b5c24e40918b78ab
3369ecd88d5b407b9eb26fb1e029ac61
d7d263cdfca24332b5c24e40918b78ab--3369ecd88d5b407b9eb26fb1e029ac61
5ec0c7a9e5104312a8f1f49ca1741b50
X
3369ecd88d5b407b9eb26fb1e029ac61--5ec0c7a9e5104312a8f1f49ca1741b50
5ec0c7a9e5104312a8f1f49ca1741b50--e26fa38028bc4aedb0b217bf00da4313
4a8797461863492f99129048b1185ee0
RX(p1₁₄)
5ec0c7a9e5104312a8f1f49ca1741b50--4a8797461863492f99129048b1185ee0
2b8bb4c4e43e4537ba014eb3adb6a895
RY(p1₁₈)
4a8797461863492f99129048b1185ee0--2b8bb4c4e43e4537ba014eb3adb6a895
358b0037c5874b569cb12f465748c459
RX(p1₂₂)
2b8bb4c4e43e4537ba014eb3adb6a895--358b0037c5874b569cb12f465748c459
c5641b2a1b384433a39a0e3b2abb83bd
358b0037c5874b569cb12f465748c459--c5641b2a1b384433a39a0e3b2abb83bd
e1b984f66aba48039c9f1316c4d1e5fa
X
c5641b2a1b384433a39a0e3b2abb83bd--e1b984f66aba48039c9f1316c4d1e5fa
e1b984f66aba48039c9f1316c4d1e5fa--6284eb7fec7b4e4da3039f39e4da81fd
17b9bf6905fc4133b73881f62b94f850
RX(p2₂)
e1b984f66aba48039c9f1316c4d1e5fa--17b9bf6905fc4133b73881f62b94f850
0fd1e9466f13484e8d63c439f3758bef
RY(p2₆)
17b9bf6905fc4133b73881f62b94f850--0fd1e9466f13484e8d63c439f3758bef
d813c230926643bea25620b4e1fdbf52
RX(p2₁₀)
0fd1e9466f13484e8d63c439f3758bef--d813c230926643bea25620b4e1fdbf52
8ee933186f8448a8a287ac09f31c3249
d813c230926643bea25620b4e1fdbf52--8ee933186f8448a8a287ac09f31c3249
429aedf201f342a8ace8bd9521bf1fd9
X
8ee933186f8448a8a287ac09f31c3249--429aedf201f342a8ace8bd9521bf1fd9
429aedf201f342a8ace8bd9521bf1fd9--269c12abe49249a78cb1a19c590b7c27
eac09af2ccc048729b56389117c983e4
RX(p2₁₄)
429aedf201f342a8ace8bd9521bf1fd9--eac09af2ccc048729b56389117c983e4
a48245d0eb6f45f3abd39a3660632fae
RY(p2₁₈)
eac09af2ccc048729b56389117c983e4--a48245d0eb6f45f3abd39a3660632fae
9e6ef99b88c840e5aaf80767c4667e5e
RX(p2₂₂)
a48245d0eb6f45f3abd39a3660632fae--9e6ef99b88c840e5aaf80767c4667e5e
15f11b367df14f23b05084dbe7cc0bf0
9e6ef99b88c840e5aaf80767c4667e5e--15f11b367df14f23b05084dbe7cc0bf0
66bfc0b4609b4f49b6ac655f0239d7c8
X
15f11b367df14f23b05084dbe7cc0bf0--66bfc0b4609b4f49b6ac655f0239d7c8
66bfc0b4609b4f49b6ac655f0239d7c8--6dbf7bcd7a8f48d4901ee13f9c94f0f5
66bfc0b4609b4f49b6ac655f0239d7c8--929c64c0c75c411b97bf43be7fe6338a
3c5abb47e7c24d6baf599bf3dfc0274f
3b2ef712e500496693b4697885e62cfd
RX(p1₃)
4aaad3da46564675ba58b6564bd49af6--3b2ef712e500496693b4697885e62cfd
d7f36e123ffe4db597ca6493c841eaff
RY(p1₇)
3b2ef712e500496693b4697885e62cfd--d7f36e123ffe4db597ca6493c841eaff
172ea8e5df484b5aa34e9ea90c26ffae
RX(p1₁₁)
d7f36e123ffe4db597ca6493c841eaff--172ea8e5df484b5aa34e9ea90c26ffae
bec8c7c6d5b64d1ab5c2964c47d1743f
X
172ea8e5df484b5aa34e9ea90c26ffae--bec8c7c6d5b64d1ab5c2964c47d1743f
bec8c7c6d5b64d1ab5c2964c47d1743f--3369ecd88d5b407b9eb26fb1e029ac61
d1692c83a726477a90c1266d2f1d1b4d
bec8c7c6d5b64d1ab5c2964c47d1743f--d1692c83a726477a90c1266d2f1d1b4d
06eebb27353b41bd925ca59767bf04d3
RX(p1₁₅)
d1692c83a726477a90c1266d2f1d1b4d--06eebb27353b41bd925ca59767bf04d3
b13c8a5440454945a353f5834e37ebda
RY(p1₁₉)
06eebb27353b41bd925ca59767bf04d3--b13c8a5440454945a353f5834e37ebda
06359521606d40b9b4f6eb2306bfce4c
RX(p1₂₃)
b13c8a5440454945a353f5834e37ebda--06359521606d40b9b4f6eb2306bfce4c
5b2e4aeba0ed494aaa2fb990a3f6105e
X
06359521606d40b9b4f6eb2306bfce4c--5b2e4aeba0ed494aaa2fb990a3f6105e
5b2e4aeba0ed494aaa2fb990a3f6105e--c5641b2a1b384433a39a0e3b2abb83bd
4ab4ee83a2ae42cb90a1eb0c824267e8
5b2e4aeba0ed494aaa2fb990a3f6105e--4ab4ee83a2ae42cb90a1eb0c824267e8
da0bb4e6d8444e8d81f927c31ea5f049
RX(p2₃)
4ab4ee83a2ae42cb90a1eb0c824267e8--da0bb4e6d8444e8d81f927c31ea5f049
e0150c8892514b3f8eb616446b334005
RY(p2₇)
da0bb4e6d8444e8d81f927c31ea5f049--e0150c8892514b3f8eb616446b334005
9674bf2cbd9f4b2ea0c6140741118570
RX(p2₁₁)
e0150c8892514b3f8eb616446b334005--9674bf2cbd9f4b2ea0c6140741118570
d44b4fcd33c54998af4e668576058798
X
9674bf2cbd9f4b2ea0c6140741118570--d44b4fcd33c54998af4e668576058798
d44b4fcd33c54998af4e668576058798--8ee933186f8448a8a287ac09f31c3249
53fb841e78df44629a1fc23f524ae28e
d44b4fcd33c54998af4e668576058798--53fb841e78df44629a1fc23f524ae28e
acd086529c0742ce876bcc9060a9cdf3
RX(p2₁₅)
53fb841e78df44629a1fc23f524ae28e--acd086529c0742ce876bcc9060a9cdf3
0fd8363726d248719cb4d2a7ab37059b
RY(p2₁₉)
acd086529c0742ce876bcc9060a9cdf3--0fd8363726d248719cb4d2a7ab37059b
46e3542c59e94a688aeeb0077320bdfe
RX(p2₂₃)
0fd8363726d248719cb4d2a7ab37059b--46e3542c59e94a688aeeb0077320bdfe
46eb6dea43704766bee041759e73ab44
X
46e3542c59e94a688aeeb0077320bdfe--46eb6dea43704766bee041759e73ab44
46eb6dea43704766bee041759e73ab44--15f11b367df14f23b05084dbe7cc0bf0
a98187918a0747de8e5efc76b781d10b
46eb6dea43704766bee041759e73ab44--a98187918a0747de8e5efc76b781d10b
a98187918a0747de8e5efc76b781d10b--3c5abb47e7c24d6baf599bf3dfc0274f
The hea
function will be further explored in the QML Constructors tutorial .
Parametric observables
In Qadence, one can define quantum observables with classical optimizable parameters to
improve the convergence of QML calculations. This is particularly useful for differentiable quantum circuits.
from qadence import VariationalParameter , Z , add , tag
s = VariationalParameter ( "s" )
observable = add ( s * Z ( i ) for i in range ( n_qubits ))
Now, a quantum model can be created with the parametric observable.
The observable variational parameters are included among the model ones.
from qadence import QuantumModel , QuantumCircuit
circuit = QuantumCircuit ( n_qubits , hea ( n_qubits , depth ))
model = QuantumModel ( circuit , observable = observable )
Varia t io nal parame ters = OrderedDic t ( [ ('s' , tens or( [ 0.4060 ] )) , (' t he ta _ 0 ' , tens or( [ 0.7295 ] )) , (' t he ta _ 1 ' , tens or( [ 0.4842 ] )) , (' t he ta _ 10 ' , tens or( [ 0.2934 ] )) , (' t he ta _ 11 ' , tens or( [ 0.9087 ] )) , (' t he ta _ 12 ' , tens or( [ 0.5591 ] )) , (' t he ta _ 13 ' , tens or( [ 0.2918 ] )) , (' t he ta _ 14 ' , tens or( [ 0.6196 ] )) , (' t he ta _ 15 ' , tens or( [ 0.0873 ] )) , (' t he ta _ 16 ' , tens or( [ 0.7099 ] )) , (' t he ta _ 17 ' , tens or( [ 0.5362 ] )) , (' t he ta _ 18 ' , tens or( [ 0.3060 ] )) , (' t he ta _ 19 ' , tens or( [ 0.0122 ] )) , (' t he ta _ 2 ' , tens or( [ 0.4173 ] )) , (' t he ta _ 20 ' , tens or( [ 0.5521 ] )) , (' t he ta _ 21 ' , tens or( [ 0.0399 ] )) , (' t he ta _ 22 ' , tens or( [ 0.4448 ] )) , (' t he ta _ 23 ' , tens or( [ 0.8476 ] )) , (' t he ta _ 3 ' , tens or( [ 0.6639 ] )) , (' t he ta _ 4 ' , tens or( [ 0.6974 ] )) , (' t he ta _ 5 ' , tens or( [ 0.1438 ] )) , (' t he ta _ 6 ' , tens or( [ 0.6251 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3880 ] )) , (' t he ta _ 8 ' , tens or( [ 0.2627 ] )) , (' t he ta _ 9 ' , tens or( [ 0.4693 ] )) ] )
One optimization step (forward and backward pass) can be performed using built-in torch
functionalities. Variational parameters
can be checked to have been updated accordingly:
import torch
mse_loss = torch . nn . MSELoss ()
optimizer = torch . optim . Adam ( model . parameters ())
# Compute forward & backward pass
optimizer . zero_grad ()
loss = mse_loss ( model . expectation ({}), torch . zeros ( 1 ))
loss . backward ()
# Update the parameters and check the parameters.
optimizer . step ()
Varia t io nal parame ters = OrderedDic t ( [ ('s' , tens or( [ 0.4050 ] )) , (' t he ta _ 0 ' , tens or( [ 0.7285 ] )) , (' t he ta _ 1 ' , tens or( [ 0.4832 ] )) , (' t he ta _ 10 ' , tens or( [ 0.2944 ] )) , (' t he ta _ 11 ' , tens or( [ 0.9097 ] )) , (' t he ta _ 12 ' , tens or( [ 0.5601 ] )) , (' t he ta _ 13 ' , tens or( [ 0.2908 ] )) , (' t he ta _ 14 ' , tens or( [ 0.6186 ] )) , (' t he ta _ 15 ' , tens or( [ 0.0883 ] )) , (' t he ta _ 16 ' , tens or( [ 0.7109 ] )) , (' t he ta _ 17 ' , tens or( [ 0.5372 ] )) , (' t he ta _ 18 ' , tens or( [ 0.3070 ] )) , (' t he ta _ 19 ' , tens or( [ 0.0112 ] )) , (' t he ta _ 2 ' , tens or( [ 0.4183 ] )) , (' t he ta _ 20 ' , tens or( [ 0.5531 ] )) , (' t he ta _ 21 ' , tens or( [ 0.0389 ] )) , (' t he ta _ 22 ' , tens or( [ 0.4438 ] )) , (' t he ta _ 23 ' , tens or( [ 0.8486 ] )) , (' t he ta _ 3 ' , tens or( [ 0.6649 ] )) , (' t he ta _ 4 ' , tens or( [ 0.6984 ] )) , (' t he ta _ 5 ' , tens or( [ 0.1448 ] )) , (' t he ta _ 6 ' , tens or( [ 0.6261 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3870 ] )) , (' t he ta _ 8 ' , tens or( [ 0.2617 ] )) , (' t he ta _ 9 ' , tens or( [ 0.4683 ] )) ] )
Non-unitary circuits
Qadence allows composing with non-unitary blocks.
Here is an example of a non-unitary block as a sum of Pauli operators with complex coefficients.
Currently, only the PyQTorch
backend fully supports execution of non-unitary circuits.
from qadence import QuantumModel , QuantumCircuit , Z , X
c1 = 2.0
c2 = 2.0 + 2.0 j
block = c1 * Z ( 0 ) + c2 * X ( 1 ) + c1 * c2 * ( Z ( 2 ) + X ( 3 ))
circuit = QuantumCircuit ( 4 , block )
model = QuantumModel ( circuit ) # BackendName.PYQTORCH and DiffMode.AD by default.
w f = tens or( [[ 6.+4. j , 4.+4. j , 0.+0. j , 0.+0. j , 2.+2. j , 0.+0. j , 0.+0. j , 0.+0. j , 0.+0. j , 0.+0. j ,
0.+0. j , 0.+0. j , 0.+0. j , 0.+0. j , 0.+0. j , 0.+0. j ]] )