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 torch import pi
from qadence import RX , run
# 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.9754+0.0000 j , 0.0000-0.2203 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.9058+0.0000 j , 0.0000-0.4237 j ],
[ 0.9047+0.0000 j , 0.0000-0.4260 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.5444+0.0000 j , 0.8070+0.0000 j , 0.0000-0.1279 j , 0.0000-0.1896 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_1878b17140774df69963839f70afbcbb
[* 2]
cluster_72f95b9eb79c4ca6a832ca2d28719c82
Rotations
2f7b96f2847a44cda5bbd084774a58ff
0
4636664afce04e4eb1a00ecbf296aaa2
RX(phi/theta)
2f7b96f2847a44cda5bbd084774a58ff--4636664afce04e4eb1a00ecbf296aaa2
17016e39bff449b695f08cbe37791eb6
1
319e7a5f08824e6aae31ff80221cfaa4
RX(phi)
4636664afce04e4eb1a00ecbf296aaa2--319e7a5f08824e6aae31ff80221cfaa4
f301b43583b7461eb3b5d6b06d304128
RX(phi)
319e7a5f08824e6aae31ff80221cfaa4--f301b43583b7461eb3b5d6b06d304128
45c9eeffdf554279962d7a0868c91de3
RX(phi + theta)
f301b43583b7461eb3b5d6b06d304128--45c9eeffdf554279962d7a0868c91de3
9a3bd2a2e1db41cf8fa189cefddb4ac8
45c9eeffdf554279962d7a0868c91de3--9a3bd2a2e1db41cf8fa189cefddb4ac8
00602ad6d692488aa0750952e77b0e0c
9a3bd2a2e1db41cf8fa189cefddb4ac8--00602ad6d692488aa0750952e77b0e0c
28406704f63d4265be66e32815be0dbf
Z
00602ad6d692488aa0750952e77b0e0c--28406704f63d4265be66e32815be0dbf
1f9da4f681eb48eeb7d2cbb613d9e6ed
28406704f63d4265be66e32815be0dbf--1f9da4f681eb48eeb7d2cbb613d9e6ed
b2346decb3b543029932a52b4a3120b9
e190c6715197452c94e9158ab7080a05
RY(2*theta)
17016e39bff449b695f08cbe37791eb6--e190c6715197452c94e9158ab7080a05
610ac34af9fa46c2b366f5a345ef4a7b
2
293077c9abaa46d38021757ce1b29290
RY(theta)
e190c6715197452c94e9158ab7080a05--293077c9abaa46d38021757ce1b29290
6dfef1dce4354d0d956c69c627a4fb52
RY(theta)
293077c9abaa46d38021757ce1b29290--6dfef1dce4354d0d956c69c627a4fb52
aeaeb724b3f745a19ab1a920671dc436
RY(theta**2)
6dfef1dce4354d0d956c69c627a4fb52--aeaeb724b3f745a19ab1a920671dc436
eaff4e8f4d7a4e48b5c01bb5656f1861
X
aeaeb724b3f745a19ab1a920671dc436--eaff4e8f4d7a4e48b5c01bb5656f1861
eaff4e8f4d7a4e48b5c01bb5656f1861--9a3bd2a2e1db41cf8fa189cefddb4ac8
3bdfd4dbd3074a9db5521668895a51ed
eaff4e8f4d7a4e48b5c01bb5656f1861--3bdfd4dbd3074a9db5521668895a51ed
0f0bab4d300f4237b5abc21a95744f55
Z
3bdfd4dbd3074a9db5521668895a51ed--0f0bab4d300f4237b5abc21a95744f55
0f0bab4d300f4237b5abc21a95744f55--b2346decb3b543029932a52b4a3120b9
2c135d0b97794d6999d30c383c3e42bb
6813f2a97230492ba661277924e51641
RZ(cos(phi))
610ac34af9fa46c2b366f5a345ef4a7b--6813f2a97230492ba661277924e51641
68580746152f4d1495b5de995b9f378f
RZ(phi)
6813f2a97230492ba661277924e51641--68580746152f4d1495b5de995b9f378f
761f87b4564b464084bc906430c3fe82
RZ(phi)
68580746152f4d1495b5de995b9f378f--761f87b4564b464084bc906430c3fe82
b59291ccff3444949e1b69e10d255aec
RZ(cos(phi))
761f87b4564b464084bc906430c3fe82--b59291ccff3444949e1b69e10d255aec
2e37c356d37848eca1078dcfcfc897c1
b59291ccff3444949e1b69e10d255aec--2e37c356d37848eca1078dcfcfc897c1
c3696d7c3d0e49e4aebf9021b34c0b6f
X
2e37c356d37848eca1078dcfcfc897c1--c3696d7c3d0e49e4aebf9021b34c0b6f
c3696d7c3d0e49e4aebf9021b34c0b6f--3bdfd4dbd3074a9db5521668895a51ed
80eb7615825441ff882e0021c12702c4
Z
c3696d7c3d0e49e4aebf9021b34c0b6f--80eb7615825441ff882e0021c12702c4
80eb7615825441ff882e0021c12702c4--2c135d0b97794d6999d30c383c3e42bb
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.3193 ] )) ] )
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.9192+0.0000 j , 0.2725+0.0000 j , 0.0000-0.2725 j , 0.0000-0.0808 j ],
[ 0.7623+0.0000 j , 0.4257+0.0000 j , 0.0000-0.4257 j , 0.0000-0.2377 j ],
[ 0.7010+0.0000 j , 0.4578+0.0000 j , 0.0000-0.4578 j , 0.0000-0.2990 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
119481c1227047c7ae105c6987d60979
0
5888d5a129c5480fa36f26ccfb6991c8
RX(theta₀)
119481c1227047c7ae105c6987d60979--5888d5a129c5480fa36f26ccfb6991c8
2ddbcfd7a3854deb91ddde37a8113064
1
4fd0b7f9b62c464abb6ae15a457296ff
RY(theta₄)
5888d5a129c5480fa36f26ccfb6991c8--4fd0b7f9b62c464abb6ae15a457296ff
1c32de07faf44c4f9ab4b2ae61091f5f
RX(theta₈)
4fd0b7f9b62c464abb6ae15a457296ff--1c32de07faf44c4f9ab4b2ae61091f5f
e60414fc644a4b47b56ad4286e546c1e
1c32de07faf44c4f9ab4b2ae61091f5f--e60414fc644a4b47b56ad4286e546c1e
d9ea428adc2d48ef9145f00cae2293f4
e60414fc644a4b47b56ad4286e546c1e--d9ea428adc2d48ef9145f00cae2293f4
d3afd98ae24242e39e999eeefe866bf7
RX(theta₁₂)
d9ea428adc2d48ef9145f00cae2293f4--d3afd98ae24242e39e999eeefe866bf7
bd01f6f7bb2b4566ad3f56810749856c
RY(theta₁₆)
d3afd98ae24242e39e999eeefe866bf7--bd01f6f7bb2b4566ad3f56810749856c
bd20cba0e5324900b003a1db4bda27b2
RX(theta₂₀)
bd01f6f7bb2b4566ad3f56810749856c--bd20cba0e5324900b003a1db4bda27b2
c06780699efd4c96a5ec0216fd6e9247
bd20cba0e5324900b003a1db4bda27b2--c06780699efd4c96a5ec0216fd6e9247
3837313ae66f4170a412902173dd7d1c
c06780699efd4c96a5ec0216fd6e9247--3837313ae66f4170a412902173dd7d1c
98603f2e03e14f969a4724be62c6dd16
3837313ae66f4170a412902173dd7d1c--98603f2e03e14f969a4724be62c6dd16
1a6de37a1fa3433bb6a5bc14c0478add
8a273d0cf657439093564bae5b121070
RX(theta₁)
2ddbcfd7a3854deb91ddde37a8113064--8a273d0cf657439093564bae5b121070
f98898231a77496e8dd73e5aeab060a3
2
a57f08d838ca4f8db70b205cf5cf6d2b
RY(theta₅)
8a273d0cf657439093564bae5b121070--a57f08d838ca4f8db70b205cf5cf6d2b
77cff9713994473293eba8f4d9316f2f
RX(theta₉)
a57f08d838ca4f8db70b205cf5cf6d2b--77cff9713994473293eba8f4d9316f2f
fe8c2c22afc94d54bac01311eaafa015
X
77cff9713994473293eba8f4d9316f2f--fe8c2c22afc94d54bac01311eaafa015
fe8c2c22afc94d54bac01311eaafa015--e60414fc644a4b47b56ad4286e546c1e
66b738b268974190881fd82e037b1100
fe8c2c22afc94d54bac01311eaafa015--66b738b268974190881fd82e037b1100
cf61bbfe1d7f4209906a783ae3cf2a30
RX(theta₁₃)
66b738b268974190881fd82e037b1100--cf61bbfe1d7f4209906a783ae3cf2a30
e9bbc57d80bf419c81af51a39b6165b0
RY(theta₁₇)
cf61bbfe1d7f4209906a783ae3cf2a30--e9bbc57d80bf419c81af51a39b6165b0
11aaba8b0d9549c085903170005aeb2a
RX(theta₂₁)
e9bbc57d80bf419c81af51a39b6165b0--11aaba8b0d9549c085903170005aeb2a
b32fe347645b4bbc9e7c61bb09a54163
X
11aaba8b0d9549c085903170005aeb2a--b32fe347645b4bbc9e7c61bb09a54163
b32fe347645b4bbc9e7c61bb09a54163--c06780699efd4c96a5ec0216fd6e9247
e91b731abde645a1b9620d1d727129b2
b32fe347645b4bbc9e7c61bb09a54163--e91b731abde645a1b9620d1d727129b2
e91b731abde645a1b9620d1d727129b2--1a6de37a1fa3433bb6a5bc14c0478add
a2e6958ad8f0435ea26bf9c2888d05bd
1a0ba21334de41dd8936a044413f19d9
RX(theta₂)
f98898231a77496e8dd73e5aeab060a3--1a0ba21334de41dd8936a044413f19d9
21dd2a701a314302b976ce47f9846947
3
89c366096013476fa19fa2209c078291
RY(theta₆)
1a0ba21334de41dd8936a044413f19d9--89c366096013476fa19fa2209c078291
72ed189305bf4334a168baa78043cb28
RX(theta₁₀)
89c366096013476fa19fa2209c078291--72ed189305bf4334a168baa78043cb28
9cca6bee9d2446fc923ad2acc1ce8e9f
72ed189305bf4334a168baa78043cb28--9cca6bee9d2446fc923ad2acc1ce8e9f
006b6bcf7d33453c99e4c5258672dcb0
X
9cca6bee9d2446fc923ad2acc1ce8e9f--006b6bcf7d33453c99e4c5258672dcb0
006b6bcf7d33453c99e4c5258672dcb0--66b738b268974190881fd82e037b1100
ec372181c7684ba3a55cbd7f665e17f7
RX(theta₁₄)
006b6bcf7d33453c99e4c5258672dcb0--ec372181c7684ba3a55cbd7f665e17f7
fa7d5c143417453599364469c2ff45b8
RY(theta₁₈)
ec372181c7684ba3a55cbd7f665e17f7--fa7d5c143417453599364469c2ff45b8
2bb3b2f076e843aba9816b0b0fb012e8
RX(theta₂₂)
fa7d5c143417453599364469c2ff45b8--2bb3b2f076e843aba9816b0b0fb012e8
c96ecf461b9149b3b31c0bb9c39855a0
2bb3b2f076e843aba9816b0b0fb012e8--c96ecf461b9149b3b31c0bb9c39855a0
a47fb27240cc41929b7e3e9971269fae
X
c96ecf461b9149b3b31c0bb9c39855a0--a47fb27240cc41929b7e3e9971269fae
a47fb27240cc41929b7e3e9971269fae--e91b731abde645a1b9620d1d727129b2
a47fb27240cc41929b7e3e9971269fae--a2e6958ad8f0435ea26bf9c2888d05bd
1fe7d0dc2984481facc5a6c66977d1c1
1f07f57dc71c4016abb0e694da3a650d
RX(theta₃)
21dd2a701a314302b976ce47f9846947--1f07f57dc71c4016abb0e694da3a650d
db15590b5ea54ebf826d102e5ac71b33
RY(theta₇)
1f07f57dc71c4016abb0e694da3a650d--db15590b5ea54ebf826d102e5ac71b33
4a25b11da6304711966ba834f7aa08a7
RX(theta₁₁)
db15590b5ea54ebf826d102e5ac71b33--4a25b11da6304711966ba834f7aa08a7
a590cc93288443279fa4d7d67deb8a05
X
4a25b11da6304711966ba834f7aa08a7--a590cc93288443279fa4d7d67deb8a05
a590cc93288443279fa4d7d67deb8a05--9cca6bee9d2446fc923ad2acc1ce8e9f
09b6b6dc080f467998167b3df46aead0
a590cc93288443279fa4d7d67deb8a05--09b6b6dc080f467998167b3df46aead0
6d65b2e027c74d5284cc6e38f8ad69ad
RX(theta₁₅)
09b6b6dc080f467998167b3df46aead0--6d65b2e027c74d5284cc6e38f8ad69ad
73171b4bd7c34229a82cbfe2515ee750
RY(theta₁₉)
6d65b2e027c74d5284cc6e38f8ad69ad--73171b4bd7c34229a82cbfe2515ee750
f526c89a26d7451bbeb30ffe92dcd068
RX(theta₂₃)
73171b4bd7c34229a82cbfe2515ee750--f526c89a26d7451bbeb30ffe92dcd068
57feeeb6d73f430caaa3678bce8853b2
X
f526c89a26d7451bbeb30ffe92dcd068--57feeeb6d73f430caaa3678bce8853b2
57feeeb6d73f430caaa3678bce8853b2--c96ecf461b9149b3b31c0bb9c39855a0
5b18cff3ad6144158be978d1b9f9fff1
57feeeb6d73f430caaa3678bce8853b2--5b18cff3ad6144158be978d1b9f9fff1
5b18cff3ad6144158be978d1b9f9fff1--1fe7d0dc2984481facc5a6c66977d1c1
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_3ec20ca48f8544b386be0f09460f261b
HEA
cluster_b7f92c08130745a99a62a5af71a6f85b
HEA
f3eae8d85f99446bbaeb4b1f790265cd
0
f9fd531827ae415596cd3d3825b16a27
RX(theta₀)
f3eae8d85f99446bbaeb4b1f790265cd--f9fd531827ae415596cd3d3825b16a27
fd6fd3f9c69646d881c094344482ed0f
1
aafc3540ce0d43b291afaedf95f3fbe2
RY(theta₄)
f9fd531827ae415596cd3d3825b16a27--aafc3540ce0d43b291afaedf95f3fbe2
aaca4ca4daca47fe82b1a4e8f2b3e6f9
RX(theta₈)
aafc3540ce0d43b291afaedf95f3fbe2--aaca4ca4daca47fe82b1a4e8f2b3e6f9
6ce5ff6925dd472a8cce10d017faa77f
aaca4ca4daca47fe82b1a4e8f2b3e6f9--6ce5ff6925dd472a8cce10d017faa77f
451b3ab439e44c339d19829623ed7831
6ce5ff6925dd472a8cce10d017faa77f--451b3ab439e44c339d19829623ed7831
1f29c9374d26489da4bdada5b335b50c
RX(theta₁₂)
451b3ab439e44c339d19829623ed7831--1f29c9374d26489da4bdada5b335b50c
d7f1e77ef04e465a9b7193c652bc9e2e
RY(theta₁₆)
1f29c9374d26489da4bdada5b335b50c--d7f1e77ef04e465a9b7193c652bc9e2e
4fbbd822d26641d3a6c0643b1322d16c
RX(theta₂₀)
d7f1e77ef04e465a9b7193c652bc9e2e--4fbbd822d26641d3a6c0643b1322d16c
4beb31862ccb4d9a835a59525bfc213a
4fbbd822d26641d3a6c0643b1322d16c--4beb31862ccb4d9a835a59525bfc213a
f8135534532b4113af466a40bdff67ff
4beb31862ccb4d9a835a59525bfc213a--f8135534532b4113af466a40bdff67ff
22e48831191e4013a68dbd96e026791a
RX(theta₀)
f8135534532b4113af466a40bdff67ff--22e48831191e4013a68dbd96e026791a
f4dbc8cb613544559bdd375f018bcbd0
RY(theta₄)
22e48831191e4013a68dbd96e026791a--f4dbc8cb613544559bdd375f018bcbd0
91e2938b4d3b4c7c97682351666bdc6a
RX(theta₈)
f4dbc8cb613544559bdd375f018bcbd0--91e2938b4d3b4c7c97682351666bdc6a
5be1c851459945fb85be1cea122d23b1
91e2938b4d3b4c7c97682351666bdc6a--5be1c851459945fb85be1cea122d23b1
26f9675260df41a380ea829d188423b1
5be1c851459945fb85be1cea122d23b1--26f9675260df41a380ea829d188423b1
d14c4f79be964857a6a2adf2a9b57697
RX(theta₁₂)
26f9675260df41a380ea829d188423b1--d14c4f79be964857a6a2adf2a9b57697
9acf75ab196546a6925e69bb37deba2b
RY(theta₁₆)
d14c4f79be964857a6a2adf2a9b57697--9acf75ab196546a6925e69bb37deba2b
e7f32dc950354fdca46fe1dd62a08126
RX(theta₂₀)
9acf75ab196546a6925e69bb37deba2b--e7f32dc950354fdca46fe1dd62a08126
13bdde4285a042f9905f53e5ae0639ff
e7f32dc950354fdca46fe1dd62a08126--13bdde4285a042f9905f53e5ae0639ff
3755bb27ebfc4536b213682da20d8f18
13bdde4285a042f9905f53e5ae0639ff--3755bb27ebfc4536b213682da20d8f18
d02fe07ef9744fc3b7839d56cc6e68dd
3755bb27ebfc4536b213682da20d8f18--d02fe07ef9744fc3b7839d56cc6e68dd
48c2747fb51a48bebd64a9d435d698d0
b139f2ac0b15431f9a9ecba90855be1d
RX(theta₁)
fd6fd3f9c69646d881c094344482ed0f--b139f2ac0b15431f9a9ecba90855be1d
bd999002853a433c8a5836cbd0b843d1
2
bf0dbb58d97e42e6a3b893b33fc2a1ad
RY(theta₅)
b139f2ac0b15431f9a9ecba90855be1d--bf0dbb58d97e42e6a3b893b33fc2a1ad
8cd0076d424949b6a353934ff80d194e
RX(theta₉)
bf0dbb58d97e42e6a3b893b33fc2a1ad--8cd0076d424949b6a353934ff80d194e
b5488a1f2e8b48f9834165dfc428e8ab
X
8cd0076d424949b6a353934ff80d194e--b5488a1f2e8b48f9834165dfc428e8ab
b5488a1f2e8b48f9834165dfc428e8ab--6ce5ff6925dd472a8cce10d017faa77f
fbc05a64222f41048e59b0cdc203c7e3
b5488a1f2e8b48f9834165dfc428e8ab--fbc05a64222f41048e59b0cdc203c7e3
575fafd749b24c719d61f8c818f182b5
RX(theta₁₃)
fbc05a64222f41048e59b0cdc203c7e3--575fafd749b24c719d61f8c818f182b5
a271f1f64e024979b78a00918c6f2220
RY(theta₁₇)
575fafd749b24c719d61f8c818f182b5--a271f1f64e024979b78a00918c6f2220
e6cee60a5c1b47bc9fe9d0d625c1b20e
RX(theta₂₁)
a271f1f64e024979b78a00918c6f2220--e6cee60a5c1b47bc9fe9d0d625c1b20e
3e0e8e2015704acfa0da8f90646f3ed7
X
e6cee60a5c1b47bc9fe9d0d625c1b20e--3e0e8e2015704acfa0da8f90646f3ed7
3e0e8e2015704acfa0da8f90646f3ed7--4beb31862ccb4d9a835a59525bfc213a
3da695effcae4567b62496e2bec18f37
3e0e8e2015704acfa0da8f90646f3ed7--3da695effcae4567b62496e2bec18f37
f00a2972244c4072bf9f5bba6f2c18b9
RX(theta₁)
3da695effcae4567b62496e2bec18f37--f00a2972244c4072bf9f5bba6f2c18b9
5e8be17466e74a52b167c311f73a0271
RY(theta₅)
f00a2972244c4072bf9f5bba6f2c18b9--5e8be17466e74a52b167c311f73a0271
f1cab22b9b6f409b9b7015f95833f9d9
RX(theta₉)
5e8be17466e74a52b167c311f73a0271--f1cab22b9b6f409b9b7015f95833f9d9
2434127c5c69427e86f8fe7610754bb0
X
f1cab22b9b6f409b9b7015f95833f9d9--2434127c5c69427e86f8fe7610754bb0
2434127c5c69427e86f8fe7610754bb0--5be1c851459945fb85be1cea122d23b1
a2bae53785f44264a1c5fbb4c5c59594
2434127c5c69427e86f8fe7610754bb0--a2bae53785f44264a1c5fbb4c5c59594
aada61551c0243828d97f3af4cc90f39
RX(theta₁₃)
a2bae53785f44264a1c5fbb4c5c59594--aada61551c0243828d97f3af4cc90f39
3752a0ad1d8b41e88726afb84deec029
RY(theta₁₇)
aada61551c0243828d97f3af4cc90f39--3752a0ad1d8b41e88726afb84deec029
a71fcde43bb24527a3ee53a63c03cc57
RX(theta₂₁)
3752a0ad1d8b41e88726afb84deec029--a71fcde43bb24527a3ee53a63c03cc57
00aef2cf112446f9a73d16a9c0e59d6e
X
a71fcde43bb24527a3ee53a63c03cc57--00aef2cf112446f9a73d16a9c0e59d6e
00aef2cf112446f9a73d16a9c0e59d6e--13bdde4285a042f9905f53e5ae0639ff
8f160c9b50a54918a1cc6ca216cd923c
00aef2cf112446f9a73d16a9c0e59d6e--8f160c9b50a54918a1cc6ca216cd923c
8f160c9b50a54918a1cc6ca216cd923c--48c2747fb51a48bebd64a9d435d698d0
5c67d16b82104952b2eefb2d6e07d344
54aca9725f234d6dabc3ee4bae04ce59
RX(theta₂)
bd999002853a433c8a5836cbd0b843d1--54aca9725f234d6dabc3ee4bae04ce59
6fd4a6ee395441da8df2e95dafbb2035
3
6f8ee89702c54c0b921e97221677a3ff
RY(theta₆)
54aca9725f234d6dabc3ee4bae04ce59--6f8ee89702c54c0b921e97221677a3ff
d43563e721fb4adba330c6ab0ea233df
RX(theta₁₀)
6f8ee89702c54c0b921e97221677a3ff--d43563e721fb4adba330c6ab0ea233df
c4b585d6a54d469aaba7704460f1542f
d43563e721fb4adba330c6ab0ea233df--c4b585d6a54d469aaba7704460f1542f
44abae0470864922963cb89e948cb078
X
c4b585d6a54d469aaba7704460f1542f--44abae0470864922963cb89e948cb078
44abae0470864922963cb89e948cb078--fbc05a64222f41048e59b0cdc203c7e3
9363c6419eea4252a4006049b2162590
RX(theta₁₄)
44abae0470864922963cb89e948cb078--9363c6419eea4252a4006049b2162590
25123f54fdae41938d9535ffbafb7aa9
RY(theta₁₈)
9363c6419eea4252a4006049b2162590--25123f54fdae41938d9535ffbafb7aa9
16ee3d2974b5461ebf4cfa807d09fb6f
RX(theta₂₂)
25123f54fdae41938d9535ffbafb7aa9--16ee3d2974b5461ebf4cfa807d09fb6f
8d2daa112b714f298c548bac22b4f76f
16ee3d2974b5461ebf4cfa807d09fb6f--8d2daa112b714f298c548bac22b4f76f
cc5c006af26e4c37b02ab556fcff6eeb
X
8d2daa112b714f298c548bac22b4f76f--cc5c006af26e4c37b02ab556fcff6eeb
cc5c006af26e4c37b02ab556fcff6eeb--3da695effcae4567b62496e2bec18f37
b82faba301d34fe298b2bfb744405174
RX(theta₂)
cc5c006af26e4c37b02ab556fcff6eeb--b82faba301d34fe298b2bfb744405174
604fec9da3b1488fa0481afd3fbfd4c4
RY(theta₆)
b82faba301d34fe298b2bfb744405174--604fec9da3b1488fa0481afd3fbfd4c4
7b090c75164041d9b333a96cbec6c2fb
RX(theta₁₀)
604fec9da3b1488fa0481afd3fbfd4c4--7b090c75164041d9b333a96cbec6c2fb
7f547dadcd3d4efd9ef8a46b2baebd4a
7b090c75164041d9b333a96cbec6c2fb--7f547dadcd3d4efd9ef8a46b2baebd4a
884288bed6174940984f9137484573a3
X
7f547dadcd3d4efd9ef8a46b2baebd4a--884288bed6174940984f9137484573a3
884288bed6174940984f9137484573a3--a2bae53785f44264a1c5fbb4c5c59594
75ac2ba8625a4202a014367ed0a89e42
RX(theta₁₄)
884288bed6174940984f9137484573a3--75ac2ba8625a4202a014367ed0a89e42
dbbce75ac7d24c879d18bbc4ae172ab4
RY(theta₁₈)
75ac2ba8625a4202a014367ed0a89e42--dbbce75ac7d24c879d18bbc4ae172ab4
2d71efa8c6164c38916df414220b16af
RX(theta₂₂)
dbbce75ac7d24c879d18bbc4ae172ab4--2d71efa8c6164c38916df414220b16af
919e14f53935462e9ec475c9149bb129
2d71efa8c6164c38916df414220b16af--919e14f53935462e9ec475c9149bb129
8a60c39432b84eb98c8b5485d1f881bb
X
919e14f53935462e9ec475c9149bb129--8a60c39432b84eb98c8b5485d1f881bb
8a60c39432b84eb98c8b5485d1f881bb--8f160c9b50a54918a1cc6ca216cd923c
8a60c39432b84eb98c8b5485d1f881bb--5c67d16b82104952b2eefb2d6e07d344
18987bd187ed4410b35465c1cd8f63b4
4d430131687a4622bb1aeb1ab96fbfe0
RX(theta₃)
6fd4a6ee395441da8df2e95dafbb2035--4d430131687a4622bb1aeb1ab96fbfe0
87fa23d15638469db46f34941d766718
RY(theta₇)
4d430131687a4622bb1aeb1ab96fbfe0--87fa23d15638469db46f34941d766718
b30ab8bc938b4bb787a802cdf96134d1
RX(theta₁₁)
87fa23d15638469db46f34941d766718--b30ab8bc938b4bb787a802cdf96134d1
6e9fff7565624716bc46f34fcaf7607d
X
b30ab8bc938b4bb787a802cdf96134d1--6e9fff7565624716bc46f34fcaf7607d
6e9fff7565624716bc46f34fcaf7607d--c4b585d6a54d469aaba7704460f1542f
c839cb8010184ca09a9ba34179710db7
6e9fff7565624716bc46f34fcaf7607d--c839cb8010184ca09a9ba34179710db7
a9850d6ce48448f089cdf3a2258f8d32
RX(theta₁₅)
c839cb8010184ca09a9ba34179710db7--a9850d6ce48448f089cdf3a2258f8d32
78e2b10868ad4ea4b3a3526b75501afa
RY(theta₁₉)
a9850d6ce48448f089cdf3a2258f8d32--78e2b10868ad4ea4b3a3526b75501afa
ac1b22285903449fbc2e2d0afc740f00
RX(theta₂₃)
78e2b10868ad4ea4b3a3526b75501afa--ac1b22285903449fbc2e2d0afc740f00
5f874b77b2dc4608a57e9810c0a06a32
X
ac1b22285903449fbc2e2d0afc740f00--5f874b77b2dc4608a57e9810c0a06a32
5f874b77b2dc4608a57e9810c0a06a32--8d2daa112b714f298c548bac22b4f76f
5cb16cfecdae444fab52f3ed886e5411
5f874b77b2dc4608a57e9810c0a06a32--5cb16cfecdae444fab52f3ed886e5411
a6f453038fc84c149b71ffdb9769af89
RX(theta₃)
5cb16cfecdae444fab52f3ed886e5411--a6f453038fc84c149b71ffdb9769af89
a13bfc77ff4742aa9951d3ce7769892e
RY(theta₇)
a6f453038fc84c149b71ffdb9769af89--a13bfc77ff4742aa9951d3ce7769892e
cd8313a70b9a41ee9ea3dffca49808a6
RX(theta₁₁)
a13bfc77ff4742aa9951d3ce7769892e--cd8313a70b9a41ee9ea3dffca49808a6
b664969d77f14d4e84db548240d847b7
X
cd8313a70b9a41ee9ea3dffca49808a6--b664969d77f14d4e84db548240d847b7
b664969d77f14d4e84db548240d847b7--7f547dadcd3d4efd9ef8a46b2baebd4a
bf1b4573510243b399bb2a8cb58eb625
b664969d77f14d4e84db548240d847b7--bf1b4573510243b399bb2a8cb58eb625
36630a8fb1ba41ca821177e2c7b77b90
RX(theta₁₅)
bf1b4573510243b399bb2a8cb58eb625--36630a8fb1ba41ca821177e2c7b77b90
a9d9fd59bcad41a490981e64949982cd
RY(theta₁₉)
36630a8fb1ba41ca821177e2c7b77b90--a9d9fd59bcad41a490981e64949982cd
dc830c2050c04a3a9b4d72a6a05d3399
RX(theta₂₃)
a9d9fd59bcad41a490981e64949982cd--dc830c2050c04a3a9b4d72a6a05d3399
4fbc37d524fb49b0b3599909b90eab56
X
dc830c2050c04a3a9b4d72a6a05d3399--4fbc37d524fb49b0b3599909b90eab56
4fbc37d524fb49b0b3599909b90eab56--919e14f53935462e9ec475c9149bb129
d06f9a16b29648f6a74f626781eff512
4fbc37d524fb49b0b3599909b90eab56--d06f9a16b29648f6a74f626781eff512
d06f9a16b29648f6a74f626781eff512--18987bd187ed4410b35465c1cd8f63b4
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_1ed5770298874a3f800ebd8bc188bca9
HEA
cluster_1125f47fbb2c43faadb7b35b1c31694c
HEA
72c39073b21d4b8ebbb2a429e04a1040
0
886c3ba94e8749e8ac7ba54143964341
RX(p1₀)
72c39073b21d4b8ebbb2a429e04a1040--886c3ba94e8749e8ac7ba54143964341
1e24d33f1d51470abb13b49eb848d883
1
d6112eb383ff4e61a57b6543a393a5f2
RY(p1₄)
886c3ba94e8749e8ac7ba54143964341--d6112eb383ff4e61a57b6543a393a5f2
97a7a5572c9143608ec9c079c046d066
RX(p1₈)
d6112eb383ff4e61a57b6543a393a5f2--97a7a5572c9143608ec9c079c046d066
c228215d4529408abd8544b73e7eb840
97a7a5572c9143608ec9c079c046d066--c228215d4529408abd8544b73e7eb840
c6f0be2e8164421888faa1ceaef84f83
c228215d4529408abd8544b73e7eb840--c6f0be2e8164421888faa1ceaef84f83
65b29d94e1e746769613fd5e7313402a
RX(p1₁₂)
c6f0be2e8164421888faa1ceaef84f83--65b29d94e1e746769613fd5e7313402a
ca4daaf1fd9642768d75107bdd463a35
RY(p1₁₆)
65b29d94e1e746769613fd5e7313402a--ca4daaf1fd9642768d75107bdd463a35
529c9128858b446f94bbf486ac16f667
RX(p1₂₀)
ca4daaf1fd9642768d75107bdd463a35--529c9128858b446f94bbf486ac16f667
7d9d3f32297f4e30b8450313fa042642
529c9128858b446f94bbf486ac16f667--7d9d3f32297f4e30b8450313fa042642
1b0124e204d4430993cf5e86b0d38b4a
7d9d3f32297f4e30b8450313fa042642--1b0124e204d4430993cf5e86b0d38b4a
1fdd60b0339a4ec3abbd3410005554dc
RX(p2₀)
1b0124e204d4430993cf5e86b0d38b4a--1fdd60b0339a4ec3abbd3410005554dc
97986235897942e1b15bb440acdfe2a5
RY(p2₄)
1fdd60b0339a4ec3abbd3410005554dc--97986235897942e1b15bb440acdfe2a5
14b1f2604ac14412b8e966ef3879ae6a
RX(p2₈)
97986235897942e1b15bb440acdfe2a5--14b1f2604ac14412b8e966ef3879ae6a
400156121fed488eb5bc27b4c94d4083
14b1f2604ac14412b8e966ef3879ae6a--400156121fed488eb5bc27b4c94d4083
afb3a3a76a1d4faba8287cfd0510b2e4
400156121fed488eb5bc27b4c94d4083--afb3a3a76a1d4faba8287cfd0510b2e4
74dab1caaaf04699a86ba93458f1f058
RX(p2₁₂)
afb3a3a76a1d4faba8287cfd0510b2e4--74dab1caaaf04699a86ba93458f1f058
05c2724b629d48f896336fa546187e21
RY(p2₁₆)
74dab1caaaf04699a86ba93458f1f058--05c2724b629d48f896336fa546187e21
d77f9c1ff56e41949152c026e1ebd177
RX(p2₂₀)
05c2724b629d48f896336fa546187e21--d77f9c1ff56e41949152c026e1ebd177
f39359304f634fd6bd92a10be2c70c17
d77f9c1ff56e41949152c026e1ebd177--f39359304f634fd6bd92a10be2c70c17
2ad93507ca144598ae2e6c6ecf541fee
f39359304f634fd6bd92a10be2c70c17--2ad93507ca144598ae2e6c6ecf541fee
82a4cd5b9d3c4dcfb963f54bf2384f4a
2ad93507ca144598ae2e6c6ecf541fee--82a4cd5b9d3c4dcfb963f54bf2384f4a
4cff4e7ce9644a518f58fd1e3e377822
3e958a36186f48f094925a8aee96a98a
RX(p1₁)
1e24d33f1d51470abb13b49eb848d883--3e958a36186f48f094925a8aee96a98a
f749cbe2831d40839120e5d5e451f3c7
2
8b00e7ed100142cb846b9233404f4df5
RY(p1₅)
3e958a36186f48f094925a8aee96a98a--8b00e7ed100142cb846b9233404f4df5
2e5cfc75322f465eaad013557bfdb7ab
RX(p1₉)
8b00e7ed100142cb846b9233404f4df5--2e5cfc75322f465eaad013557bfdb7ab
b88409c0236040b0bf22cf57e94e97bf
X
2e5cfc75322f465eaad013557bfdb7ab--b88409c0236040b0bf22cf57e94e97bf
b88409c0236040b0bf22cf57e94e97bf--c228215d4529408abd8544b73e7eb840
beaa530b0e564d359a21492bc24eb1af
b88409c0236040b0bf22cf57e94e97bf--beaa530b0e564d359a21492bc24eb1af
59b1c3c373a246988f210f34784dde6b
RX(p1₁₃)
beaa530b0e564d359a21492bc24eb1af--59b1c3c373a246988f210f34784dde6b
e1b142f345c642068869b0ed828d59c3
RY(p1₁₇)
59b1c3c373a246988f210f34784dde6b--e1b142f345c642068869b0ed828d59c3
8ab6d89f06de4d119af708deae8739fa
RX(p1₂₁)
e1b142f345c642068869b0ed828d59c3--8ab6d89f06de4d119af708deae8739fa
96a35520bf24485684b8929cd3acbe0a
X
8ab6d89f06de4d119af708deae8739fa--96a35520bf24485684b8929cd3acbe0a
96a35520bf24485684b8929cd3acbe0a--7d9d3f32297f4e30b8450313fa042642
0fb98fb3242d4295acfa1699ca8e5623
96a35520bf24485684b8929cd3acbe0a--0fb98fb3242d4295acfa1699ca8e5623
e1267a9ac82c4b508650328babdcea17
RX(p2₁)
0fb98fb3242d4295acfa1699ca8e5623--e1267a9ac82c4b508650328babdcea17
5294409c4cda438db8c777b9c04582ff
RY(p2₅)
e1267a9ac82c4b508650328babdcea17--5294409c4cda438db8c777b9c04582ff
e3008dbbf46b4e3b9d6683ca49d86803
RX(p2₉)
5294409c4cda438db8c777b9c04582ff--e3008dbbf46b4e3b9d6683ca49d86803
361b3aae84c24d4fb7b0d5a1faa1da66
X
e3008dbbf46b4e3b9d6683ca49d86803--361b3aae84c24d4fb7b0d5a1faa1da66
361b3aae84c24d4fb7b0d5a1faa1da66--400156121fed488eb5bc27b4c94d4083
b29031359b2144e78732b9693cba6267
361b3aae84c24d4fb7b0d5a1faa1da66--b29031359b2144e78732b9693cba6267
1c5df76d2dae4eeca5ccbe2d70b18a13
RX(p2₁₃)
b29031359b2144e78732b9693cba6267--1c5df76d2dae4eeca5ccbe2d70b18a13
b82632ce9ba540cebdf6cbfa70a29b9c
RY(p2₁₇)
1c5df76d2dae4eeca5ccbe2d70b18a13--b82632ce9ba540cebdf6cbfa70a29b9c
7d2d99799dee4cd9b42ce4a47c495d1e
RX(p2₂₁)
b82632ce9ba540cebdf6cbfa70a29b9c--7d2d99799dee4cd9b42ce4a47c495d1e
990edf6a605d487590ba17209a7f771a
X
7d2d99799dee4cd9b42ce4a47c495d1e--990edf6a605d487590ba17209a7f771a
990edf6a605d487590ba17209a7f771a--f39359304f634fd6bd92a10be2c70c17
8c3604775b0a4904bd5a3354e737deeb
990edf6a605d487590ba17209a7f771a--8c3604775b0a4904bd5a3354e737deeb
8c3604775b0a4904bd5a3354e737deeb--4cff4e7ce9644a518f58fd1e3e377822
4cf2da5a2f1443bdaa0d161c0e957559
5b6109c098a54ab2a3e777b4c94d01b8
RX(p1₂)
f749cbe2831d40839120e5d5e451f3c7--5b6109c098a54ab2a3e777b4c94d01b8
dd9ba6e6fb954d0b85710d378248c162
3
a5b2bee893694d579c05197542223f0e
RY(p1₆)
5b6109c098a54ab2a3e777b4c94d01b8--a5b2bee893694d579c05197542223f0e
1033093b53124bd99ab6dd11ea163e64
RX(p1₁₀)
a5b2bee893694d579c05197542223f0e--1033093b53124bd99ab6dd11ea163e64
47be9533b29446c1b2a9fe80f7b20af6
1033093b53124bd99ab6dd11ea163e64--47be9533b29446c1b2a9fe80f7b20af6
ab082d39aa1c4d21a4d156e138d847fc
X
47be9533b29446c1b2a9fe80f7b20af6--ab082d39aa1c4d21a4d156e138d847fc
ab082d39aa1c4d21a4d156e138d847fc--beaa530b0e564d359a21492bc24eb1af
c7150d82ecec4784a410a5b8f52bb86c
RX(p1₁₄)
ab082d39aa1c4d21a4d156e138d847fc--c7150d82ecec4784a410a5b8f52bb86c
9ef6527fcf8a4f53a9b9ff6935802deb
RY(p1₁₈)
c7150d82ecec4784a410a5b8f52bb86c--9ef6527fcf8a4f53a9b9ff6935802deb
10d91daf82a947219550b58d9a75ea50
RX(p1₂₂)
9ef6527fcf8a4f53a9b9ff6935802deb--10d91daf82a947219550b58d9a75ea50
a8f5f262a24d4e2ca6bd54774ab38a13
10d91daf82a947219550b58d9a75ea50--a8f5f262a24d4e2ca6bd54774ab38a13
5813d9a8ab1d44c8b6583606d8e18613
X
a8f5f262a24d4e2ca6bd54774ab38a13--5813d9a8ab1d44c8b6583606d8e18613
5813d9a8ab1d44c8b6583606d8e18613--0fb98fb3242d4295acfa1699ca8e5623
a90a5b79cc5f41ab85dd28678072bfb6
RX(p2₂)
5813d9a8ab1d44c8b6583606d8e18613--a90a5b79cc5f41ab85dd28678072bfb6
4312724e06f640adb7ade9293f4ef6df
RY(p2₆)
a90a5b79cc5f41ab85dd28678072bfb6--4312724e06f640adb7ade9293f4ef6df
935dd1dd32524248b4122d38ad3b62d0
RX(p2₁₀)
4312724e06f640adb7ade9293f4ef6df--935dd1dd32524248b4122d38ad3b62d0
afaa8da439c34abea80953c8b10fecf2
935dd1dd32524248b4122d38ad3b62d0--afaa8da439c34abea80953c8b10fecf2
52071939335947c1a33e3acf6f45e36f
X
afaa8da439c34abea80953c8b10fecf2--52071939335947c1a33e3acf6f45e36f
52071939335947c1a33e3acf6f45e36f--b29031359b2144e78732b9693cba6267
eb3bd6013c464ed88260fdfde1307d1b
RX(p2₁₄)
52071939335947c1a33e3acf6f45e36f--eb3bd6013c464ed88260fdfde1307d1b
66e667f098d141129d404fe431b3b74a
RY(p2₁₈)
eb3bd6013c464ed88260fdfde1307d1b--66e667f098d141129d404fe431b3b74a
573dbdd43c224489be74f3b8681a80ea
RX(p2₂₂)
66e667f098d141129d404fe431b3b74a--573dbdd43c224489be74f3b8681a80ea
f2712a854ecc44c3b90c7d7f22d66634
573dbdd43c224489be74f3b8681a80ea--f2712a854ecc44c3b90c7d7f22d66634
e35fa204926d4b268237064c5914f86a
X
f2712a854ecc44c3b90c7d7f22d66634--e35fa204926d4b268237064c5914f86a
e35fa204926d4b268237064c5914f86a--8c3604775b0a4904bd5a3354e737deeb
e35fa204926d4b268237064c5914f86a--4cf2da5a2f1443bdaa0d161c0e957559
ac65a840bab14899b4ac21aa3efd9726
0bcbc722478748a197260cf46e5f301d
RX(p1₃)
dd9ba6e6fb954d0b85710d378248c162--0bcbc722478748a197260cf46e5f301d
ae83819f605243d59eda6a5d82cf8241
RY(p1₇)
0bcbc722478748a197260cf46e5f301d--ae83819f605243d59eda6a5d82cf8241
76ed2912eedb43b8a8a8a386853a2e9d
RX(p1₁₁)
ae83819f605243d59eda6a5d82cf8241--76ed2912eedb43b8a8a8a386853a2e9d
4bbb33df2ab048f8af6aa9492fa49c46
X
76ed2912eedb43b8a8a8a386853a2e9d--4bbb33df2ab048f8af6aa9492fa49c46
4bbb33df2ab048f8af6aa9492fa49c46--47be9533b29446c1b2a9fe80f7b20af6
d2337c2106684f13b355cce5e5ca9ac1
4bbb33df2ab048f8af6aa9492fa49c46--d2337c2106684f13b355cce5e5ca9ac1
7e6f79788e194191b5bf23293708db05
RX(p1₁₅)
d2337c2106684f13b355cce5e5ca9ac1--7e6f79788e194191b5bf23293708db05
2cbb99940bfc4a2c8e395299a62e3847
RY(p1₁₉)
7e6f79788e194191b5bf23293708db05--2cbb99940bfc4a2c8e395299a62e3847
96d1bec1824040f7ab139f17f801199c
RX(p1₂₃)
2cbb99940bfc4a2c8e395299a62e3847--96d1bec1824040f7ab139f17f801199c
86725b0c51bb4c418e375fcddf0739c9
X
96d1bec1824040f7ab139f17f801199c--86725b0c51bb4c418e375fcddf0739c9
86725b0c51bb4c418e375fcddf0739c9--a8f5f262a24d4e2ca6bd54774ab38a13
1df9a71f78e5408cb9e1529ab511fb5a
86725b0c51bb4c418e375fcddf0739c9--1df9a71f78e5408cb9e1529ab511fb5a
b051c97248004df68f58ad86c28f428a
RX(p2₃)
1df9a71f78e5408cb9e1529ab511fb5a--b051c97248004df68f58ad86c28f428a
a52f38adcb824ae68c79a39c519275d7
RY(p2₇)
b051c97248004df68f58ad86c28f428a--a52f38adcb824ae68c79a39c519275d7
ed2b8ba9795141579edd2932b97c1648
RX(p2₁₁)
a52f38adcb824ae68c79a39c519275d7--ed2b8ba9795141579edd2932b97c1648
4ccebdece6f94fe393ff20fd87b378d3
X
ed2b8ba9795141579edd2932b97c1648--4ccebdece6f94fe393ff20fd87b378d3
4ccebdece6f94fe393ff20fd87b378d3--afaa8da439c34abea80953c8b10fecf2
142266455389487f8cb34151807223dc
4ccebdece6f94fe393ff20fd87b378d3--142266455389487f8cb34151807223dc
d30d50199efb4e959f6aaab11a9bfcaa
RX(p2₁₅)
142266455389487f8cb34151807223dc--d30d50199efb4e959f6aaab11a9bfcaa
c05e642e9e5b4d69841fc3e51074118c
RY(p2₁₉)
d30d50199efb4e959f6aaab11a9bfcaa--c05e642e9e5b4d69841fc3e51074118c
bc5cc85cc5de4e75a618d077051c4a61
RX(p2₂₃)
c05e642e9e5b4d69841fc3e51074118c--bc5cc85cc5de4e75a618d077051c4a61
48fe344d52864b79991bd8fac36307e1
X
bc5cc85cc5de4e75a618d077051c4a61--48fe344d52864b79991bd8fac36307e1
48fe344d52864b79991bd8fac36307e1--f2712a854ecc44c3b90c7d7f22d66634
863ed58cfdcb4fa2ac51d511d1e0223d
48fe344d52864b79991bd8fac36307e1--863ed58cfdcb4fa2ac51d511d1e0223d
863ed58cfdcb4fa2ac51d511d1e0223d--ac65a840bab14899b4ac21aa3efd9726
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.6723 ] )) , (' t he ta _ 0 ' , tens or( [ 0.1476 ] )) , (' t he ta _ 1 ' , tens or( [ 0.6309 ] )) , (' t he ta _ 10 ' , tens or( [ 0.8657 ] )) , (' t he ta _ 11 ' , tens or( [ 0.8418 ] )) , (' t he ta _ 12 ' , tens or( [ 0.1063 ] )) , (' t he ta _ 13 ' , tens or( [ 0.6077 ] )) , (' t he ta _ 14 ' , tens or( [ 0.8846 ] )) , (' t he ta _ 15 ' , tens or( [ 0.9668 ] )) , (' t he ta _ 16 ' , tens or( [ 0.2565 ] )) , (' t he ta _ 17 ' , tens or( [ 0.1043 ] )) , (' t he ta _ 18 ' , tens or( [ 0.9783 ] )) , (' t he ta _ 19 ' , tens or( [ 0.0618 ] )) , (' t he ta _ 2 ' , tens or( [ 0.1834 ] )) , (' t he ta _ 20 ' , tens or( [ 0.4442 ] )) , (' t he ta _ 21 ' , tens or( [ 0.6389 ] )) , (' t he ta _ 22 ' , tens or( [ 0.6250 ] )) , (' t he ta _ 23 ' , tens or( [ 0.5487 ] )) , (' t he ta _ 3 ' , tens or( [ 0.8038 ] )) , (' t he ta _ 4 ' , tens or( [ 0.9408 ] )) , (' t he ta _ 5 ' , tens or( [ 0.4441 ] )) , (' t he ta _ 6 ' , tens or( [ 0.6926 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3457 ] )) , (' t he ta _ 8 ' , tens or( [ 0.6128 ] )) , (' t he ta _ 9 ' , tens or( [ 0.6174 ] )) ] )
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.6713 ] )) , (' t he ta _ 0 ' , tens or( [ 0.1486 ] )) , (' t he ta _ 1 ' , tens or( [ 0.6319 ] )) , (' t he ta _ 10 ' , tens or( [ 0.8667 ] )) , (' t he ta _ 11 ' , tens or( [ 0.8428 ] )) , (' t he ta _ 12 ' , tens or( [ 0.1073 ] )) , (' t he ta _ 13 ' , tens or( [ 0.6067 ] )) , (' t he ta _ 14 ' , tens or( [ 0.8856 ] )) , (' t he ta _ 15 ' , tens or( [ 0.9678 ] )) , (' t he ta _ 16 ' , tens or( [ 0.2575 ] )) , (' t he ta _ 17 ' , tens or( [ 0.1033 ] )) , (' t he ta _ 18 ' , tens or( [ 0.9773 ] )) , (' t he ta _ 19 ' , tens or( [ 0.0608 ] )) , (' t he ta _ 2 ' , tens or( [ 0.1844 ] )) , (' t he ta _ 20 ' , tens or( [ 0.4452 ] )) , (' t he ta _ 21 ' , tens or( [ 0.6379 ] )) , (' t he ta _ 22 ' , tens or( [ 0.6260 ] )) , (' t he ta _ 23 ' , tens or( [ 0.5497 ] )) , (' t he ta _ 3 ' , tens or( [ 0.8048 ] )) , (' t he ta _ 4 ' , tens or( [ 0.9418 ] )) , (' t he ta _ 5 ' , tens or( [ 0.4451 ] )) , (' t he ta _ 6 ' , tens or( [ 0.6936 ] )) , (' t he ta _ 7 ' , tens or( [ 0.3467 ] )) , (' t he ta _ 8 ' , tens or( [ 0.6138 ] )) , (' t he ta _ 9 ' , tens or( [ 0.6184 ] )) ] )
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 ]] )