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_6d7d116101f344b3abe1688dffb68cd8
[* 2]
cluster_56f78e1a29804bb2b6ba63ebaee7ae3e
Rotations
8a696d08e96345269c1cd66dd00b97c2
0
c229fac778154677a406c108fcb3ca39
RX(phi/theta)
8a696d08e96345269c1cd66dd00b97c2--c229fac778154677a406c108fcb3ca39
d6435d8d1f4447d0ae6d6b9ad7c4a47c
1
4b45157c750b4875bb90f0fd847ba2fb
RX(phi)
c229fac778154677a406c108fcb3ca39--4b45157c750b4875bb90f0fd847ba2fb
10d3d3af55694bc1b3ea1a82de94659f
RX(phi)
4b45157c750b4875bb90f0fd847ba2fb--10d3d3af55694bc1b3ea1a82de94659f
f5cca5a61f6940798772bb6d0d4247e2
RX(phi + theta)
10d3d3af55694bc1b3ea1a82de94659f--f5cca5a61f6940798772bb6d0d4247e2
f80bd838da194b7d83b7aa29a491e092
f5cca5a61f6940798772bb6d0d4247e2--f80bd838da194b7d83b7aa29a491e092
f954636407fa41f2bf320da76187d680
f80bd838da194b7d83b7aa29a491e092--f954636407fa41f2bf320da76187d680
8be06a8eb1c74cd39d3e9230eccbbf1d
Z
f954636407fa41f2bf320da76187d680--8be06a8eb1c74cd39d3e9230eccbbf1d
e48edac2320048f3866a16cccd4a16f8
8be06a8eb1c74cd39d3e9230eccbbf1d--e48edac2320048f3866a16cccd4a16f8
37d4a0cbfef147e9bff5c1357e19b02f
b9fce6c0d6b2472191db04f0670cc04b
RY(2*theta)
d6435d8d1f4447d0ae6d6b9ad7c4a47c--b9fce6c0d6b2472191db04f0670cc04b
a0476b86c67e40ff9ef2554f75c53f34
2
830b7e3f7a4b445eae7df9f85199e909
RY(theta)
b9fce6c0d6b2472191db04f0670cc04b--830b7e3f7a4b445eae7df9f85199e909
a4f88c02007a4555b18936a5d2e2ee77
RY(theta)
830b7e3f7a4b445eae7df9f85199e909--a4f88c02007a4555b18936a5d2e2ee77
2a81c3f0c2ac49a1bb2f1d95c74338fc
RY(theta**2)
a4f88c02007a4555b18936a5d2e2ee77--2a81c3f0c2ac49a1bb2f1d95c74338fc
06e0ebb3eadd48a998d7bb929a1632c5
X
2a81c3f0c2ac49a1bb2f1d95c74338fc--06e0ebb3eadd48a998d7bb929a1632c5
06e0ebb3eadd48a998d7bb929a1632c5--f80bd838da194b7d83b7aa29a491e092
0807a95d9be7498c87b523717d4e3381
06e0ebb3eadd48a998d7bb929a1632c5--0807a95d9be7498c87b523717d4e3381
13ce3eb1a1204408972c7b886713dddb
Z
0807a95d9be7498c87b523717d4e3381--13ce3eb1a1204408972c7b886713dddb
13ce3eb1a1204408972c7b886713dddb--37d4a0cbfef147e9bff5c1357e19b02f
1d7df57453914d589989d76aef7edd1f
8a11a41831e14e97ab828c7235b212fe
RZ(cos(phi))
a0476b86c67e40ff9ef2554f75c53f34--8a11a41831e14e97ab828c7235b212fe
d75814d3ca6c47ddab8c0851cf6f1ee4
RZ(phi)
8a11a41831e14e97ab828c7235b212fe--d75814d3ca6c47ddab8c0851cf6f1ee4
8a1f7875fcdf43739cbd08763ba58a37
RZ(phi)
d75814d3ca6c47ddab8c0851cf6f1ee4--8a1f7875fcdf43739cbd08763ba58a37
6ce235a29ab044a890d30cb029641dad
RZ(cos(phi))
8a1f7875fcdf43739cbd08763ba58a37--6ce235a29ab044a890d30cb029641dad
4c8d0e816124448699a12a27c7699c9f
6ce235a29ab044a890d30cb029641dad--4c8d0e816124448699a12a27c7699c9f
bbc8db87edcd4a3b8c566d023d1a4f92
X
4c8d0e816124448699a12a27c7699c9f--bbc8db87edcd4a3b8c566d023d1a4f92
bbc8db87edcd4a3b8c566d023d1a4f92--0807a95d9be7498c87b523717d4e3381
5ed91794300247cda33e5c27b6d9775c
Z
bbc8db87edcd4a3b8c566d023d1a4f92--5ed91794300247cda33e5c27b6d9775c
5ed91794300247cda33e5c27b6d9775c--1d7df57453914d589989d76aef7edd1f
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
0c66b21616704b0c805616fcc9acd0d3
0
e6c6beadd6fa456690959fb48e0a63ac
RX(theta₀)
0c66b21616704b0c805616fcc9acd0d3--e6c6beadd6fa456690959fb48e0a63ac
f6ffa6a2554949df96c7daad5b3e0a40
1
9f3e53d7cbc74ca18a0a51d9be809173
RY(theta₄)
e6c6beadd6fa456690959fb48e0a63ac--9f3e53d7cbc74ca18a0a51d9be809173
6e41c2adefd54c33a3a3663e0541d34e
RX(theta₈)
9f3e53d7cbc74ca18a0a51d9be809173--6e41c2adefd54c33a3a3663e0541d34e
ba35dd84ce2e40d386526e1282a86182
6e41c2adefd54c33a3a3663e0541d34e--ba35dd84ce2e40d386526e1282a86182
a20dd91112cc488f994283cb1a40fe32
ba35dd84ce2e40d386526e1282a86182--a20dd91112cc488f994283cb1a40fe32
2dd59f6ac07f48c182e90480dc193d56
RX(theta₁₂)
a20dd91112cc488f994283cb1a40fe32--2dd59f6ac07f48c182e90480dc193d56
8c7869e6c0bb4529b623177ca9950718
RY(theta₁₆)
2dd59f6ac07f48c182e90480dc193d56--8c7869e6c0bb4529b623177ca9950718
7e863a1fbed0412b9510b53621db1d0e
RX(theta₂₀)
8c7869e6c0bb4529b623177ca9950718--7e863a1fbed0412b9510b53621db1d0e
9eeacce2620845219f6ebaa68f6c5246
7e863a1fbed0412b9510b53621db1d0e--9eeacce2620845219f6ebaa68f6c5246
05b7b3e1bf5e46bda7a92e65e291e6d5
9eeacce2620845219f6ebaa68f6c5246--05b7b3e1bf5e46bda7a92e65e291e6d5
6f87b725699940aeb2f8beb07b1f0bc3
05b7b3e1bf5e46bda7a92e65e291e6d5--6f87b725699940aeb2f8beb07b1f0bc3
97114e0773e94aae88a6cdf6ecbfd858
87f6c9131e2a491eb0645b82ea89b0b0
RX(theta₁)
f6ffa6a2554949df96c7daad5b3e0a40--87f6c9131e2a491eb0645b82ea89b0b0
987a43d56c8d4b71b0391bdc56a8dde7
2
90dfcc4640e44dfe83b2f7776ae495a1
RY(theta₅)
87f6c9131e2a491eb0645b82ea89b0b0--90dfcc4640e44dfe83b2f7776ae495a1
f0e3ab95db794dc98da6deb8dcce6fcb
RX(theta₉)
90dfcc4640e44dfe83b2f7776ae495a1--f0e3ab95db794dc98da6deb8dcce6fcb
c123cdcbad394b1e9305b688d4606d58
X
f0e3ab95db794dc98da6deb8dcce6fcb--c123cdcbad394b1e9305b688d4606d58
c123cdcbad394b1e9305b688d4606d58--ba35dd84ce2e40d386526e1282a86182
f393de322c2b4f86a3c89581e1826190
c123cdcbad394b1e9305b688d4606d58--f393de322c2b4f86a3c89581e1826190
ce1506f6c0124826a989bf23b9132b02
RX(theta₁₃)
f393de322c2b4f86a3c89581e1826190--ce1506f6c0124826a989bf23b9132b02
5a256523f74b45c6b55c34996ededd55
RY(theta₁₇)
ce1506f6c0124826a989bf23b9132b02--5a256523f74b45c6b55c34996ededd55
3d0956e70c4746509eb9c125fb02beea
RX(theta₂₁)
5a256523f74b45c6b55c34996ededd55--3d0956e70c4746509eb9c125fb02beea
623c2069145d4cb1b5668486196b0f60
X
3d0956e70c4746509eb9c125fb02beea--623c2069145d4cb1b5668486196b0f60
623c2069145d4cb1b5668486196b0f60--9eeacce2620845219f6ebaa68f6c5246
7abe6e0c2bab44e7b0ec893868c9944e
623c2069145d4cb1b5668486196b0f60--7abe6e0c2bab44e7b0ec893868c9944e
7abe6e0c2bab44e7b0ec893868c9944e--97114e0773e94aae88a6cdf6ecbfd858
6948ec7ce5484026935ce0123f7a79e7
db7d65d427fa43d5ab26e228c7eda278
RX(theta₂)
987a43d56c8d4b71b0391bdc56a8dde7--db7d65d427fa43d5ab26e228c7eda278
a7afa03c50a944d8b237a6911323ea0b
3
d71f210849584edc9c9a6b21dfe81045
RY(theta₆)
db7d65d427fa43d5ab26e228c7eda278--d71f210849584edc9c9a6b21dfe81045
fb88cf0a2eff4103b156be9fd6c2c617
RX(theta₁₀)
d71f210849584edc9c9a6b21dfe81045--fb88cf0a2eff4103b156be9fd6c2c617
18489cae08c0483bb8956ba7f1a1a33c
fb88cf0a2eff4103b156be9fd6c2c617--18489cae08c0483bb8956ba7f1a1a33c
7235acfa34de4dea9c5c6e8524c34fc4
X
18489cae08c0483bb8956ba7f1a1a33c--7235acfa34de4dea9c5c6e8524c34fc4
7235acfa34de4dea9c5c6e8524c34fc4--f393de322c2b4f86a3c89581e1826190
7b2e2972554948ccbe9defe5c0317946
RX(theta₁₄)
7235acfa34de4dea9c5c6e8524c34fc4--7b2e2972554948ccbe9defe5c0317946
cb3ba2fbbb7f4273a879ae2c56e47da1
RY(theta₁₈)
7b2e2972554948ccbe9defe5c0317946--cb3ba2fbbb7f4273a879ae2c56e47da1
cfadd91759094a358fbba053e549ef3e
RX(theta₂₂)
cb3ba2fbbb7f4273a879ae2c56e47da1--cfadd91759094a358fbba053e549ef3e
7d69e37bdb38444ba73164b1c7396f6b
cfadd91759094a358fbba053e549ef3e--7d69e37bdb38444ba73164b1c7396f6b
fdb82c1132b14854aca4d41f52d30c90
X
7d69e37bdb38444ba73164b1c7396f6b--fdb82c1132b14854aca4d41f52d30c90
fdb82c1132b14854aca4d41f52d30c90--7abe6e0c2bab44e7b0ec893868c9944e
fdb82c1132b14854aca4d41f52d30c90--6948ec7ce5484026935ce0123f7a79e7
e7e323846df346ab974f1ea3731cc77f
07f56cb98fcc4b73933d8390c422ee6e
RX(theta₃)
a7afa03c50a944d8b237a6911323ea0b--07f56cb98fcc4b73933d8390c422ee6e
4b90cb86fc59451a884feb4b69f76052
RY(theta₇)
07f56cb98fcc4b73933d8390c422ee6e--4b90cb86fc59451a884feb4b69f76052
c2bbbda6cdcc442c97684200bc8c8c06
RX(theta₁₁)
4b90cb86fc59451a884feb4b69f76052--c2bbbda6cdcc442c97684200bc8c8c06
b882350181b4450cafdcc1529ff61fe1
X
c2bbbda6cdcc442c97684200bc8c8c06--b882350181b4450cafdcc1529ff61fe1
b882350181b4450cafdcc1529ff61fe1--18489cae08c0483bb8956ba7f1a1a33c
5f6c651074b247ecbbfe38c1eaa6b952
b882350181b4450cafdcc1529ff61fe1--5f6c651074b247ecbbfe38c1eaa6b952
54f6b0e2065f4557811734abba0fee9d
RX(theta₁₅)
5f6c651074b247ecbbfe38c1eaa6b952--54f6b0e2065f4557811734abba0fee9d
caead0abfd5a4d6bb732cea2bfb208eb
RY(theta₁₉)
54f6b0e2065f4557811734abba0fee9d--caead0abfd5a4d6bb732cea2bfb208eb
7f2b1af05ea14e029a7c9d0e3d967d63
RX(theta₂₃)
caead0abfd5a4d6bb732cea2bfb208eb--7f2b1af05ea14e029a7c9d0e3d967d63
b780b7ce6ab0478ebc36e83bd4d8e4fb
X
7f2b1af05ea14e029a7c9d0e3d967d63--b780b7ce6ab0478ebc36e83bd4d8e4fb
b780b7ce6ab0478ebc36e83bd4d8e4fb--7d69e37bdb38444ba73164b1c7396f6b
05c16c51c50449148963718ea0bf8328
b780b7ce6ab0478ebc36e83bd4d8e4fb--05c16c51c50449148963718ea0bf8328
05c16c51c50449148963718ea0bf8328--e7e323846df346ab974f1ea3731cc77f
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_46c80d1ac81d43ae9be646e456e5cba5
HEA
cluster_71acd74fa4f145019fef3bcb186371b7
HEA
1adb912f44b84230ae0604bb20475c80
0
8c46b614e9774a10acd7b227afcecea9
RX(theta₀)
1adb912f44b84230ae0604bb20475c80--8c46b614e9774a10acd7b227afcecea9
6d38c26a64484a0185273b8ce80fc595
1
d95e5eaba2c84a0b94f66cf9f09b1ad2
RY(theta₄)
8c46b614e9774a10acd7b227afcecea9--d95e5eaba2c84a0b94f66cf9f09b1ad2
af71c679b7b74254b03c7e7629ba4dcd
RX(theta₈)
d95e5eaba2c84a0b94f66cf9f09b1ad2--af71c679b7b74254b03c7e7629ba4dcd
18cbe6429fde4096a746c38c721b7d0a
af71c679b7b74254b03c7e7629ba4dcd--18cbe6429fde4096a746c38c721b7d0a
a0213f83a50e4010b627ad96d08e20fa
18cbe6429fde4096a746c38c721b7d0a--a0213f83a50e4010b627ad96d08e20fa
498b5393bc7b4f758d0296a756fa8fe1
RX(theta₁₂)
a0213f83a50e4010b627ad96d08e20fa--498b5393bc7b4f758d0296a756fa8fe1
7dc3c78d085f4409b8889c5765ea8f8d
RY(theta₁₆)
498b5393bc7b4f758d0296a756fa8fe1--7dc3c78d085f4409b8889c5765ea8f8d
708377b2d6134f538f2b9a7a81c21133
RX(theta₂₀)
7dc3c78d085f4409b8889c5765ea8f8d--708377b2d6134f538f2b9a7a81c21133
2f07fc1429c144f3911e6d12b08b8cab
708377b2d6134f538f2b9a7a81c21133--2f07fc1429c144f3911e6d12b08b8cab
8ae0c0eeee024f46a70d9cabea63ba78
2f07fc1429c144f3911e6d12b08b8cab--8ae0c0eeee024f46a70d9cabea63ba78
caa97758a98649aa941a06651ab0c024
RX(theta₀)
8ae0c0eeee024f46a70d9cabea63ba78--caa97758a98649aa941a06651ab0c024
0b273292a6464102b0b22340c9c04ee4
RY(theta₄)
caa97758a98649aa941a06651ab0c024--0b273292a6464102b0b22340c9c04ee4
024d8d4a25dc4228911d8504283dc92f
RX(theta₈)
0b273292a6464102b0b22340c9c04ee4--024d8d4a25dc4228911d8504283dc92f
c71c050ab091410cb992b993eaafe098
024d8d4a25dc4228911d8504283dc92f--c71c050ab091410cb992b993eaafe098
db5475c3947e456281ee79909d212f5c
c71c050ab091410cb992b993eaafe098--db5475c3947e456281ee79909d212f5c
9a9a79c9c6034bc9bfc38e620940e1e4
RX(theta₁₂)
db5475c3947e456281ee79909d212f5c--9a9a79c9c6034bc9bfc38e620940e1e4
7c51a949f5614582924393f3e0bfccb7
RY(theta₁₆)
9a9a79c9c6034bc9bfc38e620940e1e4--7c51a949f5614582924393f3e0bfccb7
fa292b89625d4052a9ad2a5b98aac0df
RX(theta₂₀)
7c51a949f5614582924393f3e0bfccb7--fa292b89625d4052a9ad2a5b98aac0df
b3cac5f2459c490f8418d389e4340f76
fa292b89625d4052a9ad2a5b98aac0df--b3cac5f2459c490f8418d389e4340f76
09c81a95742743d29eff946e52335bfe
b3cac5f2459c490f8418d389e4340f76--09c81a95742743d29eff946e52335bfe
fadf126e4122464eb4c7637bfa89d96c
09c81a95742743d29eff946e52335bfe--fadf126e4122464eb4c7637bfa89d96c
5d1ee5f1dac7419683c6658196c93a7a
3c2d008bbb0b4992ae1e7a1c7c9223b5
RX(theta₁)
6d38c26a64484a0185273b8ce80fc595--3c2d008bbb0b4992ae1e7a1c7c9223b5
7cd84bdcbe1344949792ef93a6cb1af2
2
05f87efd35094e5890fa0deffeaf4512
RY(theta₅)
3c2d008bbb0b4992ae1e7a1c7c9223b5--05f87efd35094e5890fa0deffeaf4512
86628fef28954896b02bc63495558f0e
RX(theta₉)
05f87efd35094e5890fa0deffeaf4512--86628fef28954896b02bc63495558f0e
9e697d2dcb0f40ed9b65aa18a2a65cbc
X
86628fef28954896b02bc63495558f0e--9e697d2dcb0f40ed9b65aa18a2a65cbc
9e697d2dcb0f40ed9b65aa18a2a65cbc--18cbe6429fde4096a746c38c721b7d0a
a91e3ca1625d43dcb188d9dc704d3a84
9e697d2dcb0f40ed9b65aa18a2a65cbc--a91e3ca1625d43dcb188d9dc704d3a84
7d45815aba504263bd3e708eddaef546
RX(theta₁₃)
a91e3ca1625d43dcb188d9dc704d3a84--7d45815aba504263bd3e708eddaef546
08a98fa23dcb40f68d5afea8b2a172bc
RY(theta₁₇)
7d45815aba504263bd3e708eddaef546--08a98fa23dcb40f68d5afea8b2a172bc
947e8b894690415392f006c69826b460
RX(theta₂₁)
08a98fa23dcb40f68d5afea8b2a172bc--947e8b894690415392f006c69826b460
23ab4df27689467e9ae801e223930b58
X
947e8b894690415392f006c69826b460--23ab4df27689467e9ae801e223930b58
23ab4df27689467e9ae801e223930b58--2f07fc1429c144f3911e6d12b08b8cab
eda92bdacedf47da8ef9de54fe56c0fd
23ab4df27689467e9ae801e223930b58--eda92bdacedf47da8ef9de54fe56c0fd
3c834054c2ea4ce297e796f88ebcc148
RX(theta₁)
eda92bdacedf47da8ef9de54fe56c0fd--3c834054c2ea4ce297e796f88ebcc148
0053eeed143041bbb1d2de4307cf2025
RY(theta₅)
3c834054c2ea4ce297e796f88ebcc148--0053eeed143041bbb1d2de4307cf2025
477f4e883cfc4839951e5a39a12a4d78
RX(theta₉)
0053eeed143041bbb1d2de4307cf2025--477f4e883cfc4839951e5a39a12a4d78
f7725c56c50b47a7a5ed31f23fb17f2e
X
477f4e883cfc4839951e5a39a12a4d78--f7725c56c50b47a7a5ed31f23fb17f2e
f7725c56c50b47a7a5ed31f23fb17f2e--c71c050ab091410cb992b993eaafe098
efe8d8dddccf4a6c8a6a82850e7c8f5c
f7725c56c50b47a7a5ed31f23fb17f2e--efe8d8dddccf4a6c8a6a82850e7c8f5c
e4dd15e5cc494540b8a9dc7b1ddf4c77
RX(theta₁₃)
efe8d8dddccf4a6c8a6a82850e7c8f5c--e4dd15e5cc494540b8a9dc7b1ddf4c77
601391c479c947269234e4971cc940c9
RY(theta₁₇)
e4dd15e5cc494540b8a9dc7b1ddf4c77--601391c479c947269234e4971cc940c9
2b28ea61c8c8481c84915d54c65e27c7
RX(theta₂₁)
601391c479c947269234e4971cc940c9--2b28ea61c8c8481c84915d54c65e27c7
9f84d514bd454830ab7e939c91219881
X
2b28ea61c8c8481c84915d54c65e27c7--9f84d514bd454830ab7e939c91219881
9f84d514bd454830ab7e939c91219881--b3cac5f2459c490f8418d389e4340f76
0fa0222bf7294aa096aca1ce4edd18a1
9f84d514bd454830ab7e939c91219881--0fa0222bf7294aa096aca1ce4edd18a1
0fa0222bf7294aa096aca1ce4edd18a1--5d1ee5f1dac7419683c6658196c93a7a
87f365e90dea47fcbaabcf9048de5e1f
dc8e9f867b3840fe85afa10e64a4764e
RX(theta₂)
7cd84bdcbe1344949792ef93a6cb1af2--dc8e9f867b3840fe85afa10e64a4764e
c908c77792d44ae89a3a1538732f59e1
3
5cb6f99c1b704448b30a225620ad5169
RY(theta₆)
dc8e9f867b3840fe85afa10e64a4764e--5cb6f99c1b704448b30a225620ad5169
74bad092b4b9416baa45fb84929a4205
RX(theta₁₀)
5cb6f99c1b704448b30a225620ad5169--74bad092b4b9416baa45fb84929a4205
5f78a8e5ac81492d9968026cdeac941e
74bad092b4b9416baa45fb84929a4205--5f78a8e5ac81492d9968026cdeac941e
c2afd60fac094a24a1fd8347f57812a1
X
5f78a8e5ac81492d9968026cdeac941e--c2afd60fac094a24a1fd8347f57812a1
c2afd60fac094a24a1fd8347f57812a1--a91e3ca1625d43dcb188d9dc704d3a84
7d30e30733194013b3b20e36f75a194f
RX(theta₁₄)
c2afd60fac094a24a1fd8347f57812a1--7d30e30733194013b3b20e36f75a194f
3a5ae51e8c2c4230ad4328d4966c7d3f
RY(theta₁₈)
7d30e30733194013b3b20e36f75a194f--3a5ae51e8c2c4230ad4328d4966c7d3f
cee833d06d5a493686f47534f684ff6e
RX(theta₂₂)
3a5ae51e8c2c4230ad4328d4966c7d3f--cee833d06d5a493686f47534f684ff6e
a0583b14946542a3bc6873857ce21edf
cee833d06d5a493686f47534f684ff6e--a0583b14946542a3bc6873857ce21edf
f0fd99d982e2499ebf807947b54d6e6b
X
a0583b14946542a3bc6873857ce21edf--f0fd99d982e2499ebf807947b54d6e6b
f0fd99d982e2499ebf807947b54d6e6b--eda92bdacedf47da8ef9de54fe56c0fd
3b5c13a6b5a34c92afe948fcd8a30d2a
RX(theta₂)
f0fd99d982e2499ebf807947b54d6e6b--3b5c13a6b5a34c92afe948fcd8a30d2a
9a95f82e7ec74704aa4706e5814c5b0a
RY(theta₆)
3b5c13a6b5a34c92afe948fcd8a30d2a--9a95f82e7ec74704aa4706e5814c5b0a
225b0aa590cc48d08859f84e081b3969
RX(theta₁₀)
9a95f82e7ec74704aa4706e5814c5b0a--225b0aa590cc48d08859f84e081b3969
7325a02cba3e44af90cb3ed744e80c05
225b0aa590cc48d08859f84e081b3969--7325a02cba3e44af90cb3ed744e80c05
05a41d2e0605469e950f359c19a772d8
X
7325a02cba3e44af90cb3ed744e80c05--05a41d2e0605469e950f359c19a772d8
05a41d2e0605469e950f359c19a772d8--efe8d8dddccf4a6c8a6a82850e7c8f5c
696ed80bf4f248c3b9776a12f646b129
RX(theta₁₄)
05a41d2e0605469e950f359c19a772d8--696ed80bf4f248c3b9776a12f646b129
27540e743acd4ad8b054f7c06f0c93d2
RY(theta₁₈)
696ed80bf4f248c3b9776a12f646b129--27540e743acd4ad8b054f7c06f0c93d2
9eca397203a14ce0aeaed44b9d1b0c0f
RX(theta₂₂)
27540e743acd4ad8b054f7c06f0c93d2--9eca397203a14ce0aeaed44b9d1b0c0f
17363516dc9546ccabff326efc509e77
9eca397203a14ce0aeaed44b9d1b0c0f--17363516dc9546ccabff326efc509e77
d1ae230a60e14818aa0b0646389efe9e
X
17363516dc9546ccabff326efc509e77--d1ae230a60e14818aa0b0646389efe9e
d1ae230a60e14818aa0b0646389efe9e--0fa0222bf7294aa096aca1ce4edd18a1
d1ae230a60e14818aa0b0646389efe9e--87f365e90dea47fcbaabcf9048de5e1f
c77f96550d14459ab359bf6be800e48d
48e7c94786e74f26b0a25968f8523edf
RX(theta₃)
c908c77792d44ae89a3a1538732f59e1--48e7c94786e74f26b0a25968f8523edf
8542c805a3354104a99e80118de5fb04
RY(theta₇)
48e7c94786e74f26b0a25968f8523edf--8542c805a3354104a99e80118de5fb04
af50769160ce40bea848ff59b42d4161
RX(theta₁₁)
8542c805a3354104a99e80118de5fb04--af50769160ce40bea848ff59b42d4161
a0c18a50d44f44fab50f729349f41b21
X
af50769160ce40bea848ff59b42d4161--a0c18a50d44f44fab50f729349f41b21
a0c18a50d44f44fab50f729349f41b21--5f78a8e5ac81492d9968026cdeac941e
1506a7c30cb94eab83cb3f2ee9157e74
a0c18a50d44f44fab50f729349f41b21--1506a7c30cb94eab83cb3f2ee9157e74
21816fe3587544828fb0312426f5d69e
RX(theta₁₅)
1506a7c30cb94eab83cb3f2ee9157e74--21816fe3587544828fb0312426f5d69e
4d808870169e4c35a00b2a51b10bd3a2
RY(theta₁₉)
21816fe3587544828fb0312426f5d69e--4d808870169e4c35a00b2a51b10bd3a2
ef35b4bc269440a097b181f39e5e8bd1
RX(theta₂₃)
4d808870169e4c35a00b2a51b10bd3a2--ef35b4bc269440a097b181f39e5e8bd1
eb16bd0345ed42148453920f39e30450
X
ef35b4bc269440a097b181f39e5e8bd1--eb16bd0345ed42148453920f39e30450
eb16bd0345ed42148453920f39e30450--a0583b14946542a3bc6873857ce21edf
2ae5bf42c09d4207ad505775394ae584
eb16bd0345ed42148453920f39e30450--2ae5bf42c09d4207ad505775394ae584
26dc427d94c94804b0e432074e6085ab
RX(theta₃)
2ae5bf42c09d4207ad505775394ae584--26dc427d94c94804b0e432074e6085ab
6c7231f4315c405890c1f2a9293f0280
RY(theta₇)
26dc427d94c94804b0e432074e6085ab--6c7231f4315c405890c1f2a9293f0280
aeabadccee8142e7968f300e4ffadec7
RX(theta₁₁)
6c7231f4315c405890c1f2a9293f0280--aeabadccee8142e7968f300e4ffadec7
5c794ba905c7490db99489c8a78b0bbf
X
aeabadccee8142e7968f300e4ffadec7--5c794ba905c7490db99489c8a78b0bbf
5c794ba905c7490db99489c8a78b0bbf--7325a02cba3e44af90cb3ed744e80c05
e4f91a5649144159a37a63d2b9953745
5c794ba905c7490db99489c8a78b0bbf--e4f91a5649144159a37a63d2b9953745
b0c53639896b47cdb684c23fd0ab7bec
RX(theta₁₅)
e4f91a5649144159a37a63d2b9953745--b0c53639896b47cdb684c23fd0ab7bec
e6506a46311b4e0a94176bb5e433821a
RY(theta₁₉)
b0c53639896b47cdb684c23fd0ab7bec--e6506a46311b4e0a94176bb5e433821a
8e44ae7a49b146a9883399b7d6a46092
RX(theta₂₃)
e6506a46311b4e0a94176bb5e433821a--8e44ae7a49b146a9883399b7d6a46092
6414ed563e2b426f8a083438966b4041
X
8e44ae7a49b146a9883399b7d6a46092--6414ed563e2b426f8a083438966b4041
6414ed563e2b426f8a083438966b4041--17363516dc9546ccabff326efc509e77
54b0c89599a8430eaec17986514a4e28
6414ed563e2b426f8a083438966b4041--54b0c89599a8430eaec17986514a4e28
54b0c89599a8430eaec17986514a4e28--c77f96550d14459ab359bf6be800e48d
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_b3e162d0bce44d04ae5b95c8fe142e88
HEA
cluster_015269ab6e294b2e8a1aa7645c22b116
HEA
d9b2ca04f7184858878c4d83a476e487
0
0763f3fe400441d582ea717af16a94df
RX(p1₀)
d9b2ca04f7184858878c4d83a476e487--0763f3fe400441d582ea717af16a94df
2518d00d6c2945f18a9c960de7a5db67
1
11a43eba394343e9a2bf68a87ddb9f45
RY(p1₄)
0763f3fe400441d582ea717af16a94df--11a43eba394343e9a2bf68a87ddb9f45
920ae4a7538a43c3b47797b6bb9636b5
RX(p1₈)
11a43eba394343e9a2bf68a87ddb9f45--920ae4a7538a43c3b47797b6bb9636b5
fced09e37e1b4ded931888d667dd9124
920ae4a7538a43c3b47797b6bb9636b5--fced09e37e1b4ded931888d667dd9124
005fd516745a4baea68ead6b03e44196
fced09e37e1b4ded931888d667dd9124--005fd516745a4baea68ead6b03e44196
c21035a759f8462ea2cef092d708f57e
RX(p1₁₂)
005fd516745a4baea68ead6b03e44196--c21035a759f8462ea2cef092d708f57e
3ed624e729fd44a59a5809b43da6f0ed
RY(p1₁₆)
c21035a759f8462ea2cef092d708f57e--3ed624e729fd44a59a5809b43da6f0ed
5bf0d48316074a47bbad6b7f7cba058c
RX(p1₂₀)
3ed624e729fd44a59a5809b43da6f0ed--5bf0d48316074a47bbad6b7f7cba058c
a0c5c9779b984ddfabf732a0791b010a
5bf0d48316074a47bbad6b7f7cba058c--a0c5c9779b984ddfabf732a0791b010a
f650d11a376549bdb9061eafbd7b43f6
a0c5c9779b984ddfabf732a0791b010a--f650d11a376549bdb9061eafbd7b43f6
f3670b9e55cb48388a484bc83bba17ed
RX(p2₀)
f650d11a376549bdb9061eafbd7b43f6--f3670b9e55cb48388a484bc83bba17ed
c4dcdbb839af43e98dad746a3b459f67
RY(p2₄)
f3670b9e55cb48388a484bc83bba17ed--c4dcdbb839af43e98dad746a3b459f67
cf4e7f51183c47e5902f2121a08103be
RX(p2₈)
c4dcdbb839af43e98dad746a3b459f67--cf4e7f51183c47e5902f2121a08103be
31a97e16224645918d23fd0463a3c085
cf4e7f51183c47e5902f2121a08103be--31a97e16224645918d23fd0463a3c085
157c49aed7114248beb071a203968e71
31a97e16224645918d23fd0463a3c085--157c49aed7114248beb071a203968e71
f795031282d74f70bf463b91f5dad534
RX(p2₁₂)
157c49aed7114248beb071a203968e71--f795031282d74f70bf463b91f5dad534
478c11d8d8c8424db3a80a259272513d
RY(p2₁₆)
f795031282d74f70bf463b91f5dad534--478c11d8d8c8424db3a80a259272513d
6581bc499c284f8da0224be6bd199777
RX(p2₂₀)
478c11d8d8c8424db3a80a259272513d--6581bc499c284f8da0224be6bd199777
80afceef6e6b43cca4afe0b46f4db9f8
6581bc499c284f8da0224be6bd199777--80afceef6e6b43cca4afe0b46f4db9f8
1ee7535d69c848a497d0d8906172a16b
80afceef6e6b43cca4afe0b46f4db9f8--1ee7535d69c848a497d0d8906172a16b
d6f4cf01afb24ba188d18bab92c509c1
1ee7535d69c848a497d0d8906172a16b--d6f4cf01afb24ba188d18bab92c509c1
aa5dbbbf1e084bcba7468f26425e872c
06034d67b6184e9ca0626e3b35817583
RX(p1₁)
2518d00d6c2945f18a9c960de7a5db67--06034d67b6184e9ca0626e3b35817583
fd4fcf6a3cd24e9a81b1b152ee3572fb
2
18d44a526887437aaf7a2ab534b2842a
RY(p1₅)
06034d67b6184e9ca0626e3b35817583--18d44a526887437aaf7a2ab534b2842a
ed92451da9e442929ac7f615a940afa9
RX(p1₉)
18d44a526887437aaf7a2ab534b2842a--ed92451da9e442929ac7f615a940afa9
d70a9e84d3754a1299e3c3373b21967c
X
ed92451da9e442929ac7f615a940afa9--d70a9e84d3754a1299e3c3373b21967c
d70a9e84d3754a1299e3c3373b21967c--fced09e37e1b4ded931888d667dd9124
fdb6f92e435b4903b15130722a55f448
d70a9e84d3754a1299e3c3373b21967c--fdb6f92e435b4903b15130722a55f448
13f4cc5cac9b47618b3a2b82a12dd6a3
RX(p1₁₃)
fdb6f92e435b4903b15130722a55f448--13f4cc5cac9b47618b3a2b82a12dd6a3
b45711dfa2d846fa84818499d0e27c01
RY(p1₁₇)
13f4cc5cac9b47618b3a2b82a12dd6a3--b45711dfa2d846fa84818499d0e27c01
7b95aa556e6f46bfa2d4fdf1682777d5
RX(p1₂₁)
b45711dfa2d846fa84818499d0e27c01--7b95aa556e6f46bfa2d4fdf1682777d5
939e3a858bbf41e3ab00c08c6ae19b6a
X
7b95aa556e6f46bfa2d4fdf1682777d5--939e3a858bbf41e3ab00c08c6ae19b6a
939e3a858bbf41e3ab00c08c6ae19b6a--a0c5c9779b984ddfabf732a0791b010a
ab3d50eb234f4d40b99f2d41429e97fc
939e3a858bbf41e3ab00c08c6ae19b6a--ab3d50eb234f4d40b99f2d41429e97fc
de243f72369f4bd1aed5e83755ad3246
RX(p2₁)
ab3d50eb234f4d40b99f2d41429e97fc--de243f72369f4bd1aed5e83755ad3246
8466c40928824514818188266749c1d6
RY(p2₅)
de243f72369f4bd1aed5e83755ad3246--8466c40928824514818188266749c1d6
31d86527d09d45b8bc007424cae8fd27
RX(p2₉)
8466c40928824514818188266749c1d6--31d86527d09d45b8bc007424cae8fd27
1ae3522e2299468e9dcce6076954928c
X
31d86527d09d45b8bc007424cae8fd27--1ae3522e2299468e9dcce6076954928c
1ae3522e2299468e9dcce6076954928c--31a97e16224645918d23fd0463a3c085
161e54f49fc449e3a81c7e09edf8d87f
1ae3522e2299468e9dcce6076954928c--161e54f49fc449e3a81c7e09edf8d87f
b30b9c53849c4404bff5499b1113aca7
RX(p2₁₃)
161e54f49fc449e3a81c7e09edf8d87f--b30b9c53849c4404bff5499b1113aca7
ab1fbe08880b4e5e94738e775739aba0
RY(p2₁₇)
b30b9c53849c4404bff5499b1113aca7--ab1fbe08880b4e5e94738e775739aba0
292d6c883308429ba1f9a321e7563914
RX(p2₂₁)
ab1fbe08880b4e5e94738e775739aba0--292d6c883308429ba1f9a321e7563914
f214339a9e974145863e64ffa666cf02
X
292d6c883308429ba1f9a321e7563914--f214339a9e974145863e64ffa666cf02
f214339a9e974145863e64ffa666cf02--80afceef6e6b43cca4afe0b46f4db9f8
092900477d3d431a82734e616c4c761c
f214339a9e974145863e64ffa666cf02--092900477d3d431a82734e616c4c761c
092900477d3d431a82734e616c4c761c--aa5dbbbf1e084bcba7468f26425e872c
b7067f7003e14bbea86e89f0cb8afa81
13cfa4904de44de99af711392b5f42f2
RX(p1₂)
fd4fcf6a3cd24e9a81b1b152ee3572fb--13cfa4904de44de99af711392b5f42f2
00aa95522afa44e3b423b3818cea5d4e
3
95291082264b4312b979f0dc158493c4
RY(p1₆)
13cfa4904de44de99af711392b5f42f2--95291082264b4312b979f0dc158493c4
1cc00d29675b4a338b32fc500237a9b0
RX(p1₁₀)
95291082264b4312b979f0dc158493c4--1cc00d29675b4a338b32fc500237a9b0
6f1c5df81f5d4c058241ff77ef5ff858
1cc00d29675b4a338b32fc500237a9b0--6f1c5df81f5d4c058241ff77ef5ff858
21bb176ae3a04312aa4a3e15a0cfabfb
X
6f1c5df81f5d4c058241ff77ef5ff858--21bb176ae3a04312aa4a3e15a0cfabfb
21bb176ae3a04312aa4a3e15a0cfabfb--fdb6f92e435b4903b15130722a55f448
357ae40f2e964f5188dc9fe20a793913
RX(p1₁₄)
21bb176ae3a04312aa4a3e15a0cfabfb--357ae40f2e964f5188dc9fe20a793913
4317d2cf3a9f43f293fd89dc5be447a5
RY(p1₁₈)
357ae40f2e964f5188dc9fe20a793913--4317d2cf3a9f43f293fd89dc5be447a5
b77f48d285434ac6b363434e316f271b
RX(p1₂₂)
4317d2cf3a9f43f293fd89dc5be447a5--b77f48d285434ac6b363434e316f271b
22b77ba32ffd45679738edc7fc000505
b77f48d285434ac6b363434e316f271b--22b77ba32ffd45679738edc7fc000505
0be659634d004fe78df54a7382f29826
X
22b77ba32ffd45679738edc7fc000505--0be659634d004fe78df54a7382f29826
0be659634d004fe78df54a7382f29826--ab3d50eb234f4d40b99f2d41429e97fc
b3772d2713524b66bfab5b10d763fc3f
RX(p2₂)
0be659634d004fe78df54a7382f29826--b3772d2713524b66bfab5b10d763fc3f
a357aae091e848c8998b0e6be9d7928c
RY(p2₆)
b3772d2713524b66bfab5b10d763fc3f--a357aae091e848c8998b0e6be9d7928c
8036f2359a2044e18a0ba7424d737cf1
RX(p2₁₀)
a357aae091e848c8998b0e6be9d7928c--8036f2359a2044e18a0ba7424d737cf1
99543b1bbf3b4e998760ecca02396bf8
8036f2359a2044e18a0ba7424d737cf1--99543b1bbf3b4e998760ecca02396bf8
73ae78120c68469eacf56eb2ec929260
X
99543b1bbf3b4e998760ecca02396bf8--73ae78120c68469eacf56eb2ec929260
73ae78120c68469eacf56eb2ec929260--161e54f49fc449e3a81c7e09edf8d87f
d303b36385ea40e98d6775e95ba2f136
RX(p2₁₄)
73ae78120c68469eacf56eb2ec929260--d303b36385ea40e98d6775e95ba2f136
82beb9c0c6f74ae3b08af620ec550ed9
RY(p2₁₈)
d303b36385ea40e98d6775e95ba2f136--82beb9c0c6f74ae3b08af620ec550ed9
bf4c36a6ec5149feaf1b9709087b8b08
RX(p2₂₂)
82beb9c0c6f74ae3b08af620ec550ed9--bf4c36a6ec5149feaf1b9709087b8b08
f2ade50a7d734deeb61c536abcb7234b
bf4c36a6ec5149feaf1b9709087b8b08--f2ade50a7d734deeb61c536abcb7234b
55c6a2e389ab4ae2bfd57fe9815030f5
X
f2ade50a7d734deeb61c536abcb7234b--55c6a2e389ab4ae2bfd57fe9815030f5
55c6a2e389ab4ae2bfd57fe9815030f5--092900477d3d431a82734e616c4c761c
55c6a2e389ab4ae2bfd57fe9815030f5--b7067f7003e14bbea86e89f0cb8afa81
b4a6b90c32774378b2ec0e3549377294
f45b7c3888c44cf493c16c2f9a3ed149
RX(p1₃)
00aa95522afa44e3b423b3818cea5d4e--f45b7c3888c44cf493c16c2f9a3ed149
d14a4066ffac404b98830d92afca7954
RY(p1₇)
f45b7c3888c44cf493c16c2f9a3ed149--d14a4066ffac404b98830d92afca7954
35f747ac84304f78bb541e3844f7e9f3
RX(p1₁₁)
d14a4066ffac404b98830d92afca7954--35f747ac84304f78bb541e3844f7e9f3
d320be68e29344d59d732e99d0b77191
X
35f747ac84304f78bb541e3844f7e9f3--d320be68e29344d59d732e99d0b77191
d320be68e29344d59d732e99d0b77191--6f1c5df81f5d4c058241ff77ef5ff858
c88434f5dc934cac9787b90b90586961
d320be68e29344d59d732e99d0b77191--c88434f5dc934cac9787b90b90586961
e01f6752276543c5b6abfc52b5e5a6ce
RX(p1₁₅)
c88434f5dc934cac9787b90b90586961--e01f6752276543c5b6abfc52b5e5a6ce
9f609863704342c4bdd9f852a463bb90
RY(p1₁₉)
e01f6752276543c5b6abfc52b5e5a6ce--9f609863704342c4bdd9f852a463bb90
abca9971a4a1448abfc39e8ede83c070
RX(p1₂₃)
9f609863704342c4bdd9f852a463bb90--abca9971a4a1448abfc39e8ede83c070
f53ff139b9d842a9af32fdff7eaec63a
X
abca9971a4a1448abfc39e8ede83c070--f53ff139b9d842a9af32fdff7eaec63a
f53ff139b9d842a9af32fdff7eaec63a--22b77ba32ffd45679738edc7fc000505
f8b307a4f7244e2ea10d205f7bc300db
f53ff139b9d842a9af32fdff7eaec63a--f8b307a4f7244e2ea10d205f7bc300db
e9f14b14ad6346f98f721e5c8d3f6c14
RX(p2₃)
f8b307a4f7244e2ea10d205f7bc300db--e9f14b14ad6346f98f721e5c8d3f6c14
8bde671c191a41169895fd3e52acec46
RY(p2₇)
e9f14b14ad6346f98f721e5c8d3f6c14--8bde671c191a41169895fd3e52acec46
ceaf442f753243e59d4a200efe390ceb
RX(p2₁₁)
8bde671c191a41169895fd3e52acec46--ceaf442f753243e59d4a200efe390ceb
1afb55701e1d4efbb0ed2609e5b322f7
X
ceaf442f753243e59d4a200efe390ceb--1afb55701e1d4efbb0ed2609e5b322f7
1afb55701e1d4efbb0ed2609e5b322f7--99543b1bbf3b4e998760ecca02396bf8
4f3b03429726485c942326215e01b23a
1afb55701e1d4efbb0ed2609e5b322f7--4f3b03429726485c942326215e01b23a
61821cc445944b3ea2600bd61731ea41
RX(p2₁₅)
4f3b03429726485c942326215e01b23a--61821cc445944b3ea2600bd61731ea41
f8f8dd4dcb6c415d8844a92a7b15009e
RY(p2₁₉)
61821cc445944b3ea2600bd61731ea41--f8f8dd4dcb6c415d8844a92a7b15009e
371e778df18e459f8862223cfb6c607d
RX(p2₂₃)
f8f8dd4dcb6c415d8844a92a7b15009e--371e778df18e459f8862223cfb6c607d
ffd5ea8b6ab144dfa2570788ffd5441b
X
371e778df18e459f8862223cfb6c607d--ffd5ea8b6ab144dfa2570788ffd5441b
ffd5ea8b6ab144dfa2570788ffd5441b--f2ade50a7d734deeb61c536abcb7234b
8d8511a116bd4c6ab9eeb1559a922d82
ffd5ea8b6ab144dfa2570788ffd5441b--8d8511a116bd4c6ab9eeb1559a922d82
8d8511a116bd4c6ab9eeb1559a922d82--b4a6b90c32774378b2ec0e3549377294
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 ]] )