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.9903+0.0000 j , 0.0000-0.1388 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.8950+0.0000 j , 0.0000-0.4460 j ],
[ 0.9960+0.0000 j , 0.0000-0.0893 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.7308+0.0000 j , 0.6788+0.0000 j , 0.0000-0.0523 j , 0.0000-0.0486 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_bcd824d4eae44f04ba399a984dd76d5d
[* 2]
cluster_704d81a2ce364af9b5d4511d1d4dcab5
Rotations
9d3ecf7611a34ce49c26f204b3537acb
0
13de35bbd4d2449f8c69e77c0ade9759
RX(phi/theta)
9d3ecf7611a34ce49c26f204b3537acb--13de35bbd4d2449f8c69e77c0ade9759
0e27fd282bee4adda4dfc78d3b762529
1
2ead2a6a801e4a38be30cade2bac4b9f
RX(phi)
13de35bbd4d2449f8c69e77c0ade9759--2ead2a6a801e4a38be30cade2bac4b9f
2900bec33c2847f1aac9db6b6d6fa904
RX(phi)
2ead2a6a801e4a38be30cade2bac4b9f--2900bec33c2847f1aac9db6b6d6fa904
3d6ff47dcdde4b97847862dae1ff0e94
RX(phi + theta)
2900bec33c2847f1aac9db6b6d6fa904--3d6ff47dcdde4b97847862dae1ff0e94
2875cbf8dcd74760837a7369e57ec815
3d6ff47dcdde4b97847862dae1ff0e94--2875cbf8dcd74760837a7369e57ec815
b72c48c9f7384cd593c813cb6c2ec248
2875cbf8dcd74760837a7369e57ec815--b72c48c9f7384cd593c813cb6c2ec248
4243633ef4cc441aa861a5c073d7446d
Z
b72c48c9f7384cd593c813cb6c2ec248--4243633ef4cc441aa861a5c073d7446d
25a27c6ca3be4bb4b70e11cb83171beb
4243633ef4cc441aa861a5c073d7446d--25a27c6ca3be4bb4b70e11cb83171beb
6c6c8654885e4873abd7cdb080e6b556
89cbfa439b5d49b898df80f09222899c
RY(2*theta)
0e27fd282bee4adda4dfc78d3b762529--89cbfa439b5d49b898df80f09222899c
3ab1fe74f91f445db2ebb2db883e276b
2
61630b5ab3e6441492799efd8a57512e
RY(theta)
89cbfa439b5d49b898df80f09222899c--61630b5ab3e6441492799efd8a57512e
dc6672a6548948fa8f0b25d200eb9f1d
RY(theta)
61630b5ab3e6441492799efd8a57512e--dc6672a6548948fa8f0b25d200eb9f1d
a3a2d5f441434b3aa32fb65b1aa55f08
RY(theta**2)
dc6672a6548948fa8f0b25d200eb9f1d--a3a2d5f441434b3aa32fb65b1aa55f08
5c7a1fb6fd7c450ba6270ce103bc4d7d
X
a3a2d5f441434b3aa32fb65b1aa55f08--5c7a1fb6fd7c450ba6270ce103bc4d7d
5c7a1fb6fd7c450ba6270ce103bc4d7d--2875cbf8dcd74760837a7369e57ec815
6a6afbb99f8742dc8c69212f2c14eb9a
5c7a1fb6fd7c450ba6270ce103bc4d7d--6a6afbb99f8742dc8c69212f2c14eb9a
01662068eafb4356b86586fe1ceb69f3
Z
6a6afbb99f8742dc8c69212f2c14eb9a--01662068eafb4356b86586fe1ceb69f3
01662068eafb4356b86586fe1ceb69f3--6c6c8654885e4873abd7cdb080e6b556
2a8a21beb4ae46278e0cc50da327ab3c
43e82b32f01a4404be618f9621d365d1
RZ(cos(phi))
3ab1fe74f91f445db2ebb2db883e276b--43e82b32f01a4404be618f9621d365d1
e817b59240ca424e9be963742dfbd76a
RZ(phi)
43e82b32f01a4404be618f9621d365d1--e817b59240ca424e9be963742dfbd76a
07bdf39d49bc4f0481d1c93bf6224bd0
RZ(phi)
e817b59240ca424e9be963742dfbd76a--07bdf39d49bc4f0481d1c93bf6224bd0
02a2d76f11504c0e936b9a5975271c20
RZ(cos(phi))
07bdf39d49bc4f0481d1c93bf6224bd0--02a2d76f11504c0e936b9a5975271c20
6e101c1c9a4c4f3abb26141400266b1d
02a2d76f11504c0e936b9a5975271c20--6e101c1c9a4c4f3abb26141400266b1d
6a5dbe8d7de3409390768d2d19efcfe0
X
6e101c1c9a4c4f3abb26141400266b1d--6a5dbe8d7de3409390768d2d19efcfe0
6a5dbe8d7de3409390768d2d19efcfe0--6a6afbb99f8742dc8c69212f2c14eb9a
a3f2f5af13984480a4e5f39171e4b7a3
Z
6a5dbe8d7de3409390768d2d19efcfe0--a3f2f5af13984480a4e5f39171e4b7a3
a3f2f5af13984480a4e5f39171e4b7a3--2a8a21beb4ae46278e0cc50da327ab3c
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.1479 ] )) ] )
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.9868+0.0000 j , 0.1142+0.0000 j , 0.0000-0.1142 j , 0.0000-0.0132 j ],
[ 0.9047+0.0000 j , 0.2937+0.0000 j , 0.0000-0.2937 j , 0.0000-0.0953 j ],
[ 0.8202+0.0000 j , 0.3840+0.0000 j , 0.0000-0.3840 j , 0.0000-0.1798 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
7b14e3151bb64f988e71cca181aacc32
0
5a7f4d8695f94097b20687d2e2b51fe5
RX(theta₀)
7b14e3151bb64f988e71cca181aacc32--5a7f4d8695f94097b20687d2e2b51fe5
b3d3d126e0374606a4d81fcb40786e5c
1
268e1ea081384bc28e51abc06355d387
RY(theta₄)
5a7f4d8695f94097b20687d2e2b51fe5--268e1ea081384bc28e51abc06355d387
c8cee8036c154a28b8afb03ed2db3f2e
RX(theta₈)
268e1ea081384bc28e51abc06355d387--c8cee8036c154a28b8afb03ed2db3f2e
97103b782c054e4ea055098724027381
c8cee8036c154a28b8afb03ed2db3f2e--97103b782c054e4ea055098724027381
85a83fc68cfe406291b74acc897558a5
97103b782c054e4ea055098724027381--85a83fc68cfe406291b74acc897558a5
1fe39255f32e4a818baeb0319cd88078
RX(theta₁₂)
85a83fc68cfe406291b74acc897558a5--1fe39255f32e4a818baeb0319cd88078
0c0400ed4261427ca865944d3f07bb68
RY(theta₁₆)
1fe39255f32e4a818baeb0319cd88078--0c0400ed4261427ca865944d3f07bb68
224750f2f5f04e92b7c25170ad6da54f
RX(theta₂₀)
0c0400ed4261427ca865944d3f07bb68--224750f2f5f04e92b7c25170ad6da54f
07366ba379fc450896811669d8dda8bf
224750f2f5f04e92b7c25170ad6da54f--07366ba379fc450896811669d8dda8bf
5e798b89dccc48cdb820dbecde2fe766
07366ba379fc450896811669d8dda8bf--5e798b89dccc48cdb820dbecde2fe766
b4b92dd15606490488bbd91ad148e941
5e798b89dccc48cdb820dbecde2fe766--b4b92dd15606490488bbd91ad148e941
70fcd7cee92b435a9cf1989216ffe193
2c528b2007cc4dfa9f591b2af3265545
RX(theta₁)
b3d3d126e0374606a4d81fcb40786e5c--2c528b2007cc4dfa9f591b2af3265545
ae667163d6414fda9155e5f62d40625b
2
7fee5d98129048708aa30ba4dd928988
RY(theta₅)
2c528b2007cc4dfa9f591b2af3265545--7fee5d98129048708aa30ba4dd928988
34dd97745062441782b7422369936a35
RX(theta₉)
7fee5d98129048708aa30ba4dd928988--34dd97745062441782b7422369936a35
a691a6b0a3bc4d24a38e5f91c9cb9cf6
X
34dd97745062441782b7422369936a35--a691a6b0a3bc4d24a38e5f91c9cb9cf6
a691a6b0a3bc4d24a38e5f91c9cb9cf6--97103b782c054e4ea055098724027381
5b3a512be8c24207a14757f25d4f0159
a691a6b0a3bc4d24a38e5f91c9cb9cf6--5b3a512be8c24207a14757f25d4f0159
31d00f47fcfa4aee8dce3a2dde8f951a
RX(theta₁₃)
5b3a512be8c24207a14757f25d4f0159--31d00f47fcfa4aee8dce3a2dde8f951a
637103fa45504e608faaffaf4ea5436d
RY(theta₁₇)
31d00f47fcfa4aee8dce3a2dde8f951a--637103fa45504e608faaffaf4ea5436d
d3f7f01952874777a7d874a8454c18dd
RX(theta₂₁)
637103fa45504e608faaffaf4ea5436d--d3f7f01952874777a7d874a8454c18dd
57d3ed0fae6b4dc9a09afabd7e68e30d
X
d3f7f01952874777a7d874a8454c18dd--57d3ed0fae6b4dc9a09afabd7e68e30d
57d3ed0fae6b4dc9a09afabd7e68e30d--07366ba379fc450896811669d8dda8bf
9cfea8f7b4e8448cae83d4278b94d46a
57d3ed0fae6b4dc9a09afabd7e68e30d--9cfea8f7b4e8448cae83d4278b94d46a
9cfea8f7b4e8448cae83d4278b94d46a--70fcd7cee92b435a9cf1989216ffe193
9a7280390be94aa1a075d83f984ebb55
4bdd1133f5ea4718a5093d9b72db4026
RX(theta₂)
ae667163d6414fda9155e5f62d40625b--4bdd1133f5ea4718a5093d9b72db4026
b771256a62ab422db550d07dc118c64a
3
c471859043c149ee92bfa618c1160601
RY(theta₆)
4bdd1133f5ea4718a5093d9b72db4026--c471859043c149ee92bfa618c1160601
8762c187f2a84158bbbe483f94182b21
RX(theta₁₀)
c471859043c149ee92bfa618c1160601--8762c187f2a84158bbbe483f94182b21
3253500c39f4447b9acea0eff07ac7bc
8762c187f2a84158bbbe483f94182b21--3253500c39f4447b9acea0eff07ac7bc
4a5ddc0888b44d5585984567b5a9e3e9
X
3253500c39f4447b9acea0eff07ac7bc--4a5ddc0888b44d5585984567b5a9e3e9
4a5ddc0888b44d5585984567b5a9e3e9--5b3a512be8c24207a14757f25d4f0159
79b5b23deac743f1ba1dd655e02de515
RX(theta₁₄)
4a5ddc0888b44d5585984567b5a9e3e9--79b5b23deac743f1ba1dd655e02de515
45d55c1a6d934d089321047e58898489
RY(theta₁₈)
79b5b23deac743f1ba1dd655e02de515--45d55c1a6d934d089321047e58898489
15eebea954bb4010ba17bf6f9a8d2a60
RX(theta₂₂)
45d55c1a6d934d089321047e58898489--15eebea954bb4010ba17bf6f9a8d2a60
41afd356b78a48a0aeaf07d586306997
15eebea954bb4010ba17bf6f9a8d2a60--41afd356b78a48a0aeaf07d586306997
b35919f7e9a945519d3c7eedbfae0379
X
41afd356b78a48a0aeaf07d586306997--b35919f7e9a945519d3c7eedbfae0379
b35919f7e9a945519d3c7eedbfae0379--9cfea8f7b4e8448cae83d4278b94d46a
b35919f7e9a945519d3c7eedbfae0379--9a7280390be94aa1a075d83f984ebb55
aa16bb5a15a149589aec15f7618d8a71
9ef27749d3da4a9fa5e79c128be5d60f
RX(theta₃)
b771256a62ab422db550d07dc118c64a--9ef27749d3da4a9fa5e79c128be5d60f
79268db3cabc45a88719263b039b9477
RY(theta₇)
9ef27749d3da4a9fa5e79c128be5d60f--79268db3cabc45a88719263b039b9477
eeef36896d9e4bdd9fbfc32b628757db
RX(theta₁₁)
79268db3cabc45a88719263b039b9477--eeef36896d9e4bdd9fbfc32b628757db
b57f7692fa9a43cea71fb1fb98894a7a
X
eeef36896d9e4bdd9fbfc32b628757db--b57f7692fa9a43cea71fb1fb98894a7a
b57f7692fa9a43cea71fb1fb98894a7a--3253500c39f4447b9acea0eff07ac7bc
442ebae2e106444eab87761e4f88fa5d
b57f7692fa9a43cea71fb1fb98894a7a--442ebae2e106444eab87761e4f88fa5d
0d30b9a9c71a480bb157b22f73146313
RX(theta₁₅)
442ebae2e106444eab87761e4f88fa5d--0d30b9a9c71a480bb157b22f73146313
741b5bd07923451cb0a6618a32b7f16c
RY(theta₁₉)
0d30b9a9c71a480bb157b22f73146313--741b5bd07923451cb0a6618a32b7f16c
58c4aa274c554a3593e39046c4384295
RX(theta₂₃)
741b5bd07923451cb0a6618a32b7f16c--58c4aa274c554a3593e39046c4384295
b03e96a5c63948cd999e22308467b8e8
X
58c4aa274c554a3593e39046c4384295--b03e96a5c63948cd999e22308467b8e8
b03e96a5c63948cd999e22308467b8e8--41afd356b78a48a0aeaf07d586306997
bc9e367e677f41268d6c3c3ccf3601ce
b03e96a5c63948cd999e22308467b8e8--bc9e367e677f41268d6c3c3ccf3601ce
bc9e367e677f41268d6c3c3ccf3601ce--aa16bb5a15a149589aec15f7618d8a71
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_8e4ebc24930b4960a82ca0e871032ab3
HEA
cluster_7dfde4dfe7884eed8d81ab6a17df3981
HEA
04f1d0c6345449108157284b0ff5df8d
0
3c353799eb5e424e9980ad6f93342104
RX(theta₀)
04f1d0c6345449108157284b0ff5df8d--3c353799eb5e424e9980ad6f93342104
98884408cc7647d4bd254635074f58e7
1
829eff0444b14740a6903652b1ea7c42
RY(theta₄)
3c353799eb5e424e9980ad6f93342104--829eff0444b14740a6903652b1ea7c42
bcf70e4788794f9fab6ec85811b613af
RX(theta₈)
829eff0444b14740a6903652b1ea7c42--bcf70e4788794f9fab6ec85811b613af
c48555aa38394be990095c936b0832b8
bcf70e4788794f9fab6ec85811b613af--c48555aa38394be990095c936b0832b8
2de46bfb55874d54ae287a5e02c960a5
c48555aa38394be990095c936b0832b8--2de46bfb55874d54ae287a5e02c960a5
3f2365be0f564904a37cbf8c19aabca8
RX(theta₁₂)
2de46bfb55874d54ae287a5e02c960a5--3f2365be0f564904a37cbf8c19aabca8
2d51054d03b44efebefe3a351f2f5f81
RY(theta₁₆)
3f2365be0f564904a37cbf8c19aabca8--2d51054d03b44efebefe3a351f2f5f81
b3e21d4159bb404ba57f4362f806c98e
RX(theta₂₀)
2d51054d03b44efebefe3a351f2f5f81--b3e21d4159bb404ba57f4362f806c98e
ea13db7fa98341cfa4d7a4fe40e836a1
b3e21d4159bb404ba57f4362f806c98e--ea13db7fa98341cfa4d7a4fe40e836a1
0c2c23d0148d4d0c8acd9e5de8c3be6a
ea13db7fa98341cfa4d7a4fe40e836a1--0c2c23d0148d4d0c8acd9e5de8c3be6a
311100d887524b78ad9de16d9eb50be2
RX(theta₀)
0c2c23d0148d4d0c8acd9e5de8c3be6a--311100d887524b78ad9de16d9eb50be2
0e8c9609129e4e86a2eeccb99c6ec8f2
RY(theta₄)
311100d887524b78ad9de16d9eb50be2--0e8c9609129e4e86a2eeccb99c6ec8f2
24e8ff6773074fe78c4bb554ffa344ef
RX(theta₈)
0e8c9609129e4e86a2eeccb99c6ec8f2--24e8ff6773074fe78c4bb554ffa344ef
e448107c125c4bd39d52bd04b6ccf187
24e8ff6773074fe78c4bb554ffa344ef--e448107c125c4bd39d52bd04b6ccf187
d73249e1bf114ae0afd4631f81b78d4b
e448107c125c4bd39d52bd04b6ccf187--d73249e1bf114ae0afd4631f81b78d4b
47ed146da55b45809db1fc65aa36941c
RX(theta₁₂)
d73249e1bf114ae0afd4631f81b78d4b--47ed146da55b45809db1fc65aa36941c
7d483279bb2d477aabd80d10946f00d3
RY(theta₁₆)
47ed146da55b45809db1fc65aa36941c--7d483279bb2d477aabd80d10946f00d3
8133636f1a9f4e59bd9b8f53d7dbd945
RX(theta₂₀)
7d483279bb2d477aabd80d10946f00d3--8133636f1a9f4e59bd9b8f53d7dbd945
f33065b172c54eeda3f2ff216f71fa6a
8133636f1a9f4e59bd9b8f53d7dbd945--f33065b172c54eeda3f2ff216f71fa6a
c538e18f4e6c4c23bd42911b0536ac17
f33065b172c54eeda3f2ff216f71fa6a--c538e18f4e6c4c23bd42911b0536ac17
bc685f5bda5841c49060c76693c41e99
c538e18f4e6c4c23bd42911b0536ac17--bc685f5bda5841c49060c76693c41e99
6e5c4cb5e691451ab93d759beab8c71e
619d1e5eed7248558b8f064af0cc884a
RX(theta₁)
98884408cc7647d4bd254635074f58e7--619d1e5eed7248558b8f064af0cc884a
063cf47a6e214522805f87f72ec26c44
2
a55e66c0293d4aaf82b34a828e8591fe
RY(theta₅)
619d1e5eed7248558b8f064af0cc884a--a55e66c0293d4aaf82b34a828e8591fe
308be88ccff2422b94332e826b1aab7c
RX(theta₉)
a55e66c0293d4aaf82b34a828e8591fe--308be88ccff2422b94332e826b1aab7c
d46ff18937a24548bbc064fb3ba1b0d1
X
308be88ccff2422b94332e826b1aab7c--d46ff18937a24548bbc064fb3ba1b0d1
d46ff18937a24548bbc064fb3ba1b0d1--c48555aa38394be990095c936b0832b8
eba8c587c647441ab6ac288218c79c6f
d46ff18937a24548bbc064fb3ba1b0d1--eba8c587c647441ab6ac288218c79c6f
aac134b08fd4468cb5b441e8f7f3c162
RX(theta₁₃)
eba8c587c647441ab6ac288218c79c6f--aac134b08fd4468cb5b441e8f7f3c162
5ed6f7f129cb4737b0fc133eed847281
RY(theta₁₇)
aac134b08fd4468cb5b441e8f7f3c162--5ed6f7f129cb4737b0fc133eed847281
7a9bdd776a8446a096b90ce93672c17c
RX(theta₂₁)
5ed6f7f129cb4737b0fc133eed847281--7a9bdd776a8446a096b90ce93672c17c
c17fa995c4f8454aa7ae69f805cb6072
X
7a9bdd776a8446a096b90ce93672c17c--c17fa995c4f8454aa7ae69f805cb6072
c17fa995c4f8454aa7ae69f805cb6072--ea13db7fa98341cfa4d7a4fe40e836a1
a1085552e53c4a4fb8b557d1a1cbc1cb
c17fa995c4f8454aa7ae69f805cb6072--a1085552e53c4a4fb8b557d1a1cbc1cb
4f98b9711cdb4e6495163f44f4047dec
RX(theta₁)
a1085552e53c4a4fb8b557d1a1cbc1cb--4f98b9711cdb4e6495163f44f4047dec
afa567e79f494415a7fbc0d34ae1479c
RY(theta₅)
4f98b9711cdb4e6495163f44f4047dec--afa567e79f494415a7fbc0d34ae1479c
31f590afcefc4855aee1fd9b6ef65baa
RX(theta₉)
afa567e79f494415a7fbc0d34ae1479c--31f590afcefc4855aee1fd9b6ef65baa
84d9b4d068f144d49223dfecd556536a
X
31f590afcefc4855aee1fd9b6ef65baa--84d9b4d068f144d49223dfecd556536a
84d9b4d068f144d49223dfecd556536a--e448107c125c4bd39d52bd04b6ccf187
f2dd6910e9714ba0aeb0b5bac482c21b
84d9b4d068f144d49223dfecd556536a--f2dd6910e9714ba0aeb0b5bac482c21b
38c5f27d04ae45df9145c08faf8eaa91
RX(theta₁₃)
f2dd6910e9714ba0aeb0b5bac482c21b--38c5f27d04ae45df9145c08faf8eaa91
838c9c8e1bc7475d9ade22681896bd69
RY(theta₁₇)
38c5f27d04ae45df9145c08faf8eaa91--838c9c8e1bc7475d9ade22681896bd69
ea1b2ede812942298fdde82aad5a8fe5
RX(theta₂₁)
838c9c8e1bc7475d9ade22681896bd69--ea1b2ede812942298fdde82aad5a8fe5
e1a42206732b4a059e80d6f5dc93428c
X
ea1b2ede812942298fdde82aad5a8fe5--e1a42206732b4a059e80d6f5dc93428c
e1a42206732b4a059e80d6f5dc93428c--f33065b172c54eeda3f2ff216f71fa6a
6c1439ca4528496a99112ce2d8fc2ee4
e1a42206732b4a059e80d6f5dc93428c--6c1439ca4528496a99112ce2d8fc2ee4
6c1439ca4528496a99112ce2d8fc2ee4--6e5c4cb5e691451ab93d759beab8c71e
a800e877078e4e4d8d3e6583141df6a0
110528401b4e42ad81cf4f2ac372581b
RX(theta₂)
063cf47a6e214522805f87f72ec26c44--110528401b4e42ad81cf4f2ac372581b
f9b5bc6bcde7480f89dee5d612874902
3
b771ca59bb2d44ae8426cde1bab5a555
RY(theta₆)
110528401b4e42ad81cf4f2ac372581b--b771ca59bb2d44ae8426cde1bab5a555
8cb98dee837c48d5b5757eb9509eb6de
RX(theta₁₀)
b771ca59bb2d44ae8426cde1bab5a555--8cb98dee837c48d5b5757eb9509eb6de
aa7788b8aefa4902a49885751b370c00
8cb98dee837c48d5b5757eb9509eb6de--aa7788b8aefa4902a49885751b370c00
69762494966248d0a36fc3f9ad2fa84f
X
aa7788b8aefa4902a49885751b370c00--69762494966248d0a36fc3f9ad2fa84f
69762494966248d0a36fc3f9ad2fa84f--eba8c587c647441ab6ac288218c79c6f
3199b216d0c943229d1c27c0963d3469
RX(theta₁₄)
69762494966248d0a36fc3f9ad2fa84f--3199b216d0c943229d1c27c0963d3469
524f3132deca4af2b82b0fc9fffa6398
RY(theta₁₈)
3199b216d0c943229d1c27c0963d3469--524f3132deca4af2b82b0fc9fffa6398
f8035fbd5344477c8c6c7e1a4350dde8
RX(theta₂₂)
524f3132deca4af2b82b0fc9fffa6398--f8035fbd5344477c8c6c7e1a4350dde8
d0908b3245324ef3b80912fca7b42bd3
f8035fbd5344477c8c6c7e1a4350dde8--d0908b3245324ef3b80912fca7b42bd3
83d5cbbfac214c6998696ff2e0190dda
X
d0908b3245324ef3b80912fca7b42bd3--83d5cbbfac214c6998696ff2e0190dda
83d5cbbfac214c6998696ff2e0190dda--a1085552e53c4a4fb8b557d1a1cbc1cb
188e5ef35c6743e58a83bd1dfb3120bb
RX(theta₂)
83d5cbbfac214c6998696ff2e0190dda--188e5ef35c6743e58a83bd1dfb3120bb
0e771a5f792847ae91f68a42e71948be
RY(theta₆)
188e5ef35c6743e58a83bd1dfb3120bb--0e771a5f792847ae91f68a42e71948be
41775eb71fa149e8955cd8f7135a8ce7
RX(theta₁₀)
0e771a5f792847ae91f68a42e71948be--41775eb71fa149e8955cd8f7135a8ce7
919f6c7cf9d748c89d4adc77b7e251b2
41775eb71fa149e8955cd8f7135a8ce7--919f6c7cf9d748c89d4adc77b7e251b2
09c89d9731b84fc5a7dbb24b7bee56b9
X
919f6c7cf9d748c89d4adc77b7e251b2--09c89d9731b84fc5a7dbb24b7bee56b9
09c89d9731b84fc5a7dbb24b7bee56b9--f2dd6910e9714ba0aeb0b5bac482c21b
8d459b40177346db9b5f3dddfa855d8f
RX(theta₁₄)
09c89d9731b84fc5a7dbb24b7bee56b9--8d459b40177346db9b5f3dddfa855d8f
4bc603764b2e4bd094fbcc4960c53a3e
RY(theta₁₈)
8d459b40177346db9b5f3dddfa855d8f--4bc603764b2e4bd094fbcc4960c53a3e
7be2f8800bef48a78247324fa98d439f
RX(theta₂₂)
4bc603764b2e4bd094fbcc4960c53a3e--7be2f8800bef48a78247324fa98d439f
44751b6ec3894e86be87424f791cb132
7be2f8800bef48a78247324fa98d439f--44751b6ec3894e86be87424f791cb132
96049fcf107e49a49f7d6c8fb8bdd2fc
X
44751b6ec3894e86be87424f791cb132--96049fcf107e49a49f7d6c8fb8bdd2fc
96049fcf107e49a49f7d6c8fb8bdd2fc--6c1439ca4528496a99112ce2d8fc2ee4
96049fcf107e49a49f7d6c8fb8bdd2fc--a800e877078e4e4d8d3e6583141df6a0
c11dddcc38444bdb880f191b315d220e
f2bb8797a6c14870abf983ae24b6a10a
RX(theta₃)
f9b5bc6bcde7480f89dee5d612874902--f2bb8797a6c14870abf983ae24b6a10a
083f065269414ce5990d09b6d545e28f
RY(theta₇)
f2bb8797a6c14870abf983ae24b6a10a--083f065269414ce5990d09b6d545e28f
e8511a000ded4302b2d9fe3a2203c942
RX(theta₁₁)
083f065269414ce5990d09b6d545e28f--e8511a000ded4302b2d9fe3a2203c942
375b223df0b648a08b8fe72b2a8c9b87
X
e8511a000ded4302b2d9fe3a2203c942--375b223df0b648a08b8fe72b2a8c9b87
375b223df0b648a08b8fe72b2a8c9b87--aa7788b8aefa4902a49885751b370c00
98e6014d06e54d019e9a83cabe7c946a
375b223df0b648a08b8fe72b2a8c9b87--98e6014d06e54d019e9a83cabe7c946a
76e0b5dde95b4b10be409aa2fb78a9ec
RX(theta₁₅)
98e6014d06e54d019e9a83cabe7c946a--76e0b5dde95b4b10be409aa2fb78a9ec
b3e05ae87bb64ffe868e30b0d0e67d83
RY(theta₁₉)
76e0b5dde95b4b10be409aa2fb78a9ec--b3e05ae87bb64ffe868e30b0d0e67d83
54a62e1a81fe4056a4a30268a1a8f061
RX(theta₂₃)
b3e05ae87bb64ffe868e30b0d0e67d83--54a62e1a81fe4056a4a30268a1a8f061
31caa895548e4a4ab662b7f48c9066b3
X
54a62e1a81fe4056a4a30268a1a8f061--31caa895548e4a4ab662b7f48c9066b3
31caa895548e4a4ab662b7f48c9066b3--d0908b3245324ef3b80912fca7b42bd3
4bf470fdc8464d069cb9103598f7aa31
31caa895548e4a4ab662b7f48c9066b3--4bf470fdc8464d069cb9103598f7aa31
3e8416ef4b3042368f5e91add361849e
RX(theta₃)
4bf470fdc8464d069cb9103598f7aa31--3e8416ef4b3042368f5e91add361849e
a46f0b1557504b82ab479b8fd6a2a5c2
RY(theta₇)
3e8416ef4b3042368f5e91add361849e--a46f0b1557504b82ab479b8fd6a2a5c2
6a55da6fcd7649c89866b3e56a10000a
RX(theta₁₁)
a46f0b1557504b82ab479b8fd6a2a5c2--6a55da6fcd7649c89866b3e56a10000a
b2e6062a1667431291d0c4d24144f876
X
6a55da6fcd7649c89866b3e56a10000a--b2e6062a1667431291d0c4d24144f876
b2e6062a1667431291d0c4d24144f876--919f6c7cf9d748c89d4adc77b7e251b2
d81d3077f6ea4fa2902c2ddc7c8022a2
b2e6062a1667431291d0c4d24144f876--d81d3077f6ea4fa2902c2ddc7c8022a2
62862c82d4d94e42841a681306aca8a2
RX(theta₁₅)
d81d3077f6ea4fa2902c2ddc7c8022a2--62862c82d4d94e42841a681306aca8a2
c7c3cffc51884f25876f96ac2566f1d4
RY(theta₁₉)
62862c82d4d94e42841a681306aca8a2--c7c3cffc51884f25876f96ac2566f1d4
bc8c796b2148426bb92fc81c3b1fda18
RX(theta₂₃)
c7c3cffc51884f25876f96ac2566f1d4--bc8c796b2148426bb92fc81c3b1fda18
6bd7ac8af0554944ac06ca60e244feca
X
bc8c796b2148426bb92fc81c3b1fda18--6bd7ac8af0554944ac06ca60e244feca
6bd7ac8af0554944ac06ca60e244feca--44751b6ec3894e86be87424f791cb132
4cc437f31a3c4242b0b51f2c1b61eab0
6bd7ac8af0554944ac06ca60e244feca--4cc437f31a3c4242b0b51f2c1b61eab0
4cc437f31a3c4242b0b51f2c1b61eab0--c11dddcc38444bdb880f191b315d220e
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_9c44e0cb90c7498f99b89c59d717aa12
HEA
cluster_69e1c6ead77a46c9917b3a5083082f4f
HEA
3985c40a266d445cb61b810b822cb1af
0
3eb2f464bfe84ebb9f105dd1fb467e86
RX(p1₀)
3985c40a266d445cb61b810b822cb1af--3eb2f464bfe84ebb9f105dd1fb467e86
0965ccd0095b4cd6877cbb4f5f787202
1
20bd9a03cb1f447cb9c1f2aa64497b04
RY(p1₄)
3eb2f464bfe84ebb9f105dd1fb467e86--20bd9a03cb1f447cb9c1f2aa64497b04
5516e713ce5a4e5d865f0340a8807022
RX(p1₈)
20bd9a03cb1f447cb9c1f2aa64497b04--5516e713ce5a4e5d865f0340a8807022
327541fee8324e82afdca1d479e4638d
5516e713ce5a4e5d865f0340a8807022--327541fee8324e82afdca1d479e4638d
631c52de351d4d99bcc0c3ae000ece6f
327541fee8324e82afdca1d479e4638d--631c52de351d4d99bcc0c3ae000ece6f
03da7bc828714be58d65141151371a4e
RX(p1₁₂)
631c52de351d4d99bcc0c3ae000ece6f--03da7bc828714be58d65141151371a4e
27562f6adc5d434691b5c45019d72115
RY(p1₁₆)
03da7bc828714be58d65141151371a4e--27562f6adc5d434691b5c45019d72115
7c8d4d0bb7874d69a6330cb312828f52
RX(p1₂₀)
27562f6adc5d434691b5c45019d72115--7c8d4d0bb7874d69a6330cb312828f52
a34c4a1306bd49b7999fab84508c70af
7c8d4d0bb7874d69a6330cb312828f52--a34c4a1306bd49b7999fab84508c70af
c8d6410357734b449182c7971bf3829d
a34c4a1306bd49b7999fab84508c70af--c8d6410357734b449182c7971bf3829d
b18cce13b94e4625aba7b718f18efb6e
RX(p2₀)
c8d6410357734b449182c7971bf3829d--b18cce13b94e4625aba7b718f18efb6e
65301132c95b40ada6abdc854edf01d8
RY(p2₄)
b18cce13b94e4625aba7b718f18efb6e--65301132c95b40ada6abdc854edf01d8
17b0726282064d859eb43226a30f6ad3
RX(p2₈)
65301132c95b40ada6abdc854edf01d8--17b0726282064d859eb43226a30f6ad3
83eac902af544ca6b0f12b5ad6015bad
17b0726282064d859eb43226a30f6ad3--83eac902af544ca6b0f12b5ad6015bad
0337df1ceafa47d4805cad3f76fec09b
83eac902af544ca6b0f12b5ad6015bad--0337df1ceafa47d4805cad3f76fec09b
d82db60ebc2349418ffee8cf738ccd44
RX(p2₁₂)
0337df1ceafa47d4805cad3f76fec09b--d82db60ebc2349418ffee8cf738ccd44
d18189e1a98e4856ab4b6ca0b82e7a7b
RY(p2₁₆)
d82db60ebc2349418ffee8cf738ccd44--d18189e1a98e4856ab4b6ca0b82e7a7b
3fded8a6e3f0494ca98ebee57e32df4b
RX(p2₂₀)
d18189e1a98e4856ab4b6ca0b82e7a7b--3fded8a6e3f0494ca98ebee57e32df4b
7a36c94c8ca24ac3b793a92747f83b98
3fded8a6e3f0494ca98ebee57e32df4b--7a36c94c8ca24ac3b793a92747f83b98
cf7674addc9444328e624a0adfb57fc9
7a36c94c8ca24ac3b793a92747f83b98--cf7674addc9444328e624a0adfb57fc9
96d93be1764a48929b3737620bcbdd85
cf7674addc9444328e624a0adfb57fc9--96d93be1764a48929b3737620bcbdd85
d2eeef02492a42d9b2a7ab77c29ce50a
91eaa1012b334fed91aee38815cec1f2
RX(p1₁)
0965ccd0095b4cd6877cbb4f5f787202--91eaa1012b334fed91aee38815cec1f2
92af7971f19d4691b687ff19791251c4
2
833883ef006b40ffaca027478766befe
RY(p1₅)
91eaa1012b334fed91aee38815cec1f2--833883ef006b40ffaca027478766befe
9a10969a28634d378294609e5d06ed15
RX(p1₉)
833883ef006b40ffaca027478766befe--9a10969a28634d378294609e5d06ed15
2f38799916c14af0964102d90654221b
X
9a10969a28634d378294609e5d06ed15--2f38799916c14af0964102d90654221b
2f38799916c14af0964102d90654221b--327541fee8324e82afdca1d479e4638d
ba374055e0434c54b2216933f47ca30e
2f38799916c14af0964102d90654221b--ba374055e0434c54b2216933f47ca30e
1931eca5bb244b5f91a9868f5c790f9a
RX(p1₁₃)
ba374055e0434c54b2216933f47ca30e--1931eca5bb244b5f91a9868f5c790f9a
659aed4fbe62478fb494e2ff7854892d
RY(p1₁₇)
1931eca5bb244b5f91a9868f5c790f9a--659aed4fbe62478fb494e2ff7854892d
92047d611e044798b7c96305de3cf8ad
RX(p1₂₁)
659aed4fbe62478fb494e2ff7854892d--92047d611e044798b7c96305de3cf8ad
fc75cf519a09480f879e5f9ab33ee0ca
X
92047d611e044798b7c96305de3cf8ad--fc75cf519a09480f879e5f9ab33ee0ca
fc75cf519a09480f879e5f9ab33ee0ca--a34c4a1306bd49b7999fab84508c70af
84b3333f4228445cacba2c6b8dfe3ce0
fc75cf519a09480f879e5f9ab33ee0ca--84b3333f4228445cacba2c6b8dfe3ce0
ba7055bc8dc94f72adbae2a57a9a00ca
RX(p2₁)
84b3333f4228445cacba2c6b8dfe3ce0--ba7055bc8dc94f72adbae2a57a9a00ca
6bf80815af9b45a4a315d78299f358b6
RY(p2₅)
ba7055bc8dc94f72adbae2a57a9a00ca--6bf80815af9b45a4a315d78299f358b6
f332baf673e349dea2897c40a3c37dc8
RX(p2₉)
6bf80815af9b45a4a315d78299f358b6--f332baf673e349dea2897c40a3c37dc8
c86ab1a42dfa455fb976d1489507b8d7
X
f332baf673e349dea2897c40a3c37dc8--c86ab1a42dfa455fb976d1489507b8d7
c86ab1a42dfa455fb976d1489507b8d7--83eac902af544ca6b0f12b5ad6015bad
b389c0478e5142508b3169329ad15ae7
c86ab1a42dfa455fb976d1489507b8d7--b389c0478e5142508b3169329ad15ae7
55dc0e7725d047cfb9032f53dd26373f
RX(p2₁₃)
b389c0478e5142508b3169329ad15ae7--55dc0e7725d047cfb9032f53dd26373f
2831a48c38e543d2ac0be7964f853c21
RY(p2₁₇)
55dc0e7725d047cfb9032f53dd26373f--2831a48c38e543d2ac0be7964f853c21
cf7eaefbb9a44434a180b57a0ae334d7
RX(p2₂₁)
2831a48c38e543d2ac0be7964f853c21--cf7eaefbb9a44434a180b57a0ae334d7
0e8c6acd046945dd9fa3cdde7b592eb0
X
cf7eaefbb9a44434a180b57a0ae334d7--0e8c6acd046945dd9fa3cdde7b592eb0
0e8c6acd046945dd9fa3cdde7b592eb0--7a36c94c8ca24ac3b793a92747f83b98
6295c204dac04cbd9b70ff6ea6378ba0
0e8c6acd046945dd9fa3cdde7b592eb0--6295c204dac04cbd9b70ff6ea6378ba0
6295c204dac04cbd9b70ff6ea6378ba0--d2eeef02492a42d9b2a7ab77c29ce50a
53f3780de27e4d35aea8dd6321b664f6
751e5b518e774b66ab34209dd380d7f4
RX(p1₂)
92af7971f19d4691b687ff19791251c4--751e5b518e774b66ab34209dd380d7f4
2d18136ef6ad453ab1ddad3b06f5a0dc
3
3febf7776c1545db8e0fe3af5af23fa0
RY(p1₆)
751e5b518e774b66ab34209dd380d7f4--3febf7776c1545db8e0fe3af5af23fa0
559dac7658c94b48a92fd10af3c4d782
RX(p1₁₀)
3febf7776c1545db8e0fe3af5af23fa0--559dac7658c94b48a92fd10af3c4d782
a9ab8490e9d94853a91ce80b81656cc8
559dac7658c94b48a92fd10af3c4d782--a9ab8490e9d94853a91ce80b81656cc8
6e3a7ac8e3d845889875cffe99b4d528
X
a9ab8490e9d94853a91ce80b81656cc8--6e3a7ac8e3d845889875cffe99b4d528
6e3a7ac8e3d845889875cffe99b4d528--ba374055e0434c54b2216933f47ca30e
14b5859ee06b4f6fa15aa216134dd711
RX(p1₁₄)
6e3a7ac8e3d845889875cffe99b4d528--14b5859ee06b4f6fa15aa216134dd711
e79dcca091ac48728810be6b583f05b7
RY(p1₁₈)
14b5859ee06b4f6fa15aa216134dd711--e79dcca091ac48728810be6b583f05b7
74460a48ddce4123a2bbcac840c98e21
RX(p1₂₂)
e79dcca091ac48728810be6b583f05b7--74460a48ddce4123a2bbcac840c98e21
e6b50624847b4bc3a4c94b180333959e
74460a48ddce4123a2bbcac840c98e21--e6b50624847b4bc3a4c94b180333959e
9d33c4c213f84ef990a602459e6ff521
X
e6b50624847b4bc3a4c94b180333959e--9d33c4c213f84ef990a602459e6ff521
9d33c4c213f84ef990a602459e6ff521--84b3333f4228445cacba2c6b8dfe3ce0
6cbec806f04941c6a71273ae0590cb0d
RX(p2₂)
9d33c4c213f84ef990a602459e6ff521--6cbec806f04941c6a71273ae0590cb0d
582d5a72ffd04af8ac335123d9e7e02d
RY(p2₆)
6cbec806f04941c6a71273ae0590cb0d--582d5a72ffd04af8ac335123d9e7e02d
f073738396db441e8a616fce8dec3685
RX(p2₁₀)
582d5a72ffd04af8ac335123d9e7e02d--f073738396db441e8a616fce8dec3685
c86519d44ae6480d9aa6980bbbc0e5ad
f073738396db441e8a616fce8dec3685--c86519d44ae6480d9aa6980bbbc0e5ad
68467b169ba94c3289322328950e62d1
X
c86519d44ae6480d9aa6980bbbc0e5ad--68467b169ba94c3289322328950e62d1
68467b169ba94c3289322328950e62d1--b389c0478e5142508b3169329ad15ae7
49db20ac83734795a24f5a67771d7f09
RX(p2₁₄)
68467b169ba94c3289322328950e62d1--49db20ac83734795a24f5a67771d7f09
6294d9d9f7e34c8bbecab9c261262147
RY(p2₁₈)
49db20ac83734795a24f5a67771d7f09--6294d9d9f7e34c8bbecab9c261262147
141fbb09449045eb87a3856cbeae7404
RX(p2₂₂)
6294d9d9f7e34c8bbecab9c261262147--141fbb09449045eb87a3856cbeae7404
12aaa0df243c4d26a83e1fc65830a828
141fbb09449045eb87a3856cbeae7404--12aaa0df243c4d26a83e1fc65830a828
161ee238f3834a5ea9e313dfeda5fe92
X
12aaa0df243c4d26a83e1fc65830a828--161ee238f3834a5ea9e313dfeda5fe92
161ee238f3834a5ea9e313dfeda5fe92--6295c204dac04cbd9b70ff6ea6378ba0
161ee238f3834a5ea9e313dfeda5fe92--53f3780de27e4d35aea8dd6321b664f6
b7f86c48211b403190808c366d13c0e1
9ed384201bc44d0ca5261fc20e826e71
RX(p1₃)
2d18136ef6ad453ab1ddad3b06f5a0dc--9ed384201bc44d0ca5261fc20e826e71
376ddce1cc7940f392d121bb792550e0
RY(p1₇)
9ed384201bc44d0ca5261fc20e826e71--376ddce1cc7940f392d121bb792550e0
33744845507b4d3f902823352beab81b
RX(p1₁₁)
376ddce1cc7940f392d121bb792550e0--33744845507b4d3f902823352beab81b
142556fc74cf473190c79973d6f22167
X
33744845507b4d3f902823352beab81b--142556fc74cf473190c79973d6f22167
142556fc74cf473190c79973d6f22167--a9ab8490e9d94853a91ce80b81656cc8
b70a5fb5a3cd4a67b84f7aabfaadf958
142556fc74cf473190c79973d6f22167--b70a5fb5a3cd4a67b84f7aabfaadf958
8a9126c99a264bb8bdb144fe3d1b1caa
RX(p1₁₅)
b70a5fb5a3cd4a67b84f7aabfaadf958--8a9126c99a264bb8bdb144fe3d1b1caa
88601752828b4070b0204b6e51e85da1
RY(p1₁₉)
8a9126c99a264bb8bdb144fe3d1b1caa--88601752828b4070b0204b6e51e85da1
0f6be8f4631e4145a864504e1ae5588f
RX(p1₂₃)
88601752828b4070b0204b6e51e85da1--0f6be8f4631e4145a864504e1ae5588f
a142a3007cd24b8e931a75a09d062f7c
X
0f6be8f4631e4145a864504e1ae5588f--a142a3007cd24b8e931a75a09d062f7c
a142a3007cd24b8e931a75a09d062f7c--e6b50624847b4bc3a4c94b180333959e
3d826b201c16406db214e6db91573fcd
a142a3007cd24b8e931a75a09d062f7c--3d826b201c16406db214e6db91573fcd
50bf5bd6ebd449d599d543c16bbdebc3
RX(p2₃)
3d826b201c16406db214e6db91573fcd--50bf5bd6ebd449d599d543c16bbdebc3
5857e5c605dd4f4892bb0f70034b5033
RY(p2₇)
50bf5bd6ebd449d599d543c16bbdebc3--5857e5c605dd4f4892bb0f70034b5033
79fedd2def1b4bf4b388dc47f61a5cbf
RX(p2₁₁)
5857e5c605dd4f4892bb0f70034b5033--79fedd2def1b4bf4b388dc47f61a5cbf
2c8a2c123b2743438cbd1686f9412fdb
X
79fedd2def1b4bf4b388dc47f61a5cbf--2c8a2c123b2743438cbd1686f9412fdb
2c8a2c123b2743438cbd1686f9412fdb--c86519d44ae6480d9aa6980bbbc0e5ad
7b1ff48e55664c96bd8b54b57e46c39a
2c8a2c123b2743438cbd1686f9412fdb--7b1ff48e55664c96bd8b54b57e46c39a
0c30250f5b7b49579c8208bcfda191d0
RX(p2₁₅)
7b1ff48e55664c96bd8b54b57e46c39a--0c30250f5b7b49579c8208bcfda191d0
23b26f7ed8a144b48055ab5134c0b445
RY(p2₁₉)
0c30250f5b7b49579c8208bcfda191d0--23b26f7ed8a144b48055ab5134c0b445
2fadc9dd01f14044b9cca7d862b82691
RX(p2₂₃)
23b26f7ed8a144b48055ab5134c0b445--2fadc9dd01f14044b9cca7d862b82691
74adac043ab14956888312012bf12cfc
X
2fadc9dd01f14044b9cca7d862b82691--74adac043ab14956888312012bf12cfc
74adac043ab14956888312012bf12cfc--12aaa0df243c4d26a83e1fc65830a828
a72275fbbd954818b1e6c6e746c80828
74adac043ab14956888312012bf12cfc--a72275fbbd954818b1e6c6e746c80828
a72275fbbd954818b1e6c6e746c80828--b7f86c48211b403190808c366d13c0e1
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.6032 ] )) , (' t he ta _ 0 ' , tens or( [ 0.7060 ] )) , (' t he ta _ 1 ' , tens or( [ 0.8729 ] )) , (' t he ta _ 10 ' , tens or( [ 0.5824 ] )) , (' t he ta _ 11 ' , tens or( [ 0.7651 ] )) , (' t he ta _ 12 ' , tens or( [ 0.7259 ] )) , (' t he ta _ 13 ' , tens or( [ 0.8999 ] )) , (' t he ta _ 14 ' , tens or( [ 0.5249 ] )) , (' t he ta _ 15 ' , tens or( [ 0.8056 ] )) , (' t he ta _ 16 ' , tens or( [ 0.8753 ] )) , (' t he ta _ 17 ' , tens or( [ 0.9508 ] )) , (' t he ta _ 18 ' , tens or( [ 0.5994 ] )) , (' t he ta _ 19 ' , tens or( [ 0.5960 ] )) , (' t he ta _ 2 ' , tens or( [ 0.3586 ] )) , (' t he ta _ 20 ' , tens or( [ 0.0068 ] )) , (' t he ta _ 21 ' , tens or( [ 0.4744 ] )) , (' t he ta _ 22 ' , tens or( [ 0.3152 ] )) , (' t he ta _ 23 ' , tens or( [ 0.4480 ] )) , (' t he ta _ 3 ' , tens or( [ 0.7231 ] )) , (' t he ta _ 4 ' , tens or( [ 0.2878 ] )) , (' t he ta _ 5 ' , tens or( [ 0.8199 ] )) , (' t he ta _ 6 ' , tens or( [ 0.4943 ] )) , (' t he ta _ 7 ' , tens or( [ 0.6892 ] )) , (' t he ta _ 8 ' , tens or( [ 0.0667 ] )) , (' t he ta _ 9 ' , tens or( [ 0.9967 ] )) ] )
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.6022 ] )) , (' t he ta _ 0 ' , tens or( [ 0.7070 ] )) , (' t he ta _ 1 ' , tens or( [ 0.8719 ] )) , (' t he ta _ 10 ' , tens or( [ 0.5834 ] )) , (' t he ta _ 11 ' , tens or( [ 0.7661 ] )) , (' t he ta _ 12 ' , tens or( [ 0.7269 ] )) , (' t he ta _ 13 ' , tens or( [ 0.9009 ] )) , (' t he ta _ 14 ' , tens or( [ 0.5259 ] )) , (' t he ta _ 15 ' , tens or( [ 0.8066 ] )) , (' t he ta _ 16 ' , tens or( [ 0.8763 ] )) , (' t he ta _ 17 ' , tens or( [ 0.9518 ] )) , (' t he ta _ 18 ' , tens or( [ 0.5984 ] )) , (' t he ta _ 19 ' , tens or( [ 0.5970 ] )) , (' t he ta _ 2 ' , tens or( [ 0.3596 ] )) , (' t he ta _ 20 ' , tens or( [ 0.0078 ] )) , (' t he ta _ 21 ' , tens or( [ 0.4754 ] )) , (' t he ta _ 22 ' , tens or( [ 0.3162 ] )) , (' t he ta _ 23 ' , tens or( [ 0.4490 ] )) , (' t he ta _ 3 ' , tens or( [ 0.7241 ] )) , (' t he ta _ 4 ' , tens or( [ 0.2888 ] )) , (' t he ta _ 5 ' , tens or( [ 0.8209 ] )) , (' t he ta _ 6 ' , tens or( [ 0.4953 ] )) , (' t he ta _ 7 ' , tens or( [ 0.6902 ] )) , (' t he ta _ 8 ' , tens or( [ 0.0677 ] )) , (' t he ta _ 9 ' , tens or( [ 0.9957 ] )) ] )
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 ]] )