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.9048+0.0000j, 0.0000-0.4258j]])

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.8776+0.0000j, 0.0000-0.4794j],
        [0.9633+0.0000j, 0.0000-0.2685j]])

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.8746+0.0000j, 0.3181+0.0000j, 0.0000-0.3439j, 0.0000-0.1251j]])

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_98e4c4520b5447d09b5d2676ce64d45a [* 2] cluster_a98a9100fb0847fc93f2bf1e733e141f Rotations f62fb64c08824dc29c5d603513d92c03 0 0b63b9364597486a8f3d383787476459 RX(phi/theta) f62fb64c08824dc29c5d603513d92c03--0b63b9364597486a8f3d383787476459 7698c44136ee46bca53390add9020032 1 eaf0f64f520b42cfb64d153b43ccec4c RX(phi) 0b63b9364597486a8f3d383787476459--eaf0f64f520b42cfb64d153b43ccec4c b389fefdebea43199331909865b0b345 RX(phi) eaf0f64f520b42cfb64d153b43ccec4c--b389fefdebea43199331909865b0b345 ad759cb33dfd41538d40b1ca7ee6b1d1 RX(phi + theta) b389fefdebea43199331909865b0b345--ad759cb33dfd41538d40b1ca7ee6b1d1 275bc930d5d1468bab7affbdac8173ae ad759cb33dfd41538d40b1ca7ee6b1d1--275bc930d5d1468bab7affbdac8173ae 18f29e55a80f4c34ab2a3225f8ea82b7 275bc930d5d1468bab7affbdac8173ae--18f29e55a80f4c34ab2a3225f8ea82b7 9df69c881840446b88e3a0f12a683def Z 18f29e55a80f4c34ab2a3225f8ea82b7--9df69c881840446b88e3a0f12a683def df125cab3b2c44c589c1fc080731e531 9df69c881840446b88e3a0f12a683def--df125cab3b2c44c589c1fc080731e531 ff7c3de9c2b94ca2a1b91ec3ec3f7f22 01be6fa21fe040a8ba3d5c6c31af8bee RY(2*theta) 7698c44136ee46bca53390add9020032--01be6fa21fe040a8ba3d5c6c31af8bee 3324657f556e481d8deed1584960c883 2 508be02a521d4d26a476ba0e6f68d4ff RY(theta) 01be6fa21fe040a8ba3d5c6c31af8bee--508be02a521d4d26a476ba0e6f68d4ff ddbabac12ec94677b413a3db19abaaf5 RY(theta) 508be02a521d4d26a476ba0e6f68d4ff--ddbabac12ec94677b413a3db19abaaf5 f2886a8773dc46c7b3d1dfcbe758d568 RY(theta**2) ddbabac12ec94677b413a3db19abaaf5--f2886a8773dc46c7b3d1dfcbe758d568 0addac31f8ba4adb94d2a88e2daa5120 X f2886a8773dc46c7b3d1dfcbe758d568--0addac31f8ba4adb94d2a88e2daa5120 0addac31f8ba4adb94d2a88e2daa5120--275bc930d5d1468bab7affbdac8173ae d540981345a6470aae77070807f1adc1 0addac31f8ba4adb94d2a88e2daa5120--d540981345a6470aae77070807f1adc1 1302b29ad5494aa496832fd6017bfedc Z d540981345a6470aae77070807f1adc1--1302b29ad5494aa496832fd6017bfedc 1302b29ad5494aa496832fd6017bfedc--ff7c3de9c2b94ca2a1b91ec3ec3f7f22 2ffb78ab4d3f42588a200a35ec4fecab 3d858675b48742cd9dfc5ddbee910dd7 RZ(cos(phi)) 3324657f556e481d8deed1584960c883--3d858675b48742cd9dfc5ddbee910dd7 0bcf5a1b247848348eaee08117912aee RZ(phi) 3d858675b48742cd9dfc5ddbee910dd7--0bcf5a1b247848348eaee08117912aee 5b709451cdc44cf99b97eff3d027c9c4 RZ(phi) 0bcf5a1b247848348eaee08117912aee--5b709451cdc44cf99b97eff3d027c9c4 a22ef5444b9646be8842bfc6082698cb RZ(cos(phi)) 5b709451cdc44cf99b97eff3d027c9c4--a22ef5444b9646be8842bfc6082698cb f6e0f26aeb2a4ead904f82626ede3ef4 a22ef5444b9646be8842bfc6082698cb--f6e0f26aeb2a4ead904f82626ede3ef4 6d807f5d99644dc7bad9991ac9f811e3 X f6e0f26aeb2a4ead904f82626ede3ef4--6d807f5d99644dc7bad9991ac9f811e3 6d807f5d99644dc7bad9991ac9f811e3--d540981345a6470aae77070807f1adc1 2d595c687a02463f9297983d9870acf4 Z 6d807f5d99644dc7bad9991ac9f811e3--2d595c687a02463f9297983d9870acf4 2d595c687a02463f9297983d9870acf4--2ffb78ab4d3f42588a200a35ec4fecab

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.6122]))])

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.8583+0.0000j, 0.3487+0.0000j, 0.0000-0.3487j, 0.0000-0.1417j],
        [0.9034+0.0000j, 0.2954+0.0000j, 0.0000-0.2954j, 0.0000-0.0966j],
        [0.6968+0.0000j, 0.4597+0.0000j, 0.0000-0.4597j, 0.0000-0.3032j]],
       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 ddd4289519894cee9e8dd749d35de386 0 418bff578dd54ab6a823bb71b8eee4ae RX(theta₀) ddd4289519894cee9e8dd749d35de386--418bff578dd54ab6a823bb71b8eee4ae 3357ca8ae83c4da5a71641ac3357bcc5 1 674cd61f05e4445fa6440a9254a36f3d RY(theta₄) 418bff578dd54ab6a823bb71b8eee4ae--674cd61f05e4445fa6440a9254a36f3d 577026fafa5e40ad97d67794c38d4fef RX(theta₈) 674cd61f05e4445fa6440a9254a36f3d--577026fafa5e40ad97d67794c38d4fef cd2a48a7810549cd82a54c63def85b06 577026fafa5e40ad97d67794c38d4fef--cd2a48a7810549cd82a54c63def85b06 d704c7306f644a89ab3f019a7838beb9 cd2a48a7810549cd82a54c63def85b06--d704c7306f644a89ab3f019a7838beb9 34f42f0411694a749fb2cc61f10a1253 RX(theta₁₂) d704c7306f644a89ab3f019a7838beb9--34f42f0411694a749fb2cc61f10a1253 8aee06a85ab54e18b098224122190201 RY(theta₁₆) 34f42f0411694a749fb2cc61f10a1253--8aee06a85ab54e18b098224122190201 b262132757d949c087a2577f0e952494 RX(theta₂₀) 8aee06a85ab54e18b098224122190201--b262132757d949c087a2577f0e952494 5877440b9bf54733a32a6269b42291fb b262132757d949c087a2577f0e952494--5877440b9bf54733a32a6269b42291fb d752925e4cb4475ba38ca9529554d677 5877440b9bf54733a32a6269b42291fb--d752925e4cb4475ba38ca9529554d677 79059a8ccc8448289aa4a84ab315b2d2 d752925e4cb4475ba38ca9529554d677--79059a8ccc8448289aa4a84ab315b2d2 3f505daad9dc4a7993cf2b1945867b51 da90ffb1da1c4c3bbca98325caf9ce70 RX(theta₁) 3357ca8ae83c4da5a71641ac3357bcc5--da90ffb1da1c4c3bbca98325caf9ce70 74afd42b01a14604b6bbcf7d6332f429 2 f4a34e7088fc435bb32006c959af34d0 RY(theta₅) da90ffb1da1c4c3bbca98325caf9ce70--f4a34e7088fc435bb32006c959af34d0 e969825f62d04ecaa467833d72816db9 RX(theta₉) f4a34e7088fc435bb32006c959af34d0--e969825f62d04ecaa467833d72816db9 e8680879bc7e4ce8a8893dfa4df76c3c X e969825f62d04ecaa467833d72816db9--e8680879bc7e4ce8a8893dfa4df76c3c e8680879bc7e4ce8a8893dfa4df76c3c--cd2a48a7810549cd82a54c63def85b06 3205ea0708a546309c98deb094315dfb e8680879bc7e4ce8a8893dfa4df76c3c--3205ea0708a546309c98deb094315dfb 55bea6e0c5f24e2982bad704baf232c2 RX(theta₁₃) 3205ea0708a546309c98deb094315dfb--55bea6e0c5f24e2982bad704baf232c2 b33f4dd602444d63a911a8bd0211a423 RY(theta₁₇) 55bea6e0c5f24e2982bad704baf232c2--b33f4dd602444d63a911a8bd0211a423 086a3179d794424abed0254726ac9b7d RX(theta₂₁) b33f4dd602444d63a911a8bd0211a423--086a3179d794424abed0254726ac9b7d 3e6cc5c5511047c0abe84b7112504938 X 086a3179d794424abed0254726ac9b7d--3e6cc5c5511047c0abe84b7112504938 3e6cc5c5511047c0abe84b7112504938--5877440b9bf54733a32a6269b42291fb 8ae0adad1f514c629518dba3a89dd2e4 3e6cc5c5511047c0abe84b7112504938--8ae0adad1f514c629518dba3a89dd2e4 8ae0adad1f514c629518dba3a89dd2e4--3f505daad9dc4a7993cf2b1945867b51 01a94fc6a48c4b1bb0e37834077aaf15 11dcbdb87c1d4d1a931269bf1b65954c RX(theta₂) 74afd42b01a14604b6bbcf7d6332f429--11dcbdb87c1d4d1a931269bf1b65954c 5d9b08f329014c4bbc09b4914b6320c7 3 39b42c5bd1a748dfa85011c7d547e39c RY(theta₆) 11dcbdb87c1d4d1a931269bf1b65954c--39b42c5bd1a748dfa85011c7d547e39c 40d9ed02ef9546dba95da1a51cf10e21 RX(theta₁₀) 39b42c5bd1a748dfa85011c7d547e39c--40d9ed02ef9546dba95da1a51cf10e21 94c67d3520624d4eabf4d61270faf92f 40d9ed02ef9546dba95da1a51cf10e21--94c67d3520624d4eabf4d61270faf92f ab37ff7b52d94576aa1cba18abe9c78f X 94c67d3520624d4eabf4d61270faf92f--ab37ff7b52d94576aa1cba18abe9c78f ab37ff7b52d94576aa1cba18abe9c78f--3205ea0708a546309c98deb094315dfb 74527da4f7034bfbb4d50259bc174732 RX(theta₁₄) ab37ff7b52d94576aa1cba18abe9c78f--74527da4f7034bfbb4d50259bc174732 27c5b9e903194662b85bd526291fff5f RY(theta₁₈) 74527da4f7034bfbb4d50259bc174732--27c5b9e903194662b85bd526291fff5f 4560c06931d74568b6192d0cbae728d1 RX(theta₂₂) 27c5b9e903194662b85bd526291fff5f--4560c06931d74568b6192d0cbae728d1 458b3db303bd4931a2437122ac8d3607 4560c06931d74568b6192d0cbae728d1--458b3db303bd4931a2437122ac8d3607 bf2d0e88cc0341128e7b6bc902103795 X 458b3db303bd4931a2437122ac8d3607--bf2d0e88cc0341128e7b6bc902103795 bf2d0e88cc0341128e7b6bc902103795--8ae0adad1f514c629518dba3a89dd2e4 bf2d0e88cc0341128e7b6bc902103795--01a94fc6a48c4b1bb0e37834077aaf15 fd7a760bde7d418bb1ea2c3d3b9be843 18db448e39d4432e934ff38e7170d8fc RX(theta₃) 5d9b08f329014c4bbc09b4914b6320c7--18db448e39d4432e934ff38e7170d8fc 483899303d3e424689d7da8ce7167d1f RY(theta₇) 18db448e39d4432e934ff38e7170d8fc--483899303d3e424689d7da8ce7167d1f f43a7cb4061f46fdb3b0db63cd5df5fa RX(theta₁₁) 483899303d3e424689d7da8ce7167d1f--f43a7cb4061f46fdb3b0db63cd5df5fa 805016d7ca194b438fd8437ff16f3e0e X f43a7cb4061f46fdb3b0db63cd5df5fa--805016d7ca194b438fd8437ff16f3e0e 805016d7ca194b438fd8437ff16f3e0e--94c67d3520624d4eabf4d61270faf92f 80d331c9260d456a923823f6623eaeea 805016d7ca194b438fd8437ff16f3e0e--80d331c9260d456a923823f6623eaeea 073803ab085647e7b0580f17a46ef619 RX(theta₁₅) 80d331c9260d456a923823f6623eaeea--073803ab085647e7b0580f17a46ef619 049ad9725e324194844e7ecd18bd94ed RY(theta₁₉) 073803ab085647e7b0580f17a46ef619--049ad9725e324194844e7ecd18bd94ed 8a56967f95a9481e88f1afa21c1e7c04 RX(theta₂₃) 049ad9725e324194844e7ecd18bd94ed--8a56967f95a9481e88f1afa21c1e7c04 d39fc4ad363744f99ccbf7ff23fa1084 X 8a56967f95a9481e88f1afa21c1e7c04--d39fc4ad363744f99ccbf7ff23fa1084 d39fc4ad363744f99ccbf7ff23fa1084--458b3db303bd4931a2437122ac8d3607 594b46eb03a1405eb538f0b0a9fc5646 d39fc4ad363744f99ccbf7ff23fa1084--594b46eb03a1405eb538f0b0a9fc5646 594b46eb03a1405eb538f0b0a9fc5646--fd7a760bde7d418bb1ea2c3d3b9be843

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_de4536714c7e48cfa98f006f7f061345 HEA cluster_100b443537d548c48b6d25ee96c6398f HEA 85c94ceec13b4b01ac1204dabd1980ef 0 7a916c92c6b148729ec0779714d1586f RX(theta₀) 85c94ceec13b4b01ac1204dabd1980ef--7a916c92c6b148729ec0779714d1586f 4bb6c2fbcfaa4d2086ba492b2f7e13be 1 2d1bf2076e964d11b94b9ea885be990d RY(theta₄) 7a916c92c6b148729ec0779714d1586f--2d1bf2076e964d11b94b9ea885be990d f050478e69da4b29abce6a98cd346e1b RX(theta₈) 2d1bf2076e964d11b94b9ea885be990d--f050478e69da4b29abce6a98cd346e1b 256bfc78f0a54c0ab727450755387519 f050478e69da4b29abce6a98cd346e1b--256bfc78f0a54c0ab727450755387519 d5e0e368626c4a7eb7a7f2cf21050870 256bfc78f0a54c0ab727450755387519--d5e0e368626c4a7eb7a7f2cf21050870 f4a6b31e381b4319a8d9fb411129068a RX(theta₁₂) d5e0e368626c4a7eb7a7f2cf21050870--f4a6b31e381b4319a8d9fb411129068a 0753ce5197b74c46865ff872e65bdda5 RY(theta₁₆) f4a6b31e381b4319a8d9fb411129068a--0753ce5197b74c46865ff872e65bdda5 ac86d803345f4a8b90efb90ccc1fe4e8 RX(theta₂₀) 0753ce5197b74c46865ff872e65bdda5--ac86d803345f4a8b90efb90ccc1fe4e8 1e9d1ce71c164b10864840c5152c9eb8 ac86d803345f4a8b90efb90ccc1fe4e8--1e9d1ce71c164b10864840c5152c9eb8 6bf3aac8185046f98d513ca04baa1223 1e9d1ce71c164b10864840c5152c9eb8--6bf3aac8185046f98d513ca04baa1223 726e0d52de4843b39301c3027fcc4932 RX(theta₀) 6bf3aac8185046f98d513ca04baa1223--726e0d52de4843b39301c3027fcc4932 82eb1dfd469b4022ada24af2fb02e012 RY(theta₄) 726e0d52de4843b39301c3027fcc4932--82eb1dfd469b4022ada24af2fb02e012 2beb92cd64f84962be2a35d903fba9ae RX(theta₈) 82eb1dfd469b4022ada24af2fb02e012--2beb92cd64f84962be2a35d903fba9ae 4e848ee16f7d45c88f1a9f650fd1eef3 2beb92cd64f84962be2a35d903fba9ae--4e848ee16f7d45c88f1a9f650fd1eef3 132b6cb77ab94cc8a5fbdab2083e59d3 4e848ee16f7d45c88f1a9f650fd1eef3--132b6cb77ab94cc8a5fbdab2083e59d3 09cc58aa5e9d4f8080afbad2f17ef0c8 RX(theta₁₂) 132b6cb77ab94cc8a5fbdab2083e59d3--09cc58aa5e9d4f8080afbad2f17ef0c8 94d4fee1ebf24c94a5d8bf8dcb0393b7 RY(theta₁₆) 09cc58aa5e9d4f8080afbad2f17ef0c8--94d4fee1ebf24c94a5d8bf8dcb0393b7 ecaf451b32bf49c2b1c9304ed0b8438e RX(theta₂₀) 94d4fee1ebf24c94a5d8bf8dcb0393b7--ecaf451b32bf49c2b1c9304ed0b8438e 05bb2c9f8a65496a8b6ee1acaa438e6b ecaf451b32bf49c2b1c9304ed0b8438e--05bb2c9f8a65496a8b6ee1acaa438e6b 79666b978a2a4a0c99df0657df9ae71e 05bb2c9f8a65496a8b6ee1acaa438e6b--79666b978a2a4a0c99df0657df9ae71e 5374948214d24a0991adee4be3ab1319 79666b978a2a4a0c99df0657df9ae71e--5374948214d24a0991adee4be3ab1319 830396d826f14448a3e41a43df373ccb 42cddec7dadf448094378bdc667749ee RX(theta₁) 4bb6c2fbcfaa4d2086ba492b2f7e13be--42cddec7dadf448094378bdc667749ee 461ccefecc6f434196ac00359a17fd9c 2 533669443f164bb4ac2a95b399bcf209 RY(theta₅) 42cddec7dadf448094378bdc667749ee--533669443f164bb4ac2a95b399bcf209 2a4e54b73d7f4693a44b0ce6e04f9912 RX(theta₉) 533669443f164bb4ac2a95b399bcf209--2a4e54b73d7f4693a44b0ce6e04f9912 b7dc3d2b0f0748c3bed82ce1e6727012 X 2a4e54b73d7f4693a44b0ce6e04f9912--b7dc3d2b0f0748c3bed82ce1e6727012 b7dc3d2b0f0748c3bed82ce1e6727012--256bfc78f0a54c0ab727450755387519 8a81bd9cab90460880bc42acfe0caaec b7dc3d2b0f0748c3bed82ce1e6727012--8a81bd9cab90460880bc42acfe0caaec 376154f6042e4bf69451e13b525ac4ae RX(theta₁₃) 8a81bd9cab90460880bc42acfe0caaec--376154f6042e4bf69451e13b525ac4ae 6a75e9420c02409ca65f04d4e10913ad RY(theta₁₇) 376154f6042e4bf69451e13b525ac4ae--6a75e9420c02409ca65f04d4e10913ad df9557c5a43d40b998e4f4880af17d62 RX(theta₂₁) 6a75e9420c02409ca65f04d4e10913ad--df9557c5a43d40b998e4f4880af17d62 70c48c4a1be74a2cb5cbfd4c70942936 X df9557c5a43d40b998e4f4880af17d62--70c48c4a1be74a2cb5cbfd4c70942936 70c48c4a1be74a2cb5cbfd4c70942936--1e9d1ce71c164b10864840c5152c9eb8 58be7c55c12d47089df4846b1ec0fe4c 70c48c4a1be74a2cb5cbfd4c70942936--58be7c55c12d47089df4846b1ec0fe4c f454d0bf7f974ca1831cb92585a3fa24 RX(theta₁) 58be7c55c12d47089df4846b1ec0fe4c--f454d0bf7f974ca1831cb92585a3fa24 d3d07770edd548b3b93d5025e7a0fdeb RY(theta₅) f454d0bf7f974ca1831cb92585a3fa24--d3d07770edd548b3b93d5025e7a0fdeb b3826ed3b3764ec18e2eae58521d3039 RX(theta₉) d3d07770edd548b3b93d5025e7a0fdeb--b3826ed3b3764ec18e2eae58521d3039 74b9f8f59c2a4cca8676f37eabc74d65 X b3826ed3b3764ec18e2eae58521d3039--74b9f8f59c2a4cca8676f37eabc74d65 74b9f8f59c2a4cca8676f37eabc74d65--4e848ee16f7d45c88f1a9f650fd1eef3 284870795f1a4ca787fc36ef92c78cf4 74b9f8f59c2a4cca8676f37eabc74d65--284870795f1a4ca787fc36ef92c78cf4 c5c615adb1a24e5baabfb9dd66f09dd1 RX(theta₁₃) 284870795f1a4ca787fc36ef92c78cf4--c5c615adb1a24e5baabfb9dd66f09dd1 194b510163294a39905788c794206445 RY(theta₁₇) c5c615adb1a24e5baabfb9dd66f09dd1--194b510163294a39905788c794206445 b535aae6766648c08d83ccc2203e06f7 RX(theta₂₁) 194b510163294a39905788c794206445--b535aae6766648c08d83ccc2203e06f7 e5f616394239408cbbe2674e516a5431 X b535aae6766648c08d83ccc2203e06f7--e5f616394239408cbbe2674e516a5431 e5f616394239408cbbe2674e516a5431--05bb2c9f8a65496a8b6ee1acaa438e6b afbcdee80dc045d5b1b27cec3772493f e5f616394239408cbbe2674e516a5431--afbcdee80dc045d5b1b27cec3772493f afbcdee80dc045d5b1b27cec3772493f--830396d826f14448a3e41a43df373ccb 02bf015066164c78866c97c3342b4a18 213c21d86b034a26a66e18865e7c105b RX(theta₂) 461ccefecc6f434196ac00359a17fd9c--213c21d86b034a26a66e18865e7c105b b61159332a234e01b7e4cca1bb2e5487 3 2ed15cfa12aa4dd681fc54ee14f5c6c8 RY(theta₆) 213c21d86b034a26a66e18865e7c105b--2ed15cfa12aa4dd681fc54ee14f5c6c8 9354adae048f497b8d46a33b74eb3513 RX(theta₁₀) 2ed15cfa12aa4dd681fc54ee14f5c6c8--9354adae048f497b8d46a33b74eb3513 d56cd195a6064904bdd47deddbec3257 9354adae048f497b8d46a33b74eb3513--d56cd195a6064904bdd47deddbec3257 11b23e3ce7f04fca90b56861c17b5d1a X d56cd195a6064904bdd47deddbec3257--11b23e3ce7f04fca90b56861c17b5d1a 11b23e3ce7f04fca90b56861c17b5d1a--8a81bd9cab90460880bc42acfe0caaec 8953b27e7e2d48a9a6fbe2391c477f95 RX(theta₁₄) 11b23e3ce7f04fca90b56861c17b5d1a--8953b27e7e2d48a9a6fbe2391c477f95 b7ebc7999392492aa303b34730e01c2f RY(theta₁₈) 8953b27e7e2d48a9a6fbe2391c477f95--b7ebc7999392492aa303b34730e01c2f 0d9be2e42dcb4fb49ee9d667988602cf RX(theta₂₂) b7ebc7999392492aa303b34730e01c2f--0d9be2e42dcb4fb49ee9d667988602cf 8c4dd38fe8b842e7a5a38098346a596b 0d9be2e42dcb4fb49ee9d667988602cf--8c4dd38fe8b842e7a5a38098346a596b eeb0f4f081864c8a89c538ab2573d4a5 X 8c4dd38fe8b842e7a5a38098346a596b--eeb0f4f081864c8a89c538ab2573d4a5 eeb0f4f081864c8a89c538ab2573d4a5--58be7c55c12d47089df4846b1ec0fe4c 25a44396cc9e4c41a02a3e4c657ebd53 RX(theta₂) eeb0f4f081864c8a89c538ab2573d4a5--25a44396cc9e4c41a02a3e4c657ebd53 230ea43f65fe4395bd9a53d95816c5d1 RY(theta₆) 25a44396cc9e4c41a02a3e4c657ebd53--230ea43f65fe4395bd9a53d95816c5d1 705acf68e03449b19247cf1f02e29da1 RX(theta₁₀) 230ea43f65fe4395bd9a53d95816c5d1--705acf68e03449b19247cf1f02e29da1 7149959237de4be696e199e3dfa1f567 705acf68e03449b19247cf1f02e29da1--7149959237de4be696e199e3dfa1f567 17660eec0c754e66a33ffa7c04ab2dd9 X 7149959237de4be696e199e3dfa1f567--17660eec0c754e66a33ffa7c04ab2dd9 17660eec0c754e66a33ffa7c04ab2dd9--284870795f1a4ca787fc36ef92c78cf4 61cbb324c1c84ad4bc5cf24096dbe267 RX(theta₁₄) 17660eec0c754e66a33ffa7c04ab2dd9--61cbb324c1c84ad4bc5cf24096dbe267 ece876f6fa4b4b38af49bb016999b27d RY(theta₁₈) 61cbb324c1c84ad4bc5cf24096dbe267--ece876f6fa4b4b38af49bb016999b27d a174ad1b88c54b42aa490f07f25b7f9e RX(theta₂₂) ece876f6fa4b4b38af49bb016999b27d--a174ad1b88c54b42aa490f07f25b7f9e 9398ad0a53e5496bad33a21fc7df5035 a174ad1b88c54b42aa490f07f25b7f9e--9398ad0a53e5496bad33a21fc7df5035 9e11adf0943d4d87af4363f04be5d61c X 9398ad0a53e5496bad33a21fc7df5035--9e11adf0943d4d87af4363f04be5d61c 9e11adf0943d4d87af4363f04be5d61c--afbcdee80dc045d5b1b27cec3772493f 9e11adf0943d4d87af4363f04be5d61c--02bf015066164c78866c97c3342b4a18 ddda53e2f8944942b0f77800452ae90a 16389e4f45934027bb6f4f495340e122 RX(theta₃) b61159332a234e01b7e4cca1bb2e5487--16389e4f45934027bb6f4f495340e122 6652b018553946bebd5297b6d0093222 RY(theta₇) 16389e4f45934027bb6f4f495340e122--6652b018553946bebd5297b6d0093222 ae979ca444fe424692ceba8f8852b50d RX(theta₁₁) 6652b018553946bebd5297b6d0093222--ae979ca444fe424692ceba8f8852b50d d0a9f0bbc45c4fac965ed5b041757c80 X ae979ca444fe424692ceba8f8852b50d--d0a9f0bbc45c4fac965ed5b041757c80 d0a9f0bbc45c4fac965ed5b041757c80--d56cd195a6064904bdd47deddbec3257 6b298c9a088c4e9c8c2b7fb87a61e40e d0a9f0bbc45c4fac965ed5b041757c80--6b298c9a088c4e9c8c2b7fb87a61e40e ac42a47bf21b4132a3e73a5e142b550e RX(theta₁₅) 6b298c9a088c4e9c8c2b7fb87a61e40e--ac42a47bf21b4132a3e73a5e142b550e a08c2bc3f4954be4b8d619617ba35862 RY(theta₁₉) ac42a47bf21b4132a3e73a5e142b550e--a08c2bc3f4954be4b8d619617ba35862 0f331fd4a2c9401bbd509ad3da41b214 RX(theta₂₃) a08c2bc3f4954be4b8d619617ba35862--0f331fd4a2c9401bbd509ad3da41b214 104e112aba1d4510b4df9de40824bfea X 0f331fd4a2c9401bbd509ad3da41b214--104e112aba1d4510b4df9de40824bfea 104e112aba1d4510b4df9de40824bfea--8c4dd38fe8b842e7a5a38098346a596b 5121a0501d20455cb02127efa745ac88 104e112aba1d4510b4df9de40824bfea--5121a0501d20455cb02127efa745ac88 0b9f92c960234eb79daa119b427db539 RX(theta₃) 5121a0501d20455cb02127efa745ac88--0b9f92c960234eb79daa119b427db539 1137ebb77bdc42238c281b1ff7e7f954 RY(theta₇) 0b9f92c960234eb79daa119b427db539--1137ebb77bdc42238c281b1ff7e7f954 4edf5ca2518e4d9c91b1442a577f9770 RX(theta₁₁) 1137ebb77bdc42238c281b1ff7e7f954--4edf5ca2518e4d9c91b1442a577f9770 5c099541a36e4acf9e4e73ae989863e5 X 4edf5ca2518e4d9c91b1442a577f9770--5c099541a36e4acf9e4e73ae989863e5 5c099541a36e4acf9e4e73ae989863e5--7149959237de4be696e199e3dfa1f567 bf55175f57674e0b95e1c96750613f22 5c099541a36e4acf9e4e73ae989863e5--bf55175f57674e0b95e1c96750613f22 8c4f2d6af6ac4b399a3a26f48369ba53 RX(theta₁₅) bf55175f57674e0b95e1c96750613f22--8c4f2d6af6ac4b399a3a26f48369ba53 d93fab496ad34044ac8fa31350130e5d RY(theta₁₉) 8c4f2d6af6ac4b399a3a26f48369ba53--d93fab496ad34044ac8fa31350130e5d fe0f4320c07a49f7abaf0b42439a2541 RX(theta₂₃) d93fab496ad34044ac8fa31350130e5d--fe0f4320c07a49f7abaf0b42439a2541 55be8dae684c476bb27e2aed4c271a5f X fe0f4320c07a49f7abaf0b42439a2541--55be8dae684c476bb27e2aed4c271a5f 55be8dae684c476bb27e2aed4c271a5f--9398ad0a53e5496bad33a21fc7df5035 257aa5e10ed54ceebb22febe474842fd 55be8dae684c476bb27e2aed4c271a5f--257aa5e10ed54ceebb22febe474842fd 257aa5e10ed54ceebb22febe474842fd--ddda53e2f8944942b0f77800452ae90a

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_8eb9a1035f7b476c99b903bbb5568413 HEA cluster_38b13d9955604a65bc2bbc69ee9a0ab7 HEA b5a789caed7f40e0ace5ea79f48938a2 0 3bc31cc2b29b44b6849cd6f1c1d4400e RX(p1₀) b5a789caed7f40e0ace5ea79f48938a2--3bc31cc2b29b44b6849cd6f1c1d4400e d5cd9c54b2204a2da5211bcdb63df9d2 1 59d3112afb7546069146e773d38265ea RY(p1₄) 3bc31cc2b29b44b6849cd6f1c1d4400e--59d3112afb7546069146e773d38265ea 991cf5534385450ca8d484df6f021086 RX(p1₈) 59d3112afb7546069146e773d38265ea--991cf5534385450ca8d484df6f021086 4c3dfd3595b64c4686548a31e84e1ea3 991cf5534385450ca8d484df6f021086--4c3dfd3595b64c4686548a31e84e1ea3 e30af62f13e44c298a7e1465f86c89df 4c3dfd3595b64c4686548a31e84e1ea3--e30af62f13e44c298a7e1465f86c89df f3e8e9cbdd7f456abc0d665f3a576f7f RX(p1₁₂) e30af62f13e44c298a7e1465f86c89df--f3e8e9cbdd7f456abc0d665f3a576f7f d8dd8285ddd74a2196fada2788150434 RY(p1₁₆) f3e8e9cbdd7f456abc0d665f3a576f7f--d8dd8285ddd74a2196fada2788150434 ce857fbfb3c247b7aeec72c48d77c8c9 RX(p1₂₀) d8dd8285ddd74a2196fada2788150434--ce857fbfb3c247b7aeec72c48d77c8c9 5e03f0ada9c2496c8f09e9650b4eae9d ce857fbfb3c247b7aeec72c48d77c8c9--5e03f0ada9c2496c8f09e9650b4eae9d be484f84b5b747bc84139fdf8e3de452 5e03f0ada9c2496c8f09e9650b4eae9d--be484f84b5b747bc84139fdf8e3de452 3967d02cc00f48ab85f6da6c8a01ec84 RX(p2₀) be484f84b5b747bc84139fdf8e3de452--3967d02cc00f48ab85f6da6c8a01ec84 0ef9f3874e434419a1ad90f3f5c6044e RY(p2₄) 3967d02cc00f48ab85f6da6c8a01ec84--0ef9f3874e434419a1ad90f3f5c6044e 938aa6bc1d384191afce39ef6a63ce5c RX(p2₈) 0ef9f3874e434419a1ad90f3f5c6044e--938aa6bc1d384191afce39ef6a63ce5c 060523327fbb431282d8bdaac481d826 938aa6bc1d384191afce39ef6a63ce5c--060523327fbb431282d8bdaac481d826 aeccf1e26a5a40169d8d3c052e9248d0 060523327fbb431282d8bdaac481d826--aeccf1e26a5a40169d8d3c052e9248d0 18e3f8584f21422b89261fe230860abf RX(p2₁₂) aeccf1e26a5a40169d8d3c052e9248d0--18e3f8584f21422b89261fe230860abf 348f784bcb984e21994023ce82c97940 RY(p2₁₆) 18e3f8584f21422b89261fe230860abf--348f784bcb984e21994023ce82c97940 4bdceed7b8bb4bc19d8349a18640a2ce RX(p2₂₀) 348f784bcb984e21994023ce82c97940--4bdceed7b8bb4bc19d8349a18640a2ce 264b14b8f9c8435ca5f3f48668d48d3c 4bdceed7b8bb4bc19d8349a18640a2ce--264b14b8f9c8435ca5f3f48668d48d3c 1ed287ec2ac745aabc677c29122d5c2c 264b14b8f9c8435ca5f3f48668d48d3c--1ed287ec2ac745aabc677c29122d5c2c e80a856408944479bec0815a5066e4e8 1ed287ec2ac745aabc677c29122d5c2c--e80a856408944479bec0815a5066e4e8 f6ff66e27cdc4419a47393480c777007 57f1b69efea841b699c39228136fcc41 RX(p1₁) d5cd9c54b2204a2da5211bcdb63df9d2--57f1b69efea841b699c39228136fcc41 06249adecebd4367ad21c09df8125617 2 a8928b7c11f144528386961d61fbcb4a RY(p1₅) 57f1b69efea841b699c39228136fcc41--a8928b7c11f144528386961d61fbcb4a d767b40381ea4c2f923049024af2b85d RX(p1₉) a8928b7c11f144528386961d61fbcb4a--d767b40381ea4c2f923049024af2b85d 5331a977dfd544dc94f326cc40c8f8b9 X d767b40381ea4c2f923049024af2b85d--5331a977dfd544dc94f326cc40c8f8b9 5331a977dfd544dc94f326cc40c8f8b9--4c3dfd3595b64c4686548a31e84e1ea3 4fb76a59f9664ebb858bba78ab6d1ea5 5331a977dfd544dc94f326cc40c8f8b9--4fb76a59f9664ebb858bba78ab6d1ea5 a5d5ce6a2c2d47f7b36e082a6463a867 RX(p1₁₃) 4fb76a59f9664ebb858bba78ab6d1ea5--a5d5ce6a2c2d47f7b36e082a6463a867 307a16eb69054774946d69a51080a99b RY(p1₁₇) a5d5ce6a2c2d47f7b36e082a6463a867--307a16eb69054774946d69a51080a99b 4fdeccfc90134c68b241c50e76d3df82 RX(p1₂₁) 307a16eb69054774946d69a51080a99b--4fdeccfc90134c68b241c50e76d3df82 4e222f496cb545f3af6837b8672c1557 X 4fdeccfc90134c68b241c50e76d3df82--4e222f496cb545f3af6837b8672c1557 4e222f496cb545f3af6837b8672c1557--5e03f0ada9c2496c8f09e9650b4eae9d e3721931c1d943d0b9e0ab4e10eac87e 4e222f496cb545f3af6837b8672c1557--e3721931c1d943d0b9e0ab4e10eac87e ffaf885da6364a5e88da20c2f445057d RX(p2₁) e3721931c1d943d0b9e0ab4e10eac87e--ffaf885da6364a5e88da20c2f445057d d966f83db5cd467e917e6e635d2f3880 RY(p2₅) ffaf885da6364a5e88da20c2f445057d--d966f83db5cd467e917e6e635d2f3880 155688270f57412bb8ada54471ebb617 RX(p2₉) d966f83db5cd467e917e6e635d2f3880--155688270f57412bb8ada54471ebb617 562329692b5849de92c8b0c35bd441f1 X 155688270f57412bb8ada54471ebb617--562329692b5849de92c8b0c35bd441f1 562329692b5849de92c8b0c35bd441f1--060523327fbb431282d8bdaac481d826 9822c5f7d2304ec0b80f9054aba53f0f 562329692b5849de92c8b0c35bd441f1--9822c5f7d2304ec0b80f9054aba53f0f 058ffe160c8b420599c65d9dc4f82545 RX(p2₁₃) 9822c5f7d2304ec0b80f9054aba53f0f--058ffe160c8b420599c65d9dc4f82545 4802b618552a4d34b373e9a68ba7f204 RY(p2₁₇) 058ffe160c8b420599c65d9dc4f82545--4802b618552a4d34b373e9a68ba7f204 367a9d3ba1914aed8a9677b44bbb4bc8 RX(p2₂₁) 4802b618552a4d34b373e9a68ba7f204--367a9d3ba1914aed8a9677b44bbb4bc8 f979e787755a4f93848cae9034551d7d X 367a9d3ba1914aed8a9677b44bbb4bc8--f979e787755a4f93848cae9034551d7d f979e787755a4f93848cae9034551d7d--264b14b8f9c8435ca5f3f48668d48d3c b11103f17bc944148f610f229b020591 f979e787755a4f93848cae9034551d7d--b11103f17bc944148f610f229b020591 b11103f17bc944148f610f229b020591--f6ff66e27cdc4419a47393480c777007 b841dbfbe3964a9b9686baf3eafffc86 168a99ca0b994a969dad78d0e31b3ee7 RX(p1₂) 06249adecebd4367ad21c09df8125617--168a99ca0b994a969dad78d0e31b3ee7 3fa0ff67739b4f4387b91e3fbab10d3f 3 363f779aaf90402b9aebe892f83957d4 RY(p1₆) 168a99ca0b994a969dad78d0e31b3ee7--363f779aaf90402b9aebe892f83957d4 74af1264545447eea39d001ebccf66a1 RX(p1₁₀) 363f779aaf90402b9aebe892f83957d4--74af1264545447eea39d001ebccf66a1 be774b88e3704eaab5ba8d9a0fd8b567 74af1264545447eea39d001ebccf66a1--be774b88e3704eaab5ba8d9a0fd8b567 7dea546841c54c4196d070e6d1cc3a92 X be774b88e3704eaab5ba8d9a0fd8b567--7dea546841c54c4196d070e6d1cc3a92 7dea546841c54c4196d070e6d1cc3a92--4fb76a59f9664ebb858bba78ab6d1ea5 0f85f01cec604ef7a9f5f2db6bf19e22 RX(p1₁₄) 7dea546841c54c4196d070e6d1cc3a92--0f85f01cec604ef7a9f5f2db6bf19e22 8d0b3eb070b94a3380801f95141fd96f RY(p1₁₈) 0f85f01cec604ef7a9f5f2db6bf19e22--8d0b3eb070b94a3380801f95141fd96f 128f415347b0438ca15ded7ead64d013 RX(p1₂₂) 8d0b3eb070b94a3380801f95141fd96f--128f415347b0438ca15ded7ead64d013 80f989db846945c6ad8b18d1541dd63f 128f415347b0438ca15ded7ead64d013--80f989db846945c6ad8b18d1541dd63f 9ef428284e25419b9c5535915df599fe X 80f989db846945c6ad8b18d1541dd63f--9ef428284e25419b9c5535915df599fe 9ef428284e25419b9c5535915df599fe--e3721931c1d943d0b9e0ab4e10eac87e c0bc2bd0b7fe4f5caa685b60def3c4d3 RX(p2₂) 9ef428284e25419b9c5535915df599fe--c0bc2bd0b7fe4f5caa685b60def3c4d3 d3e071f7ff4b4661abbebf6020c9a63c RY(p2₆) c0bc2bd0b7fe4f5caa685b60def3c4d3--d3e071f7ff4b4661abbebf6020c9a63c 3313f4d69ea2448fbbfbae5a4330c7d0 RX(p2₁₀) d3e071f7ff4b4661abbebf6020c9a63c--3313f4d69ea2448fbbfbae5a4330c7d0 afb12c8e8ace4b04a50f8426c783d10e 3313f4d69ea2448fbbfbae5a4330c7d0--afb12c8e8ace4b04a50f8426c783d10e a87612acbdcd48e9ac805830a076480c X afb12c8e8ace4b04a50f8426c783d10e--a87612acbdcd48e9ac805830a076480c a87612acbdcd48e9ac805830a076480c--9822c5f7d2304ec0b80f9054aba53f0f e11f39c104934284b07c175c6dbb40d8 RX(p2₁₄) a87612acbdcd48e9ac805830a076480c--e11f39c104934284b07c175c6dbb40d8 01fc580a557c45e6afdd8a593a33b20c RY(p2₁₈) e11f39c104934284b07c175c6dbb40d8--01fc580a557c45e6afdd8a593a33b20c f2961705eda440ddad6cf8e062478ffd RX(p2₂₂) 01fc580a557c45e6afdd8a593a33b20c--f2961705eda440ddad6cf8e062478ffd 1b5d2f64b8ca401699d2020b386b2f5d f2961705eda440ddad6cf8e062478ffd--1b5d2f64b8ca401699d2020b386b2f5d 0ce87cd0af7c4cb9a09164d04117fa57 X 1b5d2f64b8ca401699d2020b386b2f5d--0ce87cd0af7c4cb9a09164d04117fa57 0ce87cd0af7c4cb9a09164d04117fa57--b11103f17bc944148f610f229b020591 0ce87cd0af7c4cb9a09164d04117fa57--b841dbfbe3964a9b9686baf3eafffc86 fa74b54608624b47bf9c5cf41df796d1 636b8da2cfef4f408e41a2b0d510465d RX(p1₃) 3fa0ff67739b4f4387b91e3fbab10d3f--636b8da2cfef4f408e41a2b0d510465d f805dd41f38547fb97286e06412bd6c9 RY(p1₇) 636b8da2cfef4f408e41a2b0d510465d--f805dd41f38547fb97286e06412bd6c9 d6947bf2ba9044f0b24af1e06d6627a1 RX(p1₁₁) f805dd41f38547fb97286e06412bd6c9--d6947bf2ba9044f0b24af1e06d6627a1 7f2c22542b2c4e768769aed65c08ad1e X d6947bf2ba9044f0b24af1e06d6627a1--7f2c22542b2c4e768769aed65c08ad1e 7f2c22542b2c4e768769aed65c08ad1e--be774b88e3704eaab5ba8d9a0fd8b567 80421832369e46dcbd08b59d366dcfd1 7f2c22542b2c4e768769aed65c08ad1e--80421832369e46dcbd08b59d366dcfd1 5e4fb7d625f145fcaee8d084a1ebd141 RX(p1₁₅) 80421832369e46dcbd08b59d366dcfd1--5e4fb7d625f145fcaee8d084a1ebd141 5150a581299f4bf886f60f39cfe4ea0c RY(p1₁₉) 5e4fb7d625f145fcaee8d084a1ebd141--5150a581299f4bf886f60f39cfe4ea0c 4c51f67853934356bb531328a12a0a18 RX(p1₂₃) 5150a581299f4bf886f60f39cfe4ea0c--4c51f67853934356bb531328a12a0a18 2f81b4b2e9eb4407bbafb1769f354701 X 4c51f67853934356bb531328a12a0a18--2f81b4b2e9eb4407bbafb1769f354701 2f81b4b2e9eb4407bbafb1769f354701--80f989db846945c6ad8b18d1541dd63f 5a679d16e3e5426ea6d4eb3722b6dc5f 2f81b4b2e9eb4407bbafb1769f354701--5a679d16e3e5426ea6d4eb3722b6dc5f fcb85d88ee634823af6c18cd11ed6642 RX(p2₃) 5a679d16e3e5426ea6d4eb3722b6dc5f--fcb85d88ee634823af6c18cd11ed6642 36cfcb3fbd69416980409652d00d9917 RY(p2₇) fcb85d88ee634823af6c18cd11ed6642--36cfcb3fbd69416980409652d00d9917 2dfb3825e96844fda9ab668f01ac24bf RX(p2₁₁) 36cfcb3fbd69416980409652d00d9917--2dfb3825e96844fda9ab668f01ac24bf 3df43613593d433fa58238c9237fb22f X 2dfb3825e96844fda9ab668f01ac24bf--3df43613593d433fa58238c9237fb22f 3df43613593d433fa58238c9237fb22f--afb12c8e8ace4b04a50f8426c783d10e 5a30f9ccd3454e239fb4cd024019e2d7 3df43613593d433fa58238c9237fb22f--5a30f9ccd3454e239fb4cd024019e2d7 f5a8b39e48e743839bc3d1baa06d1d20 RX(p2₁₅) 5a30f9ccd3454e239fb4cd024019e2d7--f5a8b39e48e743839bc3d1baa06d1d20 65d32f741f9049c0b4c4d03c0dad4233 RY(p2₁₉) f5a8b39e48e743839bc3d1baa06d1d20--65d32f741f9049c0b4c4d03c0dad4233 84a086d2c4c44a3b8d63b78fef6b54aa RX(p2₂₃) 65d32f741f9049c0b4c4d03c0dad4233--84a086d2c4c44a3b8d63b78fef6b54aa af420f1a755d4c0e81cba115112ebe52 X 84a086d2c4c44a3b8d63b78fef6b54aa--af420f1a755d4c0e81cba115112ebe52 af420f1a755d4c0e81cba115112ebe52--1b5d2f64b8ca401699d2020b386b2f5d ac8437af5f394127a392d6dc92220d0f af420f1a755d4c0e81cba115112ebe52--ac8437af5f394127a392d6dc92220d0f ac8437af5f394127a392d6dc92220d0f--fa74b54608624b47bf9c5cf41df796d1

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.0855])), ('theta_0', tensor([0.5155])), ('theta_1', tensor([0.9281])), ('theta_10', tensor([0.9866])), ('theta_11', tensor([0.2450])), ('theta_12', tensor([0.4834])), ('theta_13', tensor([0.1215])), ('theta_14', tensor([0.0793])), ('theta_15', tensor([0.7420])), ('theta_16', tensor([0.6813])), ('theta_17', tensor([0.5558])), ('theta_18', tensor([0.9943])), ('theta_19', tensor([0.4941])), ('theta_2', tensor([0.8950])), ('theta_20', tensor([0.5997])), ('theta_21', tensor([0.0895])), ('theta_22', tensor([0.9110])), ('theta_23', tensor([0.1405])), ('theta_3', tensor([0.2954])), ('theta_4', tensor([0.5823])), ('theta_5', tensor([0.5412])), ('theta_6', tensor([0.5837])), ('theta_7', tensor([0.3800])), ('theta_8', tensor([0.2195])), ('theta_9', tensor([0.9872]))])

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.0845])), ('theta_0', tensor([0.5145])), ('theta_1', tensor([0.9291])), ('theta_10', tensor([0.9876])), ('theta_11', tensor([0.2440])), ('theta_12', tensor([0.4844])), ('theta_13', tensor([0.1225])), ('theta_14', tensor([0.0803])), ('theta_15', tensor([0.7410])), ('theta_16', tensor([0.6803])), ('theta_17', tensor([0.5568])), ('theta_18', tensor([0.9933])), ('theta_19', tensor([0.4951])), ('theta_2', tensor([0.8960])), ('theta_20', tensor([0.6007])), ('theta_21', tensor([0.0905])), ('theta_22', tensor([0.9120])), ('theta_23', tensor([0.1395])), ('theta_3', tensor([0.2944])), ('theta_4', tensor([0.5833])), ('theta_5', tensor([0.5422])), ('theta_6', tensor([0.5827])), ('theta_7', tensor([0.3790])), ('theta_8', tensor([0.2205])), ('theta_9', tensor([0.9882]))])

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]])