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.9895+0.0000 j , 0.0000-0.1448 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.8811+0.0000 j , 0.0000-0.4730 j ],
[ 0.9812+0.0000 j , 0.0000-0.1931 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.8543+0.0000 j , 0.3484+0.0000 j , 0.0000-0.3572 j , 0.0000-0.1457 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_22e44e5aec2a473da23273a5ef588dc1
[* 2]
cluster_18429e282e0144f1b7962170cb86d59a
Rotations
b8338d0c42d44f1e9168bfccbbc98270
0
411c0d00b1184f51ae8fbc97ee704cb4
RX(phi/theta)
b8338d0c42d44f1e9168bfccbbc98270--411c0d00b1184f51ae8fbc97ee704cb4
2f30bb352950486c88db4303890a5bf2
1
5192f77f42234290a95aef22a4210d00
RX(phi)
411c0d00b1184f51ae8fbc97ee704cb4--5192f77f42234290a95aef22a4210d00
53ac1e4952a64f1f99fbc70135c35e23
RX(phi)
5192f77f42234290a95aef22a4210d00--53ac1e4952a64f1f99fbc70135c35e23
1a22d0d8b3214a1a8d09c30641987e48
RX(phi + theta)
53ac1e4952a64f1f99fbc70135c35e23--1a22d0d8b3214a1a8d09c30641987e48
2f535edb08bf4420b0a137179b8acbc8
1a22d0d8b3214a1a8d09c30641987e48--2f535edb08bf4420b0a137179b8acbc8
2667e1cfa1d34f2aa0052baf6f4144f9
2f535edb08bf4420b0a137179b8acbc8--2667e1cfa1d34f2aa0052baf6f4144f9
d7ac4901f3024ffbb37211dde07a0a2e
Z
2667e1cfa1d34f2aa0052baf6f4144f9--d7ac4901f3024ffbb37211dde07a0a2e
6060728abe3c4989b8be143a2f2508ce
d7ac4901f3024ffbb37211dde07a0a2e--6060728abe3c4989b8be143a2f2508ce
1f6f7d915424460b9299fcf460cdfd43
ec9a852429da46efb1f12a1d75e3f670
RY(2*theta)
2f30bb352950486c88db4303890a5bf2--ec9a852429da46efb1f12a1d75e3f670
6ed050b180014da096cad362e4b5d1b7
2
d29faded310a4875a2615c1451d9e2dd
RY(theta)
ec9a852429da46efb1f12a1d75e3f670--d29faded310a4875a2615c1451d9e2dd
0769547d88b54b06972eb3f321c0bda9
RY(theta)
d29faded310a4875a2615c1451d9e2dd--0769547d88b54b06972eb3f321c0bda9
bcde605d2cce466aa20dd5c5dc5d9a9a
RY(theta**2)
0769547d88b54b06972eb3f321c0bda9--bcde605d2cce466aa20dd5c5dc5d9a9a
2bfb365746a8492890bb194608b4f1ff
X
bcde605d2cce466aa20dd5c5dc5d9a9a--2bfb365746a8492890bb194608b4f1ff
2bfb365746a8492890bb194608b4f1ff--2f535edb08bf4420b0a137179b8acbc8
2844943e6dd64a279fc87af160e615fc
2bfb365746a8492890bb194608b4f1ff--2844943e6dd64a279fc87af160e615fc
d423655ab4c340208f126eaf02a07d8a
Z
2844943e6dd64a279fc87af160e615fc--d423655ab4c340208f126eaf02a07d8a
d423655ab4c340208f126eaf02a07d8a--1f6f7d915424460b9299fcf460cdfd43
3d4a3c24e7eb443eab45745cb0f94047
0df2df301c0d47d1b08c1c69ff7ae228
RZ(cos(phi))
6ed050b180014da096cad362e4b5d1b7--0df2df301c0d47d1b08c1c69ff7ae228
9123e78ee6ee415682d32422f17f94df
RZ(phi)
0df2df301c0d47d1b08c1c69ff7ae228--9123e78ee6ee415682d32422f17f94df
453a7067a1dc470aaab480a37cb8a03f
RZ(phi)
9123e78ee6ee415682d32422f17f94df--453a7067a1dc470aaab480a37cb8a03f
56f520b2904443f78011d0f5601deb66
RZ(cos(phi))
453a7067a1dc470aaab480a37cb8a03f--56f520b2904443f78011d0f5601deb66
bf19f5eea4484f46832d607e2e071b64
56f520b2904443f78011d0f5601deb66--bf19f5eea4484f46832d607e2e071b64
b514bf1070a0492ca841b86ba621a16a
X
bf19f5eea4484f46832d607e2e071b64--b514bf1070a0492ca841b86ba621a16a
b514bf1070a0492ca841b86ba621a16a--2844943e6dd64a279fc87af160e615fc
79310dc8111b4e78947125322e62256d
Z
b514bf1070a0492ca841b86ba621a16a--79310dc8111b4e78947125322e62256d
79310dc8111b4e78947125322e62256d--3d4a3c24e7eb443eab45745cb0f94047
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.7213 ] )) ] )
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.4423+0.0000 j , 0.4967+0.0000 j , 0.0000-0.4967 j , 0.0000-0.5577 j ],
[ 0.5495+0.0000 j , 0.4975+0.0000 j , 0.0000-0.4975 j , 0.0000-0.4505 j ],
[ 0.8138+0.0000 j , 0.3893+0.0000 j , 0.0000-0.3893 j , 0.0000-0.1862 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
6e3b3bff53d343da9d5a59c6a31dcfe2
0
8f5bfd5871a044bca478f7b605f31e84
RX(theta₀)
6e3b3bff53d343da9d5a59c6a31dcfe2--8f5bfd5871a044bca478f7b605f31e84
a1fe492e00ed4072b8c5fb12415bd3f5
1
ee5c87892fac45e8bebe7ca4dd96c035
RY(theta₄)
8f5bfd5871a044bca478f7b605f31e84--ee5c87892fac45e8bebe7ca4dd96c035
df77fc43e3984dc5afdf2f5fb61bf5ba
RX(theta₈)
ee5c87892fac45e8bebe7ca4dd96c035--df77fc43e3984dc5afdf2f5fb61bf5ba
371e69c638974fa3a07c8ae912c863f3
df77fc43e3984dc5afdf2f5fb61bf5ba--371e69c638974fa3a07c8ae912c863f3
0f073b3bc376423296239a68becc81bc
371e69c638974fa3a07c8ae912c863f3--0f073b3bc376423296239a68becc81bc
575bb1d411ac41cd81c4ef38cb6f98f5
RX(theta₁₂)
0f073b3bc376423296239a68becc81bc--575bb1d411ac41cd81c4ef38cb6f98f5
e26e58097cf647f2a21730a2f52341ca
RY(theta₁₆)
575bb1d411ac41cd81c4ef38cb6f98f5--e26e58097cf647f2a21730a2f52341ca
ad822a2c105e4cd09393d791f91253af
RX(theta₂₀)
e26e58097cf647f2a21730a2f52341ca--ad822a2c105e4cd09393d791f91253af
a7c0fe1628124ddfa9960d5dbcf8278b
ad822a2c105e4cd09393d791f91253af--a7c0fe1628124ddfa9960d5dbcf8278b
eb91b3a4967a4736bd193c4b271e671a
a7c0fe1628124ddfa9960d5dbcf8278b--eb91b3a4967a4736bd193c4b271e671a
c085f159c5944cf49bbb26f5c4ed1fd1
eb91b3a4967a4736bd193c4b271e671a--c085f159c5944cf49bbb26f5c4ed1fd1
a13050daa57c4cb8b282f7f53b53fae8
ecbdb4551e5e45438df1cd00d345daef
RX(theta₁)
a1fe492e00ed4072b8c5fb12415bd3f5--ecbdb4551e5e45438df1cd00d345daef
a25931f2c703403b8def6944650b74ae
2
1c198cd50db14c3a8596995cc720a185
RY(theta₅)
ecbdb4551e5e45438df1cd00d345daef--1c198cd50db14c3a8596995cc720a185
b90ca461fc42457d9f1056a3766bb246
RX(theta₉)
1c198cd50db14c3a8596995cc720a185--b90ca461fc42457d9f1056a3766bb246
21ad8aa87f7249cc8982978d047630d9
X
b90ca461fc42457d9f1056a3766bb246--21ad8aa87f7249cc8982978d047630d9
21ad8aa87f7249cc8982978d047630d9--371e69c638974fa3a07c8ae912c863f3
feb5d10ef4034379b63e4048d78bd55e
21ad8aa87f7249cc8982978d047630d9--feb5d10ef4034379b63e4048d78bd55e
36fa81b102eb4e5aa724ac46feef3a6b
RX(theta₁₃)
feb5d10ef4034379b63e4048d78bd55e--36fa81b102eb4e5aa724ac46feef3a6b
bc1782727b4c459682197297908367b0
RY(theta₁₇)
36fa81b102eb4e5aa724ac46feef3a6b--bc1782727b4c459682197297908367b0
de8b1808a21648109999bceea212e64d
RX(theta₂₁)
bc1782727b4c459682197297908367b0--de8b1808a21648109999bceea212e64d
463f171613a4412cb7046ee87e6c22b9
X
de8b1808a21648109999bceea212e64d--463f171613a4412cb7046ee87e6c22b9
463f171613a4412cb7046ee87e6c22b9--a7c0fe1628124ddfa9960d5dbcf8278b
f5655d719ad948f5963a70f6a3d122a0
463f171613a4412cb7046ee87e6c22b9--f5655d719ad948f5963a70f6a3d122a0
f5655d719ad948f5963a70f6a3d122a0--a13050daa57c4cb8b282f7f53b53fae8
e8ab74d2387c4f7685868f8910558596
bfe54a8bbcb84595903e83cd27d1ca5d
RX(theta₂)
a25931f2c703403b8def6944650b74ae--bfe54a8bbcb84595903e83cd27d1ca5d
bd8942a7809f4b009672c2981f2deb0a
3
2b8710f2df4745968f898d2adf6d9337
RY(theta₆)
bfe54a8bbcb84595903e83cd27d1ca5d--2b8710f2df4745968f898d2adf6d9337
ad218507c1d045f78e461fbd7b0a4ec6
RX(theta₁₀)
2b8710f2df4745968f898d2adf6d9337--ad218507c1d045f78e461fbd7b0a4ec6
40a9d4b54cf547bbba00c19d1baca9cf
ad218507c1d045f78e461fbd7b0a4ec6--40a9d4b54cf547bbba00c19d1baca9cf
b58117bf5f4b45e3b481c7c8b09e421d
X
40a9d4b54cf547bbba00c19d1baca9cf--b58117bf5f4b45e3b481c7c8b09e421d
b58117bf5f4b45e3b481c7c8b09e421d--feb5d10ef4034379b63e4048d78bd55e
324dcfecab21433ab56f1dabe429830b
RX(theta₁₄)
b58117bf5f4b45e3b481c7c8b09e421d--324dcfecab21433ab56f1dabe429830b
36773dec78b7484d833a87c79e64e148
RY(theta₁₈)
324dcfecab21433ab56f1dabe429830b--36773dec78b7484d833a87c79e64e148
11137943ca2b4f4794cae8e77c869a34
RX(theta₂₂)
36773dec78b7484d833a87c79e64e148--11137943ca2b4f4794cae8e77c869a34
511e40a453e5468a94c89265d2988476
11137943ca2b4f4794cae8e77c869a34--511e40a453e5468a94c89265d2988476
0aa3ba1fae5949ceb50d6d29886344e5
X
511e40a453e5468a94c89265d2988476--0aa3ba1fae5949ceb50d6d29886344e5
0aa3ba1fae5949ceb50d6d29886344e5--f5655d719ad948f5963a70f6a3d122a0
0aa3ba1fae5949ceb50d6d29886344e5--e8ab74d2387c4f7685868f8910558596
61cda1e85797439d9f1c487be0c702ad
569edb53b9bb46b4ad8f20977d5f3b3c
RX(theta₃)
bd8942a7809f4b009672c2981f2deb0a--569edb53b9bb46b4ad8f20977d5f3b3c
2e18beabfcd5420fb41d9a904a4e81b6
RY(theta₇)
569edb53b9bb46b4ad8f20977d5f3b3c--2e18beabfcd5420fb41d9a904a4e81b6
03592e4f078745f08b832f37e2e94c1f
RX(theta₁₁)
2e18beabfcd5420fb41d9a904a4e81b6--03592e4f078745f08b832f37e2e94c1f
490bfe6dfa754649a6825977b18df00b
X
03592e4f078745f08b832f37e2e94c1f--490bfe6dfa754649a6825977b18df00b
490bfe6dfa754649a6825977b18df00b--40a9d4b54cf547bbba00c19d1baca9cf
264cfd7e1976454a9876f64bb8bbfc0a
490bfe6dfa754649a6825977b18df00b--264cfd7e1976454a9876f64bb8bbfc0a
5d8decdab61442139b82bc2d6f18c3af
RX(theta₁₅)
264cfd7e1976454a9876f64bb8bbfc0a--5d8decdab61442139b82bc2d6f18c3af
dac54231f4184f4db137f3ab5b58d3f2
RY(theta₁₉)
5d8decdab61442139b82bc2d6f18c3af--dac54231f4184f4db137f3ab5b58d3f2
cb9d95e7dc284abbad2ad5a85545d6a4
RX(theta₂₃)
dac54231f4184f4db137f3ab5b58d3f2--cb9d95e7dc284abbad2ad5a85545d6a4
a47a880096db471aaa8228da2a0c00b5
X
cb9d95e7dc284abbad2ad5a85545d6a4--a47a880096db471aaa8228da2a0c00b5
a47a880096db471aaa8228da2a0c00b5--511e40a453e5468a94c89265d2988476
28653e3c03894e8881f98ec67d8202c6
a47a880096db471aaa8228da2a0c00b5--28653e3c03894e8881f98ec67d8202c6
28653e3c03894e8881f98ec67d8202c6--61cda1e85797439d9f1c487be0c702ad
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_e5d0c6a6499849f7b4349479fcf89ba9
HEA
cluster_0c1e8334036e4daea2673fb2c88ce617
HEA
3561f776bd6f4eb8884d584c53cce5b9
0
39f48360d57443bb8fbea4b28f12abea
RX(theta₀)
3561f776bd6f4eb8884d584c53cce5b9--39f48360d57443bb8fbea4b28f12abea
39a22eb8f3644d70bca5d09b400f85c4
1
b527c60d18c44dedae4c643c1e7c04e7
RY(theta₄)
39f48360d57443bb8fbea4b28f12abea--b527c60d18c44dedae4c643c1e7c04e7
39a94c4d3f8e4ff29a0f2ab804709c22
RX(theta₈)
b527c60d18c44dedae4c643c1e7c04e7--39a94c4d3f8e4ff29a0f2ab804709c22
d88730ee24014f1188a0ba885c217267
39a94c4d3f8e4ff29a0f2ab804709c22--d88730ee24014f1188a0ba885c217267
bf6534876eb641409248b1dbfceee974
d88730ee24014f1188a0ba885c217267--bf6534876eb641409248b1dbfceee974
9e4c40d33bd5444e864166f2df049be3
RX(theta₁₂)
bf6534876eb641409248b1dbfceee974--9e4c40d33bd5444e864166f2df049be3
5935f32abe6e41d8bc7492b453454e34
RY(theta₁₆)
9e4c40d33bd5444e864166f2df049be3--5935f32abe6e41d8bc7492b453454e34
46c07b9e5d0f47ff8de1140e6839f0d4
RX(theta₂₀)
5935f32abe6e41d8bc7492b453454e34--46c07b9e5d0f47ff8de1140e6839f0d4
d67722f71700412fbc1f5d2860a24b79
46c07b9e5d0f47ff8de1140e6839f0d4--d67722f71700412fbc1f5d2860a24b79
a891b22f324d4183968dccc888711ba9
d67722f71700412fbc1f5d2860a24b79--a891b22f324d4183968dccc888711ba9
49e989d53ba748248cbed5bb2b9e15f8
RX(theta₀)
a891b22f324d4183968dccc888711ba9--49e989d53ba748248cbed5bb2b9e15f8
a9458b7102924c148d064d54f35123b1
RY(theta₄)
49e989d53ba748248cbed5bb2b9e15f8--a9458b7102924c148d064d54f35123b1
c9699150411245a385042ceaefb83012
RX(theta₈)
a9458b7102924c148d064d54f35123b1--c9699150411245a385042ceaefb83012
488a42524640448a9ed320a6f0139a0d
c9699150411245a385042ceaefb83012--488a42524640448a9ed320a6f0139a0d
5da6f7f453db435191d00cd391cf78df
488a42524640448a9ed320a6f0139a0d--5da6f7f453db435191d00cd391cf78df
16ddc8919a374feaa80a5a19392168c4
RX(theta₁₂)
5da6f7f453db435191d00cd391cf78df--16ddc8919a374feaa80a5a19392168c4
0f42680901b54bd283f7c5eec65ca936
RY(theta₁₆)
16ddc8919a374feaa80a5a19392168c4--0f42680901b54bd283f7c5eec65ca936
321449062e794861a8d89f78c43d9bfa
RX(theta₂₀)
0f42680901b54bd283f7c5eec65ca936--321449062e794861a8d89f78c43d9bfa
9d290a1d0e0f4334b0144ac060fa0134
321449062e794861a8d89f78c43d9bfa--9d290a1d0e0f4334b0144ac060fa0134
2b37f0583f384f4ea875a8725afb7486
9d290a1d0e0f4334b0144ac060fa0134--2b37f0583f384f4ea875a8725afb7486
ae888266a2f944e4b44337da56529381
2b37f0583f384f4ea875a8725afb7486--ae888266a2f944e4b44337da56529381
4b6bd85c9c6445b793464bce2ec1b2e5
2a1da42671b5458fa6cafde887782015
RX(theta₁)
39a22eb8f3644d70bca5d09b400f85c4--2a1da42671b5458fa6cafde887782015
0da7d3783e8a4cfaa3ba0368de5d76a9
2
c5b703e3d89e41c68314c5b12caa97d3
RY(theta₅)
2a1da42671b5458fa6cafde887782015--c5b703e3d89e41c68314c5b12caa97d3
6ec806df0c994dd1bd4f3c2ace150670
RX(theta₉)
c5b703e3d89e41c68314c5b12caa97d3--6ec806df0c994dd1bd4f3c2ace150670
297ea4302f1f4885aabe4d112663c6b4
X
6ec806df0c994dd1bd4f3c2ace150670--297ea4302f1f4885aabe4d112663c6b4
297ea4302f1f4885aabe4d112663c6b4--d88730ee24014f1188a0ba885c217267
633a1f454f8a4249bdf9b81df4b20fde
297ea4302f1f4885aabe4d112663c6b4--633a1f454f8a4249bdf9b81df4b20fde
f55234dcdf14420c84d18d94505063d1
RX(theta₁₃)
633a1f454f8a4249bdf9b81df4b20fde--f55234dcdf14420c84d18d94505063d1
9ce97d2feef7486ba7f1d896c1adb906
RY(theta₁₇)
f55234dcdf14420c84d18d94505063d1--9ce97d2feef7486ba7f1d896c1adb906
36a66d68838f42b3aa619e867600302a
RX(theta₂₁)
9ce97d2feef7486ba7f1d896c1adb906--36a66d68838f42b3aa619e867600302a
398aaab951a5451d8d2a3b28145a128d
X
36a66d68838f42b3aa619e867600302a--398aaab951a5451d8d2a3b28145a128d
398aaab951a5451d8d2a3b28145a128d--d67722f71700412fbc1f5d2860a24b79
46dbb7a2eeb749568f905a4f7d5c1f5f
398aaab951a5451d8d2a3b28145a128d--46dbb7a2eeb749568f905a4f7d5c1f5f
9ee9524490b741f4918c5d75896725c5
RX(theta₁)
46dbb7a2eeb749568f905a4f7d5c1f5f--9ee9524490b741f4918c5d75896725c5
8dab129ce8cb4884a86e52a3e7b8c0ce
RY(theta₅)
9ee9524490b741f4918c5d75896725c5--8dab129ce8cb4884a86e52a3e7b8c0ce
a5e49e245b6d43288c6d7ff888849cad
RX(theta₉)
8dab129ce8cb4884a86e52a3e7b8c0ce--a5e49e245b6d43288c6d7ff888849cad
3362333ec0034979a40dd61c73b74824
X
a5e49e245b6d43288c6d7ff888849cad--3362333ec0034979a40dd61c73b74824
3362333ec0034979a40dd61c73b74824--488a42524640448a9ed320a6f0139a0d
6d6f9047c4d24529a7cb0528246788d7
3362333ec0034979a40dd61c73b74824--6d6f9047c4d24529a7cb0528246788d7
d7c0bea4e4b64dfab42434ba0f87f866
RX(theta₁₃)
6d6f9047c4d24529a7cb0528246788d7--d7c0bea4e4b64dfab42434ba0f87f866
7f33a5951af14f07ad93ecdede784862
RY(theta₁₇)
d7c0bea4e4b64dfab42434ba0f87f866--7f33a5951af14f07ad93ecdede784862
ba4f595297d243f49a23169e38f81274
RX(theta₂₁)
7f33a5951af14f07ad93ecdede784862--ba4f595297d243f49a23169e38f81274
f9250ce0cde64ba498814c7e4ceb0c60
X
ba4f595297d243f49a23169e38f81274--f9250ce0cde64ba498814c7e4ceb0c60
f9250ce0cde64ba498814c7e4ceb0c60--9d290a1d0e0f4334b0144ac060fa0134
d2dddaba9e554149a0ff8e69c8b248f4
f9250ce0cde64ba498814c7e4ceb0c60--d2dddaba9e554149a0ff8e69c8b248f4
d2dddaba9e554149a0ff8e69c8b248f4--4b6bd85c9c6445b793464bce2ec1b2e5
174adb4b06cb48d599a53179f07eb24d
abed721477d944eabe89633554b2e746
RX(theta₂)
0da7d3783e8a4cfaa3ba0368de5d76a9--abed721477d944eabe89633554b2e746
c3bd6c30370b4ada8ec89a73746145dd
3
0f91a2be225c42fe822b261c30c4bfd1
RY(theta₆)
abed721477d944eabe89633554b2e746--0f91a2be225c42fe822b261c30c4bfd1
e639346593df4fa4bcb495ca7bbda156
RX(theta₁₀)
0f91a2be225c42fe822b261c30c4bfd1--e639346593df4fa4bcb495ca7bbda156
f528fa2ca80b486bb5362f54d08b7086
e639346593df4fa4bcb495ca7bbda156--f528fa2ca80b486bb5362f54d08b7086
668f54cdb87d4984862557ec3ae06c75
X
f528fa2ca80b486bb5362f54d08b7086--668f54cdb87d4984862557ec3ae06c75
668f54cdb87d4984862557ec3ae06c75--633a1f454f8a4249bdf9b81df4b20fde
64230f82f980493db423e5f31635b18e
RX(theta₁₄)
668f54cdb87d4984862557ec3ae06c75--64230f82f980493db423e5f31635b18e
ddec204873ca431cb0a5a5ce6157769c
RY(theta₁₈)
64230f82f980493db423e5f31635b18e--ddec204873ca431cb0a5a5ce6157769c
b45dc99ce2dd4970ae1ef8dab23f138d
RX(theta₂₂)
ddec204873ca431cb0a5a5ce6157769c--b45dc99ce2dd4970ae1ef8dab23f138d
8151e9edd4714b6d906d3d826e7644fc
b45dc99ce2dd4970ae1ef8dab23f138d--8151e9edd4714b6d906d3d826e7644fc
ff7ef9a7b0bc4fd4b9cf3a2a09994beb
X
8151e9edd4714b6d906d3d826e7644fc--ff7ef9a7b0bc4fd4b9cf3a2a09994beb
ff7ef9a7b0bc4fd4b9cf3a2a09994beb--46dbb7a2eeb749568f905a4f7d5c1f5f
534800fab6c64c158a5edd1f1fd43a77
RX(theta₂)
ff7ef9a7b0bc4fd4b9cf3a2a09994beb--534800fab6c64c158a5edd1f1fd43a77
ad3692e58a3f4f9bbcc828e5f880c9f2
RY(theta₆)
534800fab6c64c158a5edd1f1fd43a77--ad3692e58a3f4f9bbcc828e5f880c9f2
8579bff48b0e46c5b27ae83c1c60ca6f
RX(theta₁₀)
ad3692e58a3f4f9bbcc828e5f880c9f2--8579bff48b0e46c5b27ae83c1c60ca6f
53d8c0aa8d6f4fc7a1d08defe9ae928c
8579bff48b0e46c5b27ae83c1c60ca6f--53d8c0aa8d6f4fc7a1d08defe9ae928c
cced927c49a74dab8deadc8b4dd5f01f
X
53d8c0aa8d6f4fc7a1d08defe9ae928c--cced927c49a74dab8deadc8b4dd5f01f
cced927c49a74dab8deadc8b4dd5f01f--6d6f9047c4d24529a7cb0528246788d7
014a19c03b274610a4e8be250ad18f41
RX(theta₁₄)
cced927c49a74dab8deadc8b4dd5f01f--014a19c03b274610a4e8be250ad18f41
a4bed62a63254c1db79b90fd513949fe
RY(theta₁₈)
014a19c03b274610a4e8be250ad18f41--a4bed62a63254c1db79b90fd513949fe
ffb18eedc12f451aa994c34c49687ff1
RX(theta₂₂)
a4bed62a63254c1db79b90fd513949fe--ffb18eedc12f451aa994c34c49687ff1
4a523028930e487abd5ce9f748216778
ffb18eedc12f451aa994c34c49687ff1--4a523028930e487abd5ce9f748216778
4d5116dfbc2e4e04861dbd09165cd53f
X
4a523028930e487abd5ce9f748216778--4d5116dfbc2e4e04861dbd09165cd53f
4d5116dfbc2e4e04861dbd09165cd53f--d2dddaba9e554149a0ff8e69c8b248f4
4d5116dfbc2e4e04861dbd09165cd53f--174adb4b06cb48d599a53179f07eb24d
c0468b0cf9cc4c52bacc4b3c610b706f
495b9d8fac62406e94b493d69978ea91
RX(theta₃)
c3bd6c30370b4ada8ec89a73746145dd--495b9d8fac62406e94b493d69978ea91
aed63933acb049d1ac1a6e46b63cd396
RY(theta₇)
495b9d8fac62406e94b493d69978ea91--aed63933acb049d1ac1a6e46b63cd396
cdf1fba40fce4571a73959de2e66e150
RX(theta₁₁)
aed63933acb049d1ac1a6e46b63cd396--cdf1fba40fce4571a73959de2e66e150
cfbdb4cee4ee4126b591748ce0decadf
X
cdf1fba40fce4571a73959de2e66e150--cfbdb4cee4ee4126b591748ce0decadf
cfbdb4cee4ee4126b591748ce0decadf--f528fa2ca80b486bb5362f54d08b7086
c5406d3cce5d460abd1a9021b3d771ba
cfbdb4cee4ee4126b591748ce0decadf--c5406d3cce5d460abd1a9021b3d771ba
c95603b34f8d4939b592ad1cda6ae227
RX(theta₁₅)
c5406d3cce5d460abd1a9021b3d771ba--c95603b34f8d4939b592ad1cda6ae227
7430a0533e564b7790920a0a1b960823
RY(theta₁₉)
c95603b34f8d4939b592ad1cda6ae227--7430a0533e564b7790920a0a1b960823
98d3519c30e14243b08a5b5e65defd03
RX(theta₂₃)
7430a0533e564b7790920a0a1b960823--98d3519c30e14243b08a5b5e65defd03
34cbd1d7f9844130ba6f218ebca8cbdb
X
98d3519c30e14243b08a5b5e65defd03--34cbd1d7f9844130ba6f218ebca8cbdb
34cbd1d7f9844130ba6f218ebca8cbdb--8151e9edd4714b6d906d3d826e7644fc
21a4d9bde9c241dea73d6eb12e886dd5
34cbd1d7f9844130ba6f218ebca8cbdb--21a4d9bde9c241dea73d6eb12e886dd5
8ba09ed7e01b4f138f5d5c3f26164777
RX(theta₃)
21a4d9bde9c241dea73d6eb12e886dd5--8ba09ed7e01b4f138f5d5c3f26164777
41ea1f76eea34d9d8c0e23cb60bce6a5
RY(theta₇)
8ba09ed7e01b4f138f5d5c3f26164777--41ea1f76eea34d9d8c0e23cb60bce6a5
79d5b30ce00542e9a204d1535cd6d3fc
RX(theta₁₁)
41ea1f76eea34d9d8c0e23cb60bce6a5--79d5b30ce00542e9a204d1535cd6d3fc
d9576e3f72d74f108ad3a7aacafba8fb
X
79d5b30ce00542e9a204d1535cd6d3fc--d9576e3f72d74f108ad3a7aacafba8fb
d9576e3f72d74f108ad3a7aacafba8fb--53d8c0aa8d6f4fc7a1d08defe9ae928c
102e19089fdb42e08843e8a58162e882
d9576e3f72d74f108ad3a7aacafba8fb--102e19089fdb42e08843e8a58162e882
d4aacb32c6eb4b00bd34f2e5b331668d
RX(theta₁₅)
102e19089fdb42e08843e8a58162e882--d4aacb32c6eb4b00bd34f2e5b331668d
c3cd8e2c4b6b4920b53ea1a14b52d6aa
RY(theta₁₉)
d4aacb32c6eb4b00bd34f2e5b331668d--c3cd8e2c4b6b4920b53ea1a14b52d6aa
563ed042fbeb420193d14d8d53c5e56b
RX(theta₂₃)
c3cd8e2c4b6b4920b53ea1a14b52d6aa--563ed042fbeb420193d14d8d53c5e56b
90ef07202054402c9396904142e1971b
X
563ed042fbeb420193d14d8d53c5e56b--90ef07202054402c9396904142e1971b
90ef07202054402c9396904142e1971b--4a523028930e487abd5ce9f748216778
72eba46ecf184db2ab7aac37acadc244
90ef07202054402c9396904142e1971b--72eba46ecf184db2ab7aac37acadc244
72eba46ecf184db2ab7aac37acadc244--c0468b0cf9cc4c52bacc4b3c610b706f
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_62a4354e4b83483b969fcbdee1d928df
HEA
cluster_67e26684e8f948b29d54012b7abfde45
HEA
5d05498ed9a242a39e3921a7cd94f0a8
0
77c61595e1d64a919f04ca593ea61c49
RX(p1₀)
5d05498ed9a242a39e3921a7cd94f0a8--77c61595e1d64a919f04ca593ea61c49
044c147dd1e2415f85dff0eb67e00e24
1
3a5d211065854551a2f75dccfb9bfe52
RY(p1₄)
77c61595e1d64a919f04ca593ea61c49--3a5d211065854551a2f75dccfb9bfe52
8109abd17316473d8acf676a1113b50d
RX(p1₈)
3a5d211065854551a2f75dccfb9bfe52--8109abd17316473d8acf676a1113b50d
f6642da4144844148aa00171cbb6e22e
8109abd17316473d8acf676a1113b50d--f6642da4144844148aa00171cbb6e22e
0c3fbc5fe6ee4b24ad1fb914ea2bfbae
f6642da4144844148aa00171cbb6e22e--0c3fbc5fe6ee4b24ad1fb914ea2bfbae
d0b7ebf037ac4869b7db3e899f967f5d
RX(p1₁₂)
0c3fbc5fe6ee4b24ad1fb914ea2bfbae--d0b7ebf037ac4869b7db3e899f967f5d
f72a3d8da3764ac3a4d4d9220ddfdcbd
RY(p1₁₆)
d0b7ebf037ac4869b7db3e899f967f5d--f72a3d8da3764ac3a4d4d9220ddfdcbd
d23afc8ae8bd499780cb5a0272688c46
RX(p1₂₀)
f72a3d8da3764ac3a4d4d9220ddfdcbd--d23afc8ae8bd499780cb5a0272688c46
eb9b433e7d114bb09ba281e2a6bbdec3
d23afc8ae8bd499780cb5a0272688c46--eb9b433e7d114bb09ba281e2a6bbdec3
2da416d346c940a29370d2c4fc335810
eb9b433e7d114bb09ba281e2a6bbdec3--2da416d346c940a29370d2c4fc335810
abc4e3f634984466b15eade09ed71177
RX(p2₀)
2da416d346c940a29370d2c4fc335810--abc4e3f634984466b15eade09ed71177
77e06e3fc54e463e8eb9e6116108950e
RY(p2₄)
abc4e3f634984466b15eade09ed71177--77e06e3fc54e463e8eb9e6116108950e
e8d3a9f65b7e4fe6b6f23d08f172c968
RX(p2₈)
77e06e3fc54e463e8eb9e6116108950e--e8d3a9f65b7e4fe6b6f23d08f172c968
bed4945825ab4dadbb82ee9e99529db6
e8d3a9f65b7e4fe6b6f23d08f172c968--bed4945825ab4dadbb82ee9e99529db6
1b74657bb2ce4fb1b156dde718106d80
bed4945825ab4dadbb82ee9e99529db6--1b74657bb2ce4fb1b156dde718106d80
e1866064a37a48d4b7bf3cc92a58b883
RX(p2₁₂)
1b74657bb2ce4fb1b156dde718106d80--e1866064a37a48d4b7bf3cc92a58b883
a2cc0734867c480cbd8ccfd7b50cbb66
RY(p2₁₆)
e1866064a37a48d4b7bf3cc92a58b883--a2cc0734867c480cbd8ccfd7b50cbb66
3baba439e87a4df89b67011e3f6133b1
RX(p2₂₀)
a2cc0734867c480cbd8ccfd7b50cbb66--3baba439e87a4df89b67011e3f6133b1
840df656ed324e0f92c4dbb615ab071c
3baba439e87a4df89b67011e3f6133b1--840df656ed324e0f92c4dbb615ab071c
1be135b7929947dfa9bfec98cc6cc022
840df656ed324e0f92c4dbb615ab071c--1be135b7929947dfa9bfec98cc6cc022
7ffe6ce590e543aa8db2697dbd30cfbc
1be135b7929947dfa9bfec98cc6cc022--7ffe6ce590e543aa8db2697dbd30cfbc
d68ddc2f69fd44f0b3bf5a50231bbcff
c9ec4b9744f6473abdeba4f4c7f1a90d
RX(p1₁)
044c147dd1e2415f85dff0eb67e00e24--c9ec4b9744f6473abdeba4f4c7f1a90d
5ea47fd9a4594ec2abe600512345ca6e
2
cafb3bb28179485bae2637eb11fe17ea
RY(p1₅)
c9ec4b9744f6473abdeba4f4c7f1a90d--cafb3bb28179485bae2637eb11fe17ea
df80d44091834de1bc5cfb088b2f4076
RX(p1₉)
cafb3bb28179485bae2637eb11fe17ea--df80d44091834de1bc5cfb088b2f4076
6c5bcaf44cad4cca96ec96dbef6f1b6b
X
df80d44091834de1bc5cfb088b2f4076--6c5bcaf44cad4cca96ec96dbef6f1b6b
6c5bcaf44cad4cca96ec96dbef6f1b6b--f6642da4144844148aa00171cbb6e22e
47b058523fe34a378c0fd2801cc08e2a
6c5bcaf44cad4cca96ec96dbef6f1b6b--47b058523fe34a378c0fd2801cc08e2a
056fbcc2bef84c5f8d5d9e1281fcd4bf
RX(p1₁₃)
47b058523fe34a378c0fd2801cc08e2a--056fbcc2bef84c5f8d5d9e1281fcd4bf
fbb333a6038444848424b3e663b506d6
RY(p1₁₇)
056fbcc2bef84c5f8d5d9e1281fcd4bf--fbb333a6038444848424b3e663b506d6
6c760460969a47098380e95f520fefaa
RX(p1₂₁)
fbb333a6038444848424b3e663b506d6--6c760460969a47098380e95f520fefaa
0b1f06bb723f4df49f53b5a8c927e846
X
6c760460969a47098380e95f520fefaa--0b1f06bb723f4df49f53b5a8c927e846
0b1f06bb723f4df49f53b5a8c927e846--eb9b433e7d114bb09ba281e2a6bbdec3
9ee7c69a11f841a6a2636293ac4773c9
0b1f06bb723f4df49f53b5a8c927e846--9ee7c69a11f841a6a2636293ac4773c9
bc8fa82310f74081baa9369cc8a12b84
RX(p2₁)
9ee7c69a11f841a6a2636293ac4773c9--bc8fa82310f74081baa9369cc8a12b84
cafe32e9fa77492baabe3b94927c763d
RY(p2₅)
bc8fa82310f74081baa9369cc8a12b84--cafe32e9fa77492baabe3b94927c763d
4fcf1ea270d94823b9269b9c6da75cd1
RX(p2₉)
cafe32e9fa77492baabe3b94927c763d--4fcf1ea270d94823b9269b9c6da75cd1
71cc522dba4c495181b897c0bfffbdf1
X
4fcf1ea270d94823b9269b9c6da75cd1--71cc522dba4c495181b897c0bfffbdf1
71cc522dba4c495181b897c0bfffbdf1--bed4945825ab4dadbb82ee9e99529db6
b981ba9b27f74bc2b2f6359e29838459
71cc522dba4c495181b897c0bfffbdf1--b981ba9b27f74bc2b2f6359e29838459
231b938b515a46da8fdc0697c8b9bee9
RX(p2₁₃)
b981ba9b27f74bc2b2f6359e29838459--231b938b515a46da8fdc0697c8b9bee9
e1782b62745c458db7eb51734c338fc5
RY(p2₁₇)
231b938b515a46da8fdc0697c8b9bee9--e1782b62745c458db7eb51734c338fc5
bc6c48c471fa40289a530e9a1d67ec1d
RX(p2₂₁)
e1782b62745c458db7eb51734c338fc5--bc6c48c471fa40289a530e9a1d67ec1d
cf0f188558c84f10bba8ded4c860dc15
X
bc6c48c471fa40289a530e9a1d67ec1d--cf0f188558c84f10bba8ded4c860dc15
cf0f188558c84f10bba8ded4c860dc15--840df656ed324e0f92c4dbb615ab071c
9b0b4ec933bb4f96ad2da2974ed6b8ac
cf0f188558c84f10bba8ded4c860dc15--9b0b4ec933bb4f96ad2da2974ed6b8ac
9b0b4ec933bb4f96ad2da2974ed6b8ac--d68ddc2f69fd44f0b3bf5a50231bbcff
d7aa56d432984886905d4e755db6f645
e7f30a2261bc4711b3d29bfabb715483
RX(p1₂)
5ea47fd9a4594ec2abe600512345ca6e--e7f30a2261bc4711b3d29bfabb715483
8633386cae864eddb60c14b5f0d8f5e6
3
1ad1b4b349f04e2a9b5fa929b9cdbc5f
RY(p1₆)
e7f30a2261bc4711b3d29bfabb715483--1ad1b4b349f04e2a9b5fa929b9cdbc5f
50a2c0f811564c06b016329abb4197fd
RX(p1₁₀)
1ad1b4b349f04e2a9b5fa929b9cdbc5f--50a2c0f811564c06b016329abb4197fd
eac523b38432441d8d49ec56430e3aff
50a2c0f811564c06b016329abb4197fd--eac523b38432441d8d49ec56430e3aff
6ef01419bccd495095131c3c7fee0eb5
X
eac523b38432441d8d49ec56430e3aff--6ef01419bccd495095131c3c7fee0eb5
6ef01419bccd495095131c3c7fee0eb5--47b058523fe34a378c0fd2801cc08e2a
9083ef9b80114d39b587793b60311c42
RX(p1₁₄)
6ef01419bccd495095131c3c7fee0eb5--9083ef9b80114d39b587793b60311c42
25d04d4c937d45159e9103878e283e85
RY(p1₁₈)
9083ef9b80114d39b587793b60311c42--25d04d4c937d45159e9103878e283e85
9001d81c66dc4d439edab794274d0d99
RX(p1₂₂)
25d04d4c937d45159e9103878e283e85--9001d81c66dc4d439edab794274d0d99
7591ba890f2a4e32a9e3b6f264767414
9001d81c66dc4d439edab794274d0d99--7591ba890f2a4e32a9e3b6f264767414
794092e631ad411f983b2ab82e5ca165
X
7591ba890f2a4e32a9e3b6f264767414--794092e631ad411f983b2ab82e5ca165
794092e631ad411f983b2ab82e5ca165--9ee7c69a11f841a6a2636293ac4773c9
b72de6e6ef8a4ee4b8dfaa2008854984
RX(p2₂)
794092e631ad411f983b2ab82e5ca165--b72de6e6ef8a4ee4b8dfaa2008854984
ba9af9b0c24b4cdcbbc89fb6dd5cb2cf
RY(p2₆)
b72de6e6ef8a4ee4b8dfaa2008854984--ba9af9b0c24b4cdcbbc89fb6dd5cb2cf
428ba933dcdc47bcb48ea8120ba233b5
RX(p2₁₀)
ba9af9b0c24b4cdcbbc89fb6dd5cb2cf--428ba933dcdc47bcb48ea8120ba233b5
ee755d05a565412780935a996fc125e0
428ba933dcdc47bcb48ea8120ba233b5--ee755d05a565412780935a996fc125e0
c9acdc26cc624eed9cf4631a56f73e49
X
ee755d05a565412780935a996fc125e0--c9acdc26cc624eed9cf4631a56f73e49
c9acdc26cc624eed9cf4631a56f73e49--b981ba9b27f74bc2b2f6359e29838459
b59cf90fb02e4a9490874ca12c4e6ae4
RX(p2₁₄)
c9acdc26cc624eed9cf4631a56f73e49--b59cf90fb02e4a9490874ca12c4e6ae4
058ba0c568e2477daa4df12a2c875286
RY(p2₁₈)
b59cf90fb02e4a9490874ca12c4e6ae4--058ba0c568e2477daa4df12a2c875286
cdba82e7a1d343c3a50ab9506e1845d5
RX(p2₂₂)
058ba0c568e2477daa4df12a2c875286--cdba82e7a1d343c3a50ab9506e1845d5
8ab53350d0374668ab8f1dfac19f57c6
cdba82e7a1d343c3a50ab9506e1845d5--8ab53350d0374668ab8f1dfac19f57c6
412adaed0e5241dbbcb6bb122fdb0052
X
8ab53350d0374668ab8f1dfac19f57c6--412adaed0e5241dbbcb6bb122fdb0052
412adaed0e5241dbbcb6bb122fdb0052--9b0b4ec933bb4f96ad2da2974ed6b8ac
412adaed0e5241dbbcb6bb122fdb0052--d7aa56d432984886905d4e755db6f645
e9802c12862b430cb48a1cdac4e84194
a8e358ebae2a4e65b313bf2c8859f5fe
RX(p1₃)
8633386cae864eddb60c14b5f0d8f5e6--a8e358ebae2a4e65b313bf2c8859f5fe
643f40d713784e10827225dfc5843210
RY(p1₇)
a8e358ebae2a4e65b313bf2c8859f5fe--643f40d713784e10827225dfc5843210
0de1c02c204342a2849e7f5e84a9bbeb
RX(p1₁₁)
643f40d713784e10827225dfc5843210--0de1c02c204342a2849e7f5e84a9bbeb
37ce1a5e4f274900a679edbffad29ff7
X
0de1c02c204342a2849e7f5e84a9bbeb--37ce1a5e4f274900a679edbffad29ff7
37ce1a5e4f274900a679edbffad29ff7--eac523b38432441d8d49ec56430e3aff
2fb950a73f8d4db18befc34233893523
37ce1a5e4f274900a679edbffad29ff7--2fb950a73f8d4db18befc34233893523
19890fc8b1d84db98b3f493955a5292f
RX(p1₁₅)
2fb950a73f8d4db18befc34233893523--19890fc8b1d84db98b3f493955a5292f
61ece389cc144e2099d426feb0a70bd2
RY(p1₁₉)
19890fc8b1d84db98b3f493955a5292f--61ece389cc144e2099d426feb0a70bd2
deb23b40437b4a48b6a06d77448a15cd
RX(p1₂₃)
61ece389cc144e2099d426feb0a70bd2--deb23b40437b4a48b6a06d77448a15cd
f2858db6d94c4ff5b684c94bc43d2b24
X
deb23b40437b4a48b6a06d77448a15cd--f2858db6d94c4ff5b684c94bc43d2b24
f2858db6d94c4ff5b684c94bc43d2b24--7591ba890f2a4e32a9e3b6f264767414
87dfa2a616a241c9a03e4807b989e8be
f2858db6d94c4ff5b684c94bc43d2b24--87dfa2a616a241c9a03e4807b989e8be
feb7afaaba2f45a68ca1e5fe06a1354c
RX(p2₃)
87dfa2a616a241c9a03e4807b989e8be--feb7afaaba2f45a68ca1e5fe06a1354c
3816b589a65c4a8e98ed1cb4700ed4a9
RY(p2₇)
feb7afaaba2f45a68ca1e5fe06a1354c--3816b589a65c4a8e98ed1cb4700ed4a9
3109356b965e45ba9d5a6b57f9085564
RX(p2₁₁)
3816b589a65c4a8e98ed1cb4700ed4a9--3109356b965e45ba9d5a6b57f9085564
0f2d5eb8f8c341308011ae7aa61ac732
X
3109356b965e45ba9d5a6b57f9085564--0f2d5eb8f8c341308011ae7aa61ac732
0f2d5eb8f8c341308011ae7aa61ac732--ee755d05a565412780935a996fc125e0
39b4494222894236a5b3b481974af3ec
0f2d5eb8f8c341308011ae7aa61ac732--39b4494222894236a5b3b481974af3ec
55ce6e1b302d4bc7bb3861601cc9156a
RX(p2₁₅)
39b4494222894236a5b3b481974af3ec--55ce6e1b302d4bc7bb3861601cc9156a
89b6e90db86540adab5d2af89e3f814b
RY(p2₁₉)
55ce6e1b302d4bc7bb3861601cc9156a--89b6e90db86540adab5d2af89e3f814b
468017a2a94449e19e9daae6c85b4dd4
RX(p2₂₃)
89b6e90db86540adab5d2af89e3f814b--468017a2a94449e19e9daae6c85b4dd4
343c129d83f34dd69f92c81ad214f60f
X
468017a2a94449e19e9daae6c85b4dd4--343c129d83f34dd69f92c81ad214f60f
343c129d83f34dd69f92c81ad214f60f--8ab53350d0374668ab8f1dfac19f57c6
7cd4a9bbe36642b4903ad7a57e4b0001
343c129d83f34dd69f92c81ad214f60f--7cd4a9bbe36642b4903ad7a57e4b0001
7cd4a9bbe36642b4903ad7a57e4b0001--e9802c12862b430cb48a1cdac4e84194
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.6215 ] )) , (' t he ta _ 0 ' , tens or( [ 0.2697 ] )) , (' t he ta _ 1 ' , tens or( [ 0.6950 ] )) , (' t he ta _ 10 ' , tens or( [ 0.3464 ] )) , (' t he ta _ 11 ' , tens or( [ 0.9241 ] )) , (' t he ta _ 12 ' , tens or( [ 0.7898 ] )) , (' t he ta _ 13 ' , tens or( [ 0.9776 ] )) , (' t he ta _ 14 ' , tens or( [ 0.7308 ] )) , (' t he ta _ 15 ' , tens or( [ 0.7334 ] )) , (' t he ta _ 16 ' , tens or( [ 0.7720 ] )) , (' t he ta _ 17 ' , tens or( [ 0.0300 ] )) , (' t he ta _ 18 ' , tens or( [ 0.1428 ] )) , (' t he ta _ 19 ' , tens or( [ 0.2618 ] )) , (' t he ta _ 2 ' , tens or( [ 0.9746 ] )) , (' t he ta _ 20 ' , tens or( [ 0.4202 ] )) , (' t he ta _ 21 ' , tens or( [ 0.7802 ] )) , (' t he ta _ 22 ' , tens or( [ 0.2414 ] )) , (' t he ta _ 23 ' , tens or( [ 0.8382 ] )) , (' t he ta _ 3 ' , tens or( [ 0.5333 ] )) , (' t he ta _ 4 ' , tens or( [ 0.6383 ] )) , (' t he ta _ 5 ' , tens or( [ 0.0999 ] )) , (' t he ta _ 6 ' , tens or( [ 0.3065 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3257 ] )) , (' t he ta _ 8 ' , tens or( [ 0.7024 ] )) , (' t he ta _ 9 ' , tens or( [ 0.8767 ] )) ] )
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.6205 ] )) , (' t he ta _ 0 ' , tens or( [ 0.2707 ] )) , (' t he ta _ 1 ' , tens or( [ 0.6940 ] )) , (' t he ta _ 10 ' , tens or( [ 0.3474 ] )) , (' t he ta _ 11 ' , tens or( [ 0.9251 ] )) , (' t he ta _ 12 ' , tens or( [ 0.7908 ] )) , (' t he ta _ 13 ' , tens or( [ 0.9786 ] )) , (' t he ta _ 14 ' , tens or( [ 0.7318 ] )) , (' t he ta _ 15 ' , tens or( [ 0.7344 ] )) , (' t he ta _ 16 ' , tens or( [ 0.7730 ] )) , (' t he ta _ 17 ' , tens or( [ 0.0310 ] )) , (' t he ta _ 18 ' , tens or( [ 0.1418 ] )) , (' t he ta _ 19 ' , tens or( [ 0.2628 ] )) , (' t he ta _ 2 ' , tens or( [ 0.9756 ] )) , (' t he ta _ 20 ' , tens or( [ 0.4212 ] )) , (' t he ta _ 21 ' , tens or( [ 0.7812 ] )) , (' t he ta _ 22 ' , tens or( [ 0.2424 ] )) , (' t he ta _ 23 ' , tens or( [ 0.8392 ] )) , (' t he ta _ 3 ' , tens or( [ 0.5343 ] )) , (' t he ta _ 4 ' , tens or( [ 0.6373 ] )) , (' t he ta _ 5 ' , tens or( [ 0.1009 ] )) , (' t he ta _ 6 ' , tens or( [ 0.3075 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3247 ] )) , (' t he ta _ 8 ' , tens or( [ 0.7034 ] )) , (' t he ta _ 9 ' , tens or( [ 0.8757 ] )) ] )
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 ]] )