Skip to content

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)
wf = tensor([[6.1232e-17+0.j, 0.0000e+00-1.j]])
wf = tensor([[0.8776+0.0000j, 0.0000-0.4794j]])

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)
wf = tensor([[0.9974+0.0000j, 0.0000-0.0725j]])

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.])})
wf = tensor([[0.8776+0.0000j, 0.0000-0.4794j],
        [0.5403+0.0000j, 0.0000-0.8415j]])

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)
wf = tensor([[0.8777+0.0000j, 0.0000-0.4793j],
        [0.9664+0.0000j, 0.0000-0.2571j]])

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.
wf = tensor([[0.8728+0.0000j, 0.2312+0.0000j, 0.0000-0.4155j, 0.0000-0.1101j]])

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_662b4c380840489bbd44521a9bcd7c01 [* 2] cluster_0122072b574a450b83cf89aada226e9c Rotations 4221a4c5b1424fa8bdd3110ac8ecb14f 0 ed34e7b0c9e14950b9d7c3ba214274f6 RX(phi/theta) 4221a4c5b1424fa8bdd3110ac8ecb14f--ed34e7b0c9e14950b9d7c3ba214274f6 5f620733562e437aa64301b332d90007 1 3e435e91fc9e4dacb6eee51b31693cbd RX(phi) ed34e7b0c9e14950b9d7c3ba214274f6--3e435e91fc9e4dacb6eee51b31693cbd b4d7a4d2c503467c87e024e247381180 RX(phi) 3e435e91fc9e4dacb6eee51b31693cbd--b4d7a4d2c503467c87e024e247381180 a6231ac1ff1d4e279c0750bf0e529baf RX(phi + theta) b4d7a4d2c503467c87e024e247381180--a6231ac1ff1d4e279c0750bf0e529baf 1dfcbc1d02964217bd4cb1dc9466fc27 a6231ac1ff1d4e279c0750bf0e529baf--1dfcbc1d02964217bd4cb1dc9466fc27 8151fe96932e41228c0f6ba475ab6f85 1dfcbc1d02964217bd4cb1dc9466fc27--8151fe96932e41228c0f6ba475ab6f85 1ac14151d78942f9bfb2dccda7d9194e Z 8151fe96932e41228c0f6ba475ab6f85--1ac14151d78942f9bfb2dccda7d9194e c32b14d9598e4634aec6582ffa11ae58 1ac14151d78942f9bfb2dccda7d9194e--c32b14d9598e4634aec6582ffa11ae58 6aa089fee2fa4d9fb692ea186ccebbb6 70aa639923024920a6a3e998ffc355cf RY(2*theta) 5f620733562e437aa64301b332d90007--70aa639923024920a6a3e998ffc355cf 4983915510664a14af9adc71191c77fd 2 ae2bb1743806443092e1c57c67b54544 RY(theta) 70aa639923024920a6a3e998ffc355cf--ae2bb1743806443092e1c57c67b54544 979f228d11f044d49689950fdf2a0148 RY(theta) ae2bb1743806443092e1c57c67b54544--979f228d11f044d49689950fdf2a0148 10386081c3b9462eaafd3cdfa94f9f89 RY(theta**2) 979f228d11f044d49689950fdf2a0148--10386081c3b9462eaafd3cdfa94f9f89 4b002949a9574e0a8e8d02de0cdf0a0f X 10386081c3b9462eaafd3cdfa94f9f89--4b002949a9574e0a8e8d02de0cdf0a0f 4b002949a9574e0a8e8d02de0cdf0a0f--1dfcbc1d02964217bd4cb1dc9466fc27 462f292ed96c4c518fd571c5aaf218d8 4b002949a9574e0a8e8d02de0cdf0a0f--462f292ed96c4c518fd571c5aaf218d8 8a802e2476864473a24f159ffef64be0 Z 462f292ed96c4c518fd571c5aaf218d8--8a802e2476864473a24f159ffef64be0 8a802e2476864473a24f159ffef64be0--6aa089fee2fa4d9fb692ea186ccebbb6 84d9106083844f94ab3cac7f152a9bc9 09683d5db22d41148f3f5a5d5e5f285b RZ(cos(phi)) 4983915510664a14af9adc71191c77fd--09683d5db22d41148f3f5a5d5e5f285b 808408fce2834fddaa3da1e9446616ad RZ(phi) 09683d5db22d41148f3f5a5d5e5f285b--808408fce2834fddaa3da1e9446616ad 3b63db799f1c4e36b16343bc594a4e86 RZ(phi) 808408fce2834fddaa3da1e9446616ad--3b63db799f1c4e36b16343bc594a4e86 c0635e38225741dbbc213b196758e107 RZ(cos(phi)) 3b63db799f1c4e36b16343bc594a4e86--c0635e38225741dbbc213b196758e107 c822bd707d1b4e6a963c10fe0b9d5c7f c0635e38225741dbbc213b196758e107--c822bd707d1b4e6a963c10fe0b9d5c7f 01f5ed75d02446a298706c23348c1b2b X c822bd707d1b4e6a963c10fe0b9d5c7f--01f5ed75d02446a298706c23348c1b2b 01f5ed75d02446a298706c23348c1b2b--462f292ed96c4c518fd571c5aaf218d8 91cc75f90b82468a925b94d08ad70edb Z 01f5ed75d02446a298706c23348c1b2b--91cc75f90b82468a925b94d08ad70edb 91cc75f90b82468a925b94d08ad70edb--84d9106083844f94ab3cac7f152a9bc9

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
unique_params = [theta, 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
num_vparams = 1
vparams_values = OrderedDict([('theta', tensor([0.4176]))])

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)
wf = tensor([[0.7455+0.0000j, 0.4356+0.0000j, 0.0000-0.4356j, 0.0000-0.2545j],
        [0.6912+0.0000j, 0.4620+0.0000j, 0.0000-0.4620j, 0.0000-0.3088j],
        [0.9451+0.0000j, 0.2277+0.0000j, 0.0000-0.2277j, 0.0000-0.0549j]],
       grad_fn=<TBackward0>)

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
Unique parameters with a single HEA: 24
%3 9576c4fbdd3444ccb078207530487c55 0 444652542bbb491c9437a2a9406fd4f3 RX(theta₀) 9576c4fbdd3444ccb078207530487c55--444652542bbb491c9437a2a9406fd4f3 ba04c4d62c894452833197ba81cc7b18 1 d93c9aa480a24dda8c2434ff74b6bb82 RY(theta₄) 444652542bbb491c9437a2a9406fd4f3--d93c9aa480a24dda8c2434ff74b6bb82 1d6d19f2c08d407c828e95808c45d8c1 RX(theta₈) d93c9aa480a24dda8c2434ff74b6bb82--1d6d19f2c08d407c828e95808c45d8c1 133852c0b39743889a1089e3f089534a 1d6d19f2c08d407c828e95808c45d8c1--133852c0b39743889a1089e3f089534a bb64f2fbead84d5c84ba7f96a46460e5 133852c0b39743889a1089e3f089534a--bb64f2fbead84d5c84ba7f96a46460e5 bd9e9b36f1614cf79ffa5279a41e322a RX(theta₁₂) bb64f2fbead84d5c84ba7f96a46460e5--bd9e9b36f1614cf79ffa5279a41e322a e14190543d4c42679e2fa028a52ebaab RY(theta₁₆) bd9e9b36f1614cf79ffa5279a41e322a--e14190543d4c42679e2fa028a52ebaab 786f4958dc884e1ab8f75850df91105d RX(theta₂₀) e14190543d4c42679e2fa028a52ebaab--786f4958dc884e1ab8f75850df91105d 29c11a8d9084447ea983ca1cba469494 786f4958dc884e1ab8f75850df91105d--29c11a8d9084447ea983ca1cba469494 32ddd6cf8b854770b29e1d9ed731e993 29c11a8d9084447ea983ca1cba469494--32ddd6cf8b854770b29e1d9ed731e993 9b3c596cd93842598aebe690f9d7c68e 32ddd6cf8b854770b29e1d9ed731e993--9b3c596cd93842598aebe690f9d7c68e d4a1a5a245f142529678e50acf2425bd 190beffa9e7641d4b6ac44364daa9b4f RX(theta₁) ba04c4d62c894452833197ba81cc7b18--190beffa9e7641d4b6ac44364daa9b4f 051fc2597f13490a9071ccdeff513a7e 2 1aa0e96e236b4a599abd9f8e70db7692 RY(theta₅) 190beffa9e7641d4b6ac44364daa9b4f--1aa0e96e236b4a599abd9f8e70db7692 7966187987c94affa8737297b2941139 RX(theta₉) 1aa0e96e236b4a599abd9f8e70db7692--7966187987c94affa8737297b2941139 7f1f1403fb9349a3943a5097ff235b3a X 7966187987c94affa8737297b2941139--7f1f1403fb9349a3943a5097ff235b3a 7f1f1403fb9349a3943a5097ff235b3a--133852c0b39743889a1089e3f089534a ed28d2d56abd408289f7d7f06026aecc 7f1f1403fb9349a3943a5097ff235b3a--ed28d2d56abd408289f7d7f06026aecc f41e38d5208e4cd8bc6d4dbde9f55bec RX(theta₁₃) ed28d2d56abd408289f7d7f06026aecc--f41e38d5208e4cd8bc6d4dbde9f55bec 547ed62734bb4c4797f1c238fb724be0 RY(theta₁₇) f41e38d5208e4cd8bc6d4dbde9f55bec--547ed62734bb4c4797f1c238fb724be0 95e0ecdecc054c73a64c968434c9b101 RX(theta₂₁) 547ed62734bb4c4797f1c238fb724be0--95e0ecdecc054c73a64c968434c9b101 031e0b22bd1a4de7ac76528befdb5194 X 95e0ecdecc054c73a64c968434c9b101--031e0b22bd1a4de7ac76528befdb5194 031e0b22bd1a4de7ac76528befdb5194--29c11a8d9084447ea983ca1cba469494 35b51b8abeb04ae5af5c0b8a50661c84 031e0b22bd1a4de7ac76528befdb5194--35b51b8abeb04ae5af5c0b8a50661c84 35b51b8abeb04ae5af5c0b8a50661c84--d4a1a5a245f142529678e50acf2425bd 7656fa1380e743fca57e3b52737069f7 afc65c1ea6464c82b449a30228a3f6d5 RX(theta₂) 051fc2597f13490a9071ccdeff513a7e--afc65c1ea6464c82b449a30228a3f6d5 7f1c12ea578a4a31b403995eaa5f512b 3 8191f19c64624cdea41b618ffbd67748 RY(theta₆) afc65c1ea6464c82b449a30228a3f6d5--8191f19c64624cdea41b618ffbd67748 baf77deb7dc74f2da6e0ac2c57315754 RX(theta₁₀) 8191f19c64624cdea41b618ffbd67748--baf77deb7dc74f2da6e0ac2c57315754 cb446bb7e17e41afb4ce7fc25b2429a1 baf77deb7dc74f2da6e0ac2c57315754--cb446bb7e17e41afb4ce7fc25b2429a1 d835b4b16f3a4b03bb909b70433a2ce7 X cb446bb7e17e41afb4ce7fc25b2429a1--d835b4b16f3a4b03bb909b70433a2ce7 d835b4b16f3a4b03bb909b70433a2ce7--ed28d2d56abd408289f7d7f06026aecc 355f41533f044fbe8e7aef1412a78ab7 RX(theta₁₄) d835b4b16f3a4b03bb909b70433a2ce7--355f41533f044fbe8e7aef1412a78ab7 ec8bd587e3424e1f8d3b9853bf8554ba RY(theta₁₈) 355f41533f044fbe8e7aef1412a78ab7--ec8bd587e3424e1f8d3b9853bf8554ba f41f6b70934b4e85ad9c591d879b9ea2 RX(theta₂₂) ec8bd587e3424e1f8d3b9853bf8554ba--f41f6b70934b4e85ad9c591d879b9ea2 b4872a5ee29d432386525ae992fe0e66 f41f6b70934b4e85ad9c591d879b9ea2--b4872a5ee29d432386525ae992fe0e66 7df8a88bcdbf4eaaae67b9ff9a8a8758 X b4872a5ee29d432386525ae992fe0e66--7df8a88bcdbf4eaaae67b9ff9a8a8758 7df8a88bcdbf4eaaae67b9ff9a8a8758--35b51b8abeb04ae5af5c0b8a50661c84 7df8a88bcdbf4eaaae67b9ff9a8a8758--7656fa1380e743fca57e3b52737069f7 4eeb2e17442440f99e3ab0f108315c29 bcb1c2d6d13149459368315870c318d3 RX(theta₃) 7f1c12ea578a4a31b403995eaa5f512b--bcb1c2d6d13149459368315870c318d3 c956de608427497387b7c20e8f0d3cfc RY(theta₇) bcb1c2d6d13149459368315870c318d3--c956de608427497387b7c20e8f0d3cfc fee5022b61834a9aa03488d0e720e7ab RX(theta₁₁) c956de608427497387b7c20e8f0d3cfc--fee5022b61834a9aa03488d0e720e7ab 282f2208b2a94570b788048a1acde9c5 X fee5022b61834a9aa03488d0e720e7ab--282f2208b2a94570b788048a1acde9c5 282f2208b2a94570b788048a1acde9c5--cb446bb7e17e41afb4ce7fc25b2429a1 1ad02d622d714bf68b9815dddf3c8e25 282f2208b2a94570b788048a1acde9c5--1ad02d622d714bf68b9815dddf3c8e25 fe7102f21b6842879f67245d8e87bf53 RX(theta₁₅) 1ad02d622d714bf68b9815dddf3c8e25--fe7102f21b6842879f67245d8e87bf53 102d935eb8384f458d97397276c0c1c7 RY(theta₁₉) fe7102f21b6842879f67245d8e87bf53--102d935eb8384f458d97397276c0c1c7 399173a3b7c5482a85e4a0015f29464d RX(theta₂₃) 102d935eb8384f458d97397276c0c1c7--399173a3b7c5482a85e4a0015f29464d 95275efbbb29405dbee64b27eedf5496 X 399173a3b7c5482a85e4a0015f29464d--95275efbbb29405dbee64b27eedf5496 95275efbbb29405dbee64b27eedf5496--b4872a5ee29d432386525ae992fe0e66 f3907af281a9479fac8db3d2659d14a3 95275efbbb29405dbee64b27eedf5496--f3907af281a9479fac8db3d2659d14a3 f3907af281a9479fac8db3d2659d14a3--4eeb2e17442440f99e3ab0f108315c29

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
Unique parameters with two stacked HEAs: 24
%3 cluster_697702d0d32f4d2186bf8fe84744600c HEA cluster_e2c1c946a8274e2099bcb16e119d79a6 HEA 4dc4eb6a502a40fba05ec6bc84c444cb 0 9695f17b666a45a29aa6333f33f1c487 RX(theta₀) 4dc4eb6a502a40fba05ec6bc84c444cb--9695f17b666a45a29aa6333f33f1c487 c73125434f744b9f8b16162d13812470 1 5347bc3d435a43dcb71243872e8a5106 RY(theta₄) 9695f17b666a45a29aa6333f33f1c487--5347bc3d435a43dcb71243872e8a5106 751d7baec42043ce8d60489fdcbb1231 RX(theta₈) 5347bc3d435a43dcb71243872e8a5106--751d7baec42043ce8d60489fdcbb1231 37a07ee6e5b1477e9affc660349b8247 751d7baec42043ce8d60489fdcbb1231--37a07ee6e5b1477e9affc660349b8247 927c25cbd95b4f85b9b9004793aa53ae 37a07ee6e5b1477e9affc660349b8247--927c25cbd95b4f85b9b9004793aa53ae 28fe3c04982643cfa6e551d9348dcfa1 RX(theta₁₂) 927c25cbd95b4f85b9b9004793aa53ae--28fe3c04982643cfa6e551d9348dcfa1 c2a5c8c0a7274f0ba83841ad1cc993ea RY(theta₁₆) 28fe3c04982643cfa6e551d9348dcfa1--c2a5c8c0a7274f0ba83841ad1cc993ea 823a727cd25e43f79b20b6872612568a RX(theta₂₀) c2a5c8c0a7274f0ba83841ad1cc993ea--823a727cd25e43f79b20b6872612568a cc65a302f1334665a527cbc3e88af35b 823a727cd25e43f79b20b6872612568a--cc65a302f1334665a527cbc3e88af35b 21f464549c1f49dd8cc53e160b096785 cc65a302f1334665a527cbc3e88af35b--21f464549c1f49dd8cc53e160b096785 81b13f5e1a814f97b1ab8b30757841f5 RX(theta₀) 21f464549c1f49dd8cc53e160b096785--81b13f5e1a814f97b1ab8b30757841f5 ea5f537e555a4937a9f1fa70ea504f3d RY(theta₄) 81b13f5e1a814f97b1ab8b30757841f5--ea5f537e555a4937a9f1fa70ea504f3d 293abedf782340eb87a14a277b72713c RX(theta₈) ea5f537e555a4937a9f1fa70ea504f3d--293abedf782340eb87a14a277b72713c 70418d3928e6406e98b221085e4dc4f1 293abedf782340eb87a14a277b72713c--70418d3928e6406e98b221085e4dc4f1 44057abe86134316b40ededb156f3b17 70418d3928e6406e98b221085e4dc4f1--44057abe86134316b40ededb156f3b17 fe719177835f4585b8013a92c7c67683 RX(theta₁₂) 44057abe86134316b40ededb156f3b17--fe719177835f4585b8013a92c7c67683 d14d741364df44f6bf113c3527117ccb RY(theta₁₆) fe719177835f4585b8013a92c7c67683--d14d741364df44f6bf113c3527117ccb 483e7f58f08b437c9a3c532ae88b1693 RX(theta₂₀) d14d741364df44f6bf113c3527117ccb--483e7f58f08b437c9a3c532ae88b1693 589bac7538ee485b819030799d5daf39 483e7f58f08b437c9a3c532ae88b1693--589bac7538ee485b819030799d5daf39 07d0f73aee7b45e2be5961baf5d36901 589bac7538ee485b819030799d5daf39--07d0f73aee7b45e2be5961baf5d36901 85c33bfc8ab5435a962a5f8ec2aa7b78 07d0f73aee7b45e2be5961baf5d36901--85c33bfc8ab5435a962a5f8ec2aa7b78 59a769f1f1de4e04973e905c42cd496f e00c4fcbb97e488f8da042680109ca55 RX(theta₁) c73125434f744b9f8b16162d13812470--e00c4fcbb97e488f8da042680109ca55 4cafd373545e43aa9d306ebd90ff88a4 2 56cee32df14143eabd2cbdc0bb853b2e RY(theta₅) e00c4fcbb97e488f8da042680109ca55--56cee32df14143eabd2cbdc0bb853b2e 5c6e08edc65a470b834820eb5624a618 RX(theta₉) 56cee32df14143eabd2cbdc0bb853b2e--5c6e08edc65a470b834820eb5624a618 05bb16be63e14f16bdd505774563ae37 X 5c6e08edc65a470b834820eb5624a618--05bb16be63e14f16bdd505774563ae37 05bb16be63e14f16bdd505774563ae37--37a07ee6e5b1477e9affc660349b8247 7f740ec4e41e442eb5bcf98475290611 05bb16be63e14f16bdd505774563ae37--7f740ec4e41e442eb5bcf98475290611 6c0139b3c1c740429a656f1c56fff756 RX(theta₁₃) 7f740ec4e41e442eb5bcf98475290611--6c0139b3c1c740429a656f1c56fff756 a719b6e0f5954cd4924673a4e300f2b6 RY(theta₁₇) 6c0139b3c1c740429a656f1c56fff756--a719b6e0f5954cd4924673a4e300f2b6 f5f19c941695498db75d07bbd26c2040 RX(theta₂₁) a719b6e0f5954cd4924673a4e300f2b6--f5f19c941695498db75d07bbd26c2040 e6561f39742741a8936ea3b1b8396d01 X f5f19c941695498db75d07bbd26c2040--e6561f39742741a8936ea3b1b8396d01 e6561f39742741a8936ea3b1b8396d01--cc65a302f1334665a527cbc3e88af35b d41093a6a32a4ebdabd4865289d2e31e e6561f39742741a8936ea3b1b8396d01--d41093a6a32a4ebdabd4865289d2e31e 5c0353ee76e8491b84bdc30677e9cf7e RX(theta₁) d41093a6a32a4ebdabd4865289d2e31e--5c0353ee76e8491b84bdc30677e9cf7e 5e8807c281244b1881ae6d204cde749a RY(theta₅) 5c0353ee76e8491b84bdc30677e9cf7e--5e8807c281244b1881ae6d204cde749a 3f296c481f42488cac1a0ead7b72e42b RX(theta₉) 5e8807c281244b1881ae6d204cde749a--3f296c481f42488cac1a0ead7b72e42b 859881b63f03417981057c66e0c5c4fc X 3f296c481f42488cac1a0ead7b72e42b--859881b63f03417981057c66e0c5c4fc 859881b63f03417981057c66e0c5c4fc--70418d3928e6406e98b221085e4dc4f1 44b48f5e52934b0eb6d33b817caa87f4 859881b63f03417981057c66e0c5c4fc--44b48f5e52934b0eb6d33b817caa87f4 aa00f11bee0b408c8fcd61cfacf11595 RX(theta₁₃) 44b48f5e52934b0eb6d33b817caa87f4--aa00f11bee0b408c8fcd61cfacf11595 ab4fd6b6ec8e47c19eb190ffa8b18d67 RY(theta₁₇) aa00f11bee0b408c8fcd61cfacf11595--ab4fd6b6ec8e47c19eb190ffa8b18d67 9d2d621af35f4971b55ebcbc8ebf1a29 RX(theta₂₁) ab4fd6b6ec8e47c19eb190ffa8b18d67--9d2d621af35f4971b55ebcbc8ebf1a29 fb3c2714edf640259b44aba94a5e0a3d X 9d2d621af35f4971b55ebcbc8ebf1a29--fb3c2714edf640259b44aba94a5e0a3d fb3c2714edf640259b44aba94a5e0a3d--589bac7538ee485b819030799d5daf39 c3194d41792d454fa8d777a3ba115f4d fb3c2714edf640259b44aba94a5e0a3d--c3194d41792d454fa8d777a3ba115f4d c3194d41792d454fa8d777a3ba115f4d--59a769f1f1de4e04973e905c42cd496f a2bcc3c29a004eb09a54343ca08bbd6c 3099b23c6d8046a9911d47799e711b6a RX(theta₂) 4cafd373545e43aa9d306ebd90ff88a4--3099b23c6d8046a9911d47799e711b6a 70a0039d43c44eb9b6e81f413d90edd7 3 4cc2fd46ee5d45ca965a6da772383708 RY(theta₆) 3099b23c6d8046a9911d47799e711b6a--4cc2fd46ee5d45ca965a6da772383708 3f489f62719d4626b8d572577e022c7c RX(theta₁₀) 4cc2fd46ee5d45ca965a6da772383708--3f489f62719d4626b8d572577e022c7c 1a00af1957ab413a91cc33b02522f2a1 3f489f62719d4626b8d572577e022c7c--1a00af1957ab413a91cc33b02522f2a1 b965e5c5100641c0b87165983b1bdb45 X 1a00af1957ab413a91cc33b02522f2a1--b965e5c5100641c0b87165983b1bdb45 b965e5c5100641c0b87165983b1bdb45--7f740ec4e41e442eb5bcf98475290611 51500ad2fe574f22b062f8f423e1e6e8 RX(theta₁₄) b965e5c5100641c0b87165983b1bdb45--51500ad2fe574f22b062f8f423e1e6e8 e4116d188ab84e0a952527334efa452f RY(theta₁₈) 51500ad2fe574f22b062f8f423e1e6e8--e4116d188ab84e0a952527334efa452f cd53a60e0330480e8d72ae67d0ec191d RX(theta₂₂) e4116d188ab84e0a952527334efa452f--cd53a60e0330480e8d72ae67d0ec191d d1eb765b7ca0434abf75e8050ec6bb26 cd53a60e0330480e8d72ae67d0ec191d--d1eb765b7ca0434abf75e8050ec6bb26 e0fc35667a9b48578e97cfd7c57a9aab X d1eb765b7ca0434abf75e8050ec6bb26--e0fc35667a9b48578e97cfd7c57a9aab e0fc35667a9b48578e97cfd7c57a9aab--d41093a6a32a4ebdabd4865289d2e31e 84c30e86a3a64fe38a3be68d9a9663b0 RX(theta₂) e0fc35667a9b48578e97cfd7c57a9aab--84c30e86a3a64fe38a3be68d9a9663b0 53aadb7e4bde4f0fb75c5071f253cc18 RY(theta₆) 84c30e86a3a64fe38a3be68d9a9663b0--53aadb7e4bde4f0fb75c5071f253cc18 209e76affcc64c568d83e9620a29289d RX(theta₁₀) 53aadb7e4bde4f0fb75c5071f253cc18--209e76affcc64c568d83e9620a29289d 2e1781cbf8d3461eb62dd735e499343f 209e76affcc64c568d83e9620a29289d--2e1781cbf8d3461eb62dd735e499343f 475068e2ee294cfbb924c08c036cdd82 X 2e1781cbf8d3461eb62dd735e499343f--475068e2ee294cfbb924c08c036cdd82 475068e2ee294cfbb924c08c036cdd82--44b48f5e52934b0eb6d33b817caa87f4 7bc6c4f660f84f98aa2f476f1989878a RX(theta₁₄) 475068e2ee294cfbb924c08c036cdd82--7bc6c4f660f84f98aa2f476f1989878a a30100f0cd2d411293cc1ccf79473a3b RY(theta₁₈) 7bc6c4f660f84f98aa2f476f1989878a--a30100f0cd2d411293cc1ccf79473a3b a2aedb78ef054f69b1863b426d13a4d8 RX(theta₂₂) a30100f0cd2d411293cc1ccf79473a3b--a2aedb78ef054f69b1863b426d13a4d8 a0bbb047180049d3a99f9434636d95c4 a2aedb78ef054f69b1863b426d13a4d8--a0bbb047180049d3a99f9434636d95c4 0473598d09674009a3a82bd274f4aa04 X a0bbb047180049d3a99f9434636d95c4--0473598d09674009a3a82bd274f4aa04 0473598d09674009a3a82bd274f4aa04--c3194d41792d454fa8d777a3ba115f4d 0473598d09674009a3a82bd274f4aa04--a2bcc3c29a004eb09a54343ca08bbd6c ded43482ac254361beb1bd77c1e599a6 31f75ae6665648a28889e51233d26192 RX(theta₃) 70a0039d43c44eb9b6e81f413d90edd7--31f75ae6665648a28889e51233d26192 4a01fdd1f2ff4a94b041d4ac2d536502 RY(theta₇) 31f75ae6665648a28889e51233d26192--4a01fdd1f2ff4a94b041d4ac2d536502 8ec25915c542421fbb7073463d072bfa RX(theta₁₁) 4a01fdd1f2ff4a94b041d4ac2d536502--8ec25915c542421fbb7073463d072bfa a2d6393535c74dd4ae42a54a613465ac X 8ec25915c542421fbb7073463d072bfa--a2d6393535c74dd4ae42a54a613465ac a2d6393535c74dd4ae42a54a613465ac--1a00af1957ab413a91cc33b02522f2a1 381e0fd0b52f4b9e93014ce101e83c8e a2d6393535c74dd4ae42a54a613465ac--381e0fd0b52f4b9e93014ce101e83c8e 378a6bb909074e7bbe1cb7a63c79d092 RX(theta₁₅) 381e0fd0b52f4b9e93014ce101e83c8e--378a6bb909074e7bbe1cb7a63c79d092 7a3459c85d104a0489a6809dadf6e2e9 RY(theta₁₉) 378a6bb909074e7bbe1cb7a63c79d092--7a3459c85d104a0489a6809dadf6e2e9 92995f5038c14941b5bf09dfc54ff67a RX(theta₂₃) 7a3459c85d104a0489a6809dadf6e2e9--92995f5038c14941b5bf09dfc54ff67a 98740beabf754ab8b3ec742a0db5d0ab X 92995f5038c14941b5bf09dfc54ff67a--98740beabf754ab8b3ec742a0db5d0ab 98740beabf754ab8b3ec742a0db5d0ab--d1eb765b7ca0434abf75e8050ec6bb26 46d50148c0234524a7260323b35cabd8 98740beabf754ab8b3ec742a0db5d0ab--46d50148c0234524a7260323b35cabd8 1c7d98cc79e048fda5117891a23c7693 RX(theta₃) 46d50148c0234524a7260323b35cabd8--1c7d98cc79e048fda5117891a23c7693 2f99e8be971146df889a590964188aef RY(theta₇) 1c7d98cc79e048fda5117891a23c7693--2f99e8be971146df889a590964188aef f3006f47390343c1a9957ad0146100cb RX(theta₁₁) 2f99e8be971146df889a590964188aef--f3006f47390343c1a9957ad0146100cb 92da5454b21e4ef9a624481de894087b X f3006f47390343c1a9957ad0146100cb--92da5454b21e4ef9a624481de894087b 92da5454b21e4ef9a624481de894087b--2e1781cbf8d3461eb62dd735e499343f 7065de4a68374766a0065f4aa71c80cb 92da5454b21e4ef9a624481de894087b--7065de4a68374766a0065f4aa71c80cb b7d6e8f5a23a43b3ab2a83657ae742ba RX(theta₁₅) 7065de4a68374766a0065f4aa71c80cb--b7d6e8f5a23a43b3ab2a83657ae742ba 75f2950fd6b44beca782129bff07950b RY(theta₁₉) b7d6e8f5a23a43b3ab2a83657ae742ba--75f2950fd6b44beca782129bff07950b e601699d83be493e97a68836986d985f RX(theta₂₃) 75f2950fd6b44beca782129bff07950b--e601699d83be493e97a68836986d985f 4e9e974636b84782872cdf200f69d6a0 X e601699d83be493e97a68836986d985f--4e9e974636b84782872cdf200f69d6a0 4e9e974636b84782872cdf200f69d6a0--a0bbb047180049d3a99f9434636d95c4 6ab248a1881f41a3ba720a62dae20b39 4e9e974636b84782872cdf200f69d6a0--6ab248a1881f41a3ba720a62dae20b39 6ab248a1881f41a3ba720a62dae20b39--ded43482ac254361beb1bd77c1e599a6

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
Unique parameters with two stacked HEAs: 48
%3 cluster_a7eb3c1f181d40bea2eb349e66ac32f7 HEA cluster_abd3c614584a4180a3f5620e72ec6bf1 HEA 9417a4e061174c9e9eb125330cbd6d50 0 82d4a5bae51049f0870cf5cd515658fa RX(p1₀) 9417a4e061174c9e9eb125330cbd6d50--82d4a5bae51049f0870cf5cd515658fa 802839d6ab204a31b0b410d4cdc313bb 1 88e7f005bba04af288aed5e09372501a RY(p1₄) 82d4a5bae51049f0870cf5cd515658fa--88e7f005bba04af288aed5e09372501a 15fdf9df7c594d2fae38e4b1fbb5ea6d RX(p1₈) 88e7f005bba04af288aed5e09372501a--15fdf9df7c594d2fae38e4b1fbb5ea6d b26b04d415f6424da76dcf30531e6554 15fdf9df7c594d2fae38e4b1fbb5ea6d--b26b04d415f6424da76dcf30531e6554 5020aeba931d404f870f78a672ae4a48 b26b04d415f6424da76dcf30531e6554--5020aeba931d404f870f78a672ae4a48 4eef3804559646a88bb0c91fa84f0b3f RX(p1₁₂) 5020aeba931d404f870f78a672ae4a48--4eef3804559646a88bb0c91fa84f0b3f f188788850be4679a1cd517ed35d516f RY(p1₁₆) 4eef3804559646a88bb0c91fa84f0b3f--f188788850be4679a1cd517ed35d516f b373e93fb8434502b72817b292c2f98c RX(p1₂₀) f188788850be4679a1cd517ed35d516f--b373e93fb8434502b72817b292c2f98c 1f899b6594464f41884e4d9400941d33 b373e93fb8434502b72817b292c2f98c--1f899b6594464f41884e4d9400941d33 b8c132c237aa4f11be16f3760e11ebc5 1f899b6594464f41884e4d9400941d33--b8c132c237aa4f11be16f3760e11ebc5 2fe85b4fa88a4d6e94be37fbc39cfef7 RX(p2₀) b8c132c237aa4f11be16f3760e11ebc5--2fe85b4fa88a4d6e94be37fbc39cfef7 a213e4d3a8c24251abd566a2eafb9527 RY(p2₄) 2fe85b4fa88a4d6e94be37fbc39cfef7--a213e4d3a8c24251abd566a2eafb9527 2fac79d1a022453f9632527919353333 RX(p2₈) a213e4d3a8c24251abd566a2eafb9527--2fac79d1a022453f9632527919353333 2d43694e044a41ffb5c3c56ec6727230 2fac79d1a022453f9632527919353333--2d43694e044a41ffb5c3c56ec6727230 4228c5e926c349b2882fb0afe9a259d7 2d43694e044a41ffb5c3c56ec6727230--4228c5e926c349b2882fb0afe9a259d7 772d72038b284771855d6db991c0fe24 RX(p2₁₂) 4228c5e926c349b2882fb0afe9a259d7--772d72038b284771855d6db991c0fe24 120ad2cce07c46f58281361d83eecd5a RY(p2₁₆) 772d72038b284771855d6db991c0fe24--120ad2cce07c46f58281361d83eecd5a 2d9333c42ca34be8be99bf39292bf207 RX(p2₂₀) 120ad2cce07c46f58281361d83eecd5a--2d9333c42ca34be8be99bf39292bf207 9e2a9fab90424d328f5c7ec58f437d1b 2d9333c42ca34be8be99bf39292bf207--9e2a9fab90424d328f5c7ec58f437d1b 8140f38d43e545c39c14e81979ace873 9e2a9fab90424d328f5c7ec58f437d1b--8140f38d43e545c39c14e81979ace873 0b73e36966d047dfae584ce2fc69b14b 8140f38d43e545c39c14e81979ace873--0b73e36966d047dfae584ce2fc69b14b 49fbd35dd88a47eaa738e5e448362958 aa11a105b1b54c32852e9a6557e71dfa RX(p1₁) 802839d6ab204a31b0b410d4cdc313bb--aa11a105b1b54c32852e9a6557e71dfa 0b8b19b0b08e47999c1b2d33d6b66d96 2 94fe922f6aa647df837ea287c8da97f9 RY(p1₅) aa11a105b1b54c32852e9a6557e71dfa--94fe922f6aa647df837ea287c8da97f9 55175f1663754581b4992027a40e36ab RX(p1₉) 94fe922f6aa647df837ea287c8da97f9--55175f1663754581b4992027a40e36ab b3a2777635494a08a2d9eb6d9eba3011 X 55175f1663754581b4992027a40e36ab--b3a2777635494a08a2d9eb6d9eba3011 b3a2777635494a08a2d9eb6d9eba3011--b26b04d415f6424da76dcf30531e6554 dbf3477312044a039c25fcc8106f79d0 b3a2777635494a08a2d9eb6d9eba3011--dbf3477312044a039c25fcc8106f79d0 ae9ad9ef6dd34859ab3257ea1dc8eb19 RX(p1₁₃) dbf3477312044a039c25fcc8106f79d0--ae9ad9ef6dd34859ab3257ea1dc8eb19 308c4095732a4cc3b56382085fbbfd99 RY(p1₁₇) ae9ad9ef6dd34859ab3257ea1dc8eb19--308c4095732a4cc3b56382085fbbfd99 dd6b1698148247d3a601ba1cfe365941 RX(p1₂₁) 308c4095732a4cc3b56382085fbbfd99--dd6b1698148247d3a601ba1cfe365941 97ba82c932004324aee2283861f4b01e X dd6b1698148247d3a601ba1cfe365941--97ba82c932004324aee2283861f4b01e 97ba82c932004324aee2283861f4b01e--1f899b6594464f41884e4d9400941d33 f5136b4378e74bc88339ad09a9575d5c 97ba82c932004324aee2283861f4b01e--f5136b4378e74bc88339ad09a9575d5c d6ce4b4b94e0485498dd53a7227c1ef1 RX(p2₁) f5136b4378e74bc88339ad09a9575d5c--d6ce4b4b94e0485498dd53a7227c1ef1 8dbd97fd1a8b4a5fbcd73dc4689e3fb2 RY(p2₅) d6ce4b4b94e0485498dd53a7227c1ef1--8dbd97fd1a8b4a5fbcd73dc4689e3fb2 72488cea44284ff0bf4b783021a3f944 RX(p2₉) 8dbd97fd1a8b4a5fbcd73dc4689e3fb2--72488cea44284ff0bf4b783021a3f944 25d2e167e41c4861b9713abd5337817c X 72488cea44284ff0bf4b783021a3f944--25d2e167e41c4861b9713abd5337817c 25d2e167e41c4861b9713abd5337817c--2d43694e044a41ffb5c3c56ec6727230 b516c87ddbc7402f9ead4ebe8b31febe 25d2e167e41c4861b9713abd5337817c--b516c87ddbc7402f9ead4ebe8b31febe 361be583b0e3429c8b169907447ece65 RX(p2₁₃) b516c87ddbc7402f9ead4ebe8b31febe--361be583b0e3429c8b169907447ece65 0ff07746891145e4a699d223ca00fcf1 RY(p2₁₇) 361be583b0e3429c8b169907447ece65--0ff07746891145e4a699d223ca00fcf1 ab3f18c114eb44529f024fa93136a130 RX(p2₂₁) 0ff07746891145e4a699d223ca00fcf1--ab3f18c114eb44529f024fa93136a130 fccd84e5fdd245e89fbaaba099c55fd0 X ab3f18c114eb44529f024fa93136a130--fccd84e5fdd245e89fbaaba099c55fd0 fccd84e5fdd245e89fbaaba099c55fd0--9e2a9fab90424d328f5c7ec58f437d1b 2b9bc3319dad4ad6b25b1c11ffdd2625 fccd84e5fdd245e89fbaaba099c55fd0--2b9bc3319dad4ad6b25b1c11ffdd2625 2b9bc3319dad4ad6b25b1c11ffdd2625--49fbd35dd88a47eaa738e5e448362958 ab9974f3359241a7948e8e15861f6e69 f320c5d6f60343b1a150be8551592c34 RX(p1₂) 0b8b19b0b08e47999c1b2d33d6b66d96--f320c5d6f60343b1a150be8551592c34 31744e50792b41fdb34d534f172e9428 3 0021e20ca7a74ef2954b92c178bc9ee0 RY(p1₆) f320c5d6f60343b1a150be8551592c34--0021e20ca7a74ef2954b92c178bc9ee0 7611c24812c34d52aec33f9d8e23edac RX(p1₁₀) 0021e20ca7a74ef2954b92c178bc9ee0--7611c24812c34d52aec33f9d8e23edac 59d56689d49d43409f0b9ab57ef0b9c6 7611c24812c34d52aec33f9d8e23edac--59d56689d49d43409f0b9ab57ef0b9c6 9edb15d537274e7fb7c8f39fdba222c1 X 59d56689d49d43409f0b9ab57ef0b9c6--9edb15d537274e7fb7c8f39fdba222c1 9edb15d537274e7fb7c8f39fdba222c1--dbf3477312044a039c25fcc8106f79d0 43d6029c59c5454ab52e94d997caabdf RX(p1₁₄) 9edb15d537274e7fb7c8f39fdba222c1--43d6029c59c5454ab52e94d997caabdf 1f98ff5aca474536846defd7e2fc7eac RY(p1₁₈) 43d6029c59c5454ab52e94d997caabdf--1f98ff5aca474536846defd7e2fc7eac 375865f7f5fb4909832ef8a9e8b22f1e RX(p1₂₂) 1f98ff5aca474536846defd7e2fc7eac--375865f7f5fb4909832ef8a9e8b22f1e 3d1811fc296f45e98c75206cb665eefb 375865f7f5fb4909832ef8a9e8b22f1e--3d1811fc296f45e98c75206cb665eefb ebd91aa214b64c108b1d4ac408904685 X 3d1811fc296f45e98c75206cb665eefb--ebd91aa214b64c108b1d4ac408904685 ebd91aa214b64c108b1d4ac408904685--f5136b4378e74bc88339ad09a9575d5c 0befd7556161491e81f13947487d177e RX(p2₂) ebd91aa214b64c108b1d4ac408904685--0befd7556161491e81f13947487d177e 2f027b0277e846e7b095e2b0ee482bdf RY(p2₆) 0befd7556161491e81f13947487d177e--2f027b0277e846e7b095e2b0ee482bdf 9738eb725c7d40868d1ccb6d575b1cc5 RX(p2₁₀) 2f027b0277e846e7b095e2b0ee482bdf--9738eb725c7d40868d1ccb6d575b1cc5 88d8b790825c43dc96857bd2323f2be7 9738eb725c7d40868d1ccb6d575b1cc5--88d8b790825c43dc96857bd2323f2be7 ea216e5fdd454f4a9fe38cdbbb3f32fd X 88d8b790825c43dc96857bd2323f2be7--ea216e5fdd454f4a9fe38cdbbb3f32fd ea216e5fdd454f4a9fe38cdbbb3f32fd--b516c87ddbc7402f9ead4ebe8b31febe d17f945071f44607bc7177aa4fb36107 RX(p2₁₄) ea216e5fdd454f4a9fe38cdbbb3f32fd--d17f945071f44607bc7177aa4fb36107 42dd23b56a8d4fafb2157a09b712a52f RY(p2₁₈) d17f945071f44607bc7177aa4fb36107--42dd23b56a8d4fafb2157a09b712a52f 3835a08c74d543ac9f8de1bfd034e167 RX(p2₂₂) 42dd23b56a8d4fafb2157a09b712a52f--3835a08c74d543ac9f8de1bfd034e167 19e286fe51d747aab5905891ace8f300 3835a08c74d543ac9f8de1bfd034e167--19e286fe51d747aab5905891ace8f300 d033b8f349444ff683f97c500f24ac47 X 19e286fe51d747aab5905891ace8f300--d033b8f349444ff683f97c500f24ac47 d033b8f349444ff683f97c500f24ac47--2b9bc3319dad4ad6b25b1c11ffdd2625 d033b8f349444ff683f97c500f24ac47--ab9974f3359241a7948e8e15861f6e69 4bad89a8bad64afa877105f393e2b83a 7f659f7185ab44b5a59011aa73de740e RX(p1₃) 31744e50792b41fdb34d534f172e9428--7f659f7185ab44b5a59011aa73de740e b6822ba119c942379cb91099323fc26d RY(p1₇) 7f659f7185ab44b5a59011aa73de740e--b6822ba119c942379cb91099323fc26d a1edeee4844b4b4cad57b0165f2532f4 RX(p1₁₁) b6822ba119c942379cb91099323fc26d--a1edeee4844b4b4cad57b0165f2532f4 8d195689aeac44ef8238935b1226eab3 X a1edeee4844b4b4cad57b0165f2532f4--8d195689aeac44ef8238935b1226eab3 8d195689aeac44ef8238935b1226eab3--59d56689d49d43409f0b9ab57ef0b9c6 a0705cbd18f246fe8cfa0492c516dab9 8d195689aeac44ef8238935b1226eab3--a0705cbd18f246fe8cfa0492c516dab9 0bbfed2f37134536ad68ecc8efca6b07 RX(p1₁₅) a0705cbd18f246fe8cfa0492c516dab9--0bbfed2f37134536ad68ecc8efca6b07 6482db6d2b844850901010aefeeeea9e RY(p1₁₉) 0bbfed2f37134536ad68ecc8efca6b07--6482db6d2b844850901010aefeeeea9e ea309da5f0324c11b70ec3a29475eba3 RX(p1₂₃) 6482db6d2b844850901010aefeeeea9e--ea309da5f0324c11b70ec3a29475eba3 aceecbc57add473db764f515b85a44ac X ea309da5f0324c11b70ec3a29475eba3--aceecbc57add473db764f515b85a44ac aceecbc57add473db764f515b85a44ac--3d1811fc296f45e98c75206cb665eefb 8b2cb403abb747958606502d29713576 aceecbc57add473db764f515b85a44ac--8b2cb403abb747958606502d29713576 1ecf49967cd046c9b02ea57f9fc3d1d6 RX(p2₃) 8b2cb403abb747958606502d29713576--1ecf49967cd046c9b02ea57f9fc3d1d6 b0446c4a07de47729406ab3fed4e5ee9 RY(p2₇) 1ecf49967cd046c9b02ea57f9fc3d1d6--b0446c4a07de47729406ab3fed4e5ee9 2024c0ae7f0045daa1297a83c9123331 RX(p2₁₁) b0446c4a07de47729406ab3fed4e5ee9--2024c0ae7f0045daa1297a83c9123331 404bf430100241819a900af39ef530e6 X 2024c0ae7f0045daa1297a83c9123331--404bf430100241819a900af39ef530e6 404bf430100241819a900af39ef530e6--88d8b790825c43dc96857bd2323f2be7 dbb7eca95cc34f4283a9020faa3cfb30 404bf430100241819a900af39ef530e6--dbb7eca95cc34f4283a9020faa3cfb30 7ef57f8ebdf04d20b984654f8f2678c7 RX(p2₁₅) dbb7eca95cc34f4283a9020faa3cfb30--7ef57f8ebdf04d20b984654f8f2678c7 7134c875d4d34382a4ea6e3a537ab257 RY(p2₁₉) 7ef57f8ebdf04d20b984654f8f2678c7--7134c875d4d34382a4ea6e3a537ab257 063ab72779504be7b2d1f975c7e160ae RX(p2₂₃) 7134c875d4d34382a4ea6e3a537ab257--063ab72779504be7b2d1f975c7e160ae ad9927bacc924d29b77e33de45e63749 X 063ab72779504be7b2d1f975c7e160ae--ad9927bacc924d29b77e33de45e63749 ad9927bacc924d29b77e33de45e63749--19e286fe51d747aab5905891ace8f300 685dc74531cf4d74b5e1bd141e0043f2 ad9927bacc924d29b77e33de45e63749--685dc74531cf4d74b5e1bd141e0043f2 685dc74531cf4d74b5e1bd141e0043f2--4bad89a8bad64afa877105f393e2b83a

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)
Variational parameters = OrderedDict([('s', tensor([0.8235])), ('theta_0', tensor([0.2038])), ('theta_1', tensor([0.7853])), ('theta_10', tensor([0.9408])), ('theta_11', tensor([0.4441])), ('theta_12', tensor([0.6926])), ('theta_13', tensor([0.3457])), ('theta_14', tensor([0.6128])), ('theta_15', tensor([0.6174])), ('theta_16', tensor([0.8657])), ('theta_17', tensor([0.8418])), ('theta_18', tensor([0.1063])), ('theta_19', tensor([0.6077])), ('theta_2', tensor([0.2668])), ('theta_20', tensor([0.8846])), ('theta_21', tensor([0.9668])), ('theta_22', tensor([0.2565])), ('theta_23', tensor([0.1043])), ('theta_3', tensor([0.5797])), ('theta_4', tensor([0.4227])), ('theta_5', tensor([0.6723])), ('theta_6', tensor([0.1476])), ('theta_7', tensor([0.6309])), ('theta_8', tensor([0.1834])), ('theta_9', tensor([0.8038]))])

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()
Variational parameters = OrderedDict([('s', tensor([0.8225])), ('theta_0', tensor([0.2048])), ('theta_1', tensor([0.7863])), ('theta_10', tensor([0.9398])), ('theta_11', tensor([0.4451])), ('theta_12', tensor([0.6916])), ('theta_13', tensor([0.3467])), ('theta_14', tensor([0.6118])), ('theta_15', tensor([0.6184])), ('theta_16', tensor([0.8647])), ('theta_17', tensor([0.8408])), ('theta_18', tensor([0.1073])), ('theta_19', tensor([0.6067])), ('theta_2', tensor([0.2658])), ('theta_20', tensor([0.8836])), ('theta_21', tensor([0.9678])), ('theta_22', tensor([0.2555])), ('theta_23', tensor([0.1053])), ('theta_3', tensor([0.5787])), ('theta_4', tensor([0.4217])), ('theta_5', tensor([0.6713])), ('theta_6', tensor([0.1486])), ('theta_7', tensor([0.6319])), ('theta_8', tensor([0.1844])), ('theta_9', tensor([0.8028]))])

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.0j

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.
wf = tensor([[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]])