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([[1.0000+0.0000j, 0.0000-0.0005j]])

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.8865+0.0000j, 0.0000-0.4627j],
        [0.9895+0.0000j, 0.0000-0.1448j]])

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([[9.9947e-01+0.0000e+00j, 2.8254e-04+0.0000e+00j, 0.0000e+00-3.2686e-02j,
         0.0000e+00-9.2401e-06j]])

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_5ad33ba079b44fff8dfc5bf353c6d1de [* 2] cluster_0b62e76a855e4781b4208a7f759db8b6 Rotations cb0b05306723446c91520bcbc13854b3 0 86fa269642ed47a284d03743bd0237ff RX(phi/theta) cb0b05306723446c91520bcbc13854b3--86fa269642ed47a284d03743bd0237ff bae631d4141b40cdafb850a1b9fdff39 1 9d9fcb108f93475491712141bc2c19fd RX(phi) 86fa269642ed47a284d03743bd0237ff--9d9fcb108f93475491712141bc2c19fd cbe910a932ee4df6a8114f4fdd8f455b RX(phi) 9d9fcb108f93475491712141bc2c19fd--cbe910a932ee4df6a8114f4fdd8f455b 7c85c3351a394f86971f1035314a7b8d RX(phi + theta) cbe910a932ee4df6a8114f4fdd8f455b--7c85c3351a394f86971f1035314a7b8d b485f01451d140c0a928e1ce337b55a3 7c85c3351a394f86971f1035314a7b8d--b485f01451d140c0a928e1ce337b55a3 98741d4175af47d6942088b16759fd16 b485f01451d140c0a928e1ce337b55a3--98741d4175af47d6942088b16759fd16 fa7fced3c22f4a02bb27ae02b822e19d Z 98741d4175af47d6942088b16759fd16--fa7fced3c22f4a02bb27ae02b822e19d 868461f9be31425f999bdd47e7059cde fa7fced3c22f4a02bb27ae02b822e19d--868461f9be31425f999bdd47e7059cde 48723cece6dc437f9f42ac9d0f5c318c de876aa809404a828c53fc86d129e6c3 RY(2*theta) bae631d4141b40cdafb850a1b9fdff39--de876aa809404a828c53fc86d129e6c3 830bdc638d1b418ea448e29c8eb26853 2 19bdbe914bf1438aafa62d73360a9f8e RY(theta) de876aa809404a828c53fc86d129e6c3--19bdbe914bf1438aafa62d73360a9f8e 4bc0759704824e4da334e8318eca66cc RY(theta) 19bdbe914bf1438aafa62d73360a9f8e--4bc0759704824e4da334e8318eca66cc f5d34e8daf2d4b5fb9ca0372db517632 RY(theta**2) 4bc0759704824e4da334e8318eca66cc--f5d34e8daf2d4b5fb9ca0372db517632 69292b1eded94b2198043b07261dd5ee X f5d34e8daf2d4b5fb9ca0372db517632--69292b1eded94b2198043b07261dd5ee 69292b1eded94b2198043b07261dd5ee--b485f01451d140c0a928e1ce337b55a3 113108d6e9094b39b0ff2faeec382bca 69292b1eded94b2198043b07261dd5ee--113108d6e9094b39b0ff2faeec382bca 71207b1387d7496998038d000dca8904 Z 113108d6e9094b39b0ff2faeec382bca--71207b1387d7496998038d000dca8904 71207b1387d7496998038d000dca8904--48723cece6dc437f9f42ac9d0f5c318c 524b8a6225ec46d68c49fc2dfedffdd6 803b20a6e5fb461fb1d13ac6332b7629 RZ(cos(phi)) 830bdc638d1b418ea448e29c8eb26853--803b20a6e5fb461fb1d13ac6332b7629 fefea8477f674a03bd60a052d3e79334 RZ(phi) 803b20a6e5fb461fb1d13ac6332b7629--fefea8477f674a03bd60a052d3e79334 965c69176f7640f392b7e5cfbf33d083 RZ(phi) fefea8477f674a03bd60a052d3e79334--965c69176f7640f392b7e5cfbf33d083 78cf983a851747fe8fca0871475a2751 RZ(cos(phi)) 965c69176f7640f392b7e5cfbf33d083--78cf983a851747fe8fca0871475a2751 457fd04fb6d6467f81fe46967f076d90 78cf983a851747fe8fca0871475a2751--457fd04fb6d6467f81fe46967f076d90 72feaf89191b496d9e0662f79f3c5959 X 457fd04fb6d6467f81fe46967f076d90--72feaf89191b496d9e0662f79f3c5959 72feaf89191b496d9e0662f79f3c5959--113108d6e9094b39b0ff2faeec382bca 8ad39a522c564f53ad13da7c0f6ea156 Z 72feaf89191b496d9e0662f79f3c5959--8ad39a522c564f53ad13da7c0f6ea156 8ad39a522c564f53ad13da7c0f6ea156--524b8a6225ec46d68c49fc2dfedffdd6

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

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.7476+0.0000j, 0.4344+0.0000j, 0.0000-0.4344j, 0.0000-0.2524j],
        [0.8146+0.0000j, 0.3886+0.0000j, 0.0000-0.3886j, 0.0000-0.1854j],
        [0.7536+0.0000j, 0.4309+0.0000j, 0.0000-0.4309j, 0.0000-0.2464j]],
       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 75f9a1462b2d4ea79a7ba0effd0286e9 0 653471c6dabf40c09b82e27dd2993ebf RX(theta₀) 75f9a1462b2d4ea79a7ba0effd0286e9--653471c6dabf40c09b82e27dd2993ebf e01e7089d19a42269bce7be868bef92d 1 f545e0e39b9b4f83bca4e7cae93ced16 RY(theta₄) 653471c6dabf40c09b82e27dd2993ebf--f545e0e39b9b4f83bca4e7cae93ced16 e5aa2c7cc9d64cfc8aa2b2469ed1dcb7 RX(theta₈) f545e0e39b9b4f83bca4e7cae93ced16--e5aa2c7cc9d64cfc8aa2b2469ed1dcb7 3eeb7eb77e354657be6af107b2997370 e5aa2c7cc9d64cfc8aa2b2469ed1dcb7--3eeb7eb77e354657be6af107b2997370 1c7066a92d4e4899bb7490813b9abb95 3eeb7eb77e354657be6af107b2997370--1c7066a92d4e4899bb7490813b9abb95 9353e5627ee14a26bf8e1d345c6dfb7a RX(theta₁₂) 1c7066a92d4e4899bb7490813b9abb95--9353e5627ee14a26bf8e1d345c6dfb7a 99185b0cd7d64609b07c409e6d6d6eb2 RY(theta₁₆) 9353e5627ee14a26bf8e1d345c6dfb7a--99185b0cd7d64609b07c409e6d6d6eb2 95fbe86761364e4e80bb255459f7ccc0 RX(theta₂₀) 99185b0cd7d64609b07c409e6d6d6eb2--95fbe86761364e4e80bb255459f7ccc0 24131c2f5aee407881bcc09fd0b5896f 95fbe86761364e4e80bb255459f7ccc0--24131c2f5aee407881bcc09fd0b5896f 878b08507f044b5f9354b26b6e08b834 24131c2f5aee407881bcc09fd0b5896f--878b08507f044b5f9354b26b6e08b834 10677b8b9a524d5bbea25b138f758d97 878b08507f044b5f9354b26b6e08b834--10677b8b9a524d5bbea25b138f758d97 908d435ecd344688b6340c5ebfd25791 719c4f8621d7421799514c6bbd74fb35 RX(theta₁) e01e7089d19a42269bce7be868bef92d--719c4f8621d7421799514c6bbd74fb35 f75a90220d754d61b5908e3cd0c4885b 2 cabd78a8f38b40cf971d592b2c3168ec RY(theta₅) 719c4f8621d7421799514c6bbd74fb35--cabd78a8f38b40cf971d592b2c3168ec f956cb72b51648c6b3e3ab83d74ed63b RX(theta₉) cabd78a8f38b40cf971d592b2c3168ec--f956cb72b51648c6b3e3ab83d74ed63b 5854c14b02594c0cbd03c01616f0735d X f956cb72b51648c6b3e3ab83d74ed63b--5854c14b02594c0cbd03c01616f0735d 5854c14b02594c0cbd03c01616f0735d--3eeb7eb77e354657be6af107b2997370 a021c9e9b8e545d1a575c022e819f548 5854c14b02594c0cbd03c01616f0735d--a021c9e9b8e545d1a575c022e819f548 c55db7c03b8c466d87d8e7de09e24e17 RX(theta₁₃) a021c9e9b8e545d1a575c022e819f548--c55db7c03b8c466d87d8e7de09e24e17 cecf096de41d43b89da1594a398b4311 RY(theta₁₇) c55db7c03b8c466d87d8e7de09e24e17--cecf096de41d43b89da1594a398b4311 7723650f9ba046b0b4ec4aa5b6f4e6ae RX(theta₂₁) cecf096de41d43b89da1594a398b4311--7723650f9ba046b0b4ec4aa5b6f4e6ae 44d2a46f3a7b4910911d9289135deb00 X 7723650f9ba046b0b4ec4aa5b6f4e6ae--44d2a46f3a7b4910911d9289135deb00 44d2a46f3a7b4910911d9289135deb00--24131c2f5aee407881bcc09fd0b5896f 0cfb9ffa41434545bd343fb128e0ab90 44d2a46f3a7b4910911d9289135deb00--0cfb9ffa41434545bd343fb128e0ab90 0cfb9ffa41434545bd343fb128e0ab90--908d435ecd344688b6340c5ebfd25791 0edd9c62f5b74b9c866ef937fd0dd684 edfa4c92cbba4f93859f9e4397fb4f38 RX(theta₂) f75a90220d754d61b5908e3cd0c4885b--edfa4c92cbba4f93859f9e4397fb4f38 919e277f2eb349c0aa73f74434fde05c 3 05fd8e19d8e54c3086f9206a048dac9a RY(theta₆) edfa4c92cbba4f93859f9e4397fb4f38--05fd8e19d8e54c3086f9206a048dac9a 63bd57775c6c4fb086c7fca78574fa9c RX(theta₁₀) 05fd8e19d8e54c3086f9206a048dac9a--63bd57775c6c4fb086c7fca78574fa9c 632bc6ed91804a268d3c58ed34b67ecd 63bd57775c6c4fb086c7fca78574fa9c--632bc6ed91804a268d3c58ed34b67ecd 74726519ae40405ea4e8acbc2cc0bea8 X 632bc6ed91804a268d3c58ed34b67ecd--74726519ae40405ea4e8acbc2cc0bea8 74726519ae40405ea4e8acbc2cc0bea8--a021c9e9b8e545d1a575c022e819f548 6b7d5d0b0eda4930a283de5d9e62006c RX(theta₁₄) 74726519ae40405ea4e8acbc2cc0bea8--6b7d5d0b0eda4930a283de5d9e62006c 28f4d94f2c78492f99422c216b303611 RY(theta₁₈) 6b7d5d0b0eda4930a283de5d9e62006c--28f4d94f2c78492f99422c216b303611 198b7857c6be4a3190844a74a7d6f753 RX(theta₂₂) 28f4d94f2c78492f99422c216b303611--198b7857c6be4a3190844a74a7d6f753 c057e4c40c2144f8a1607dbfde4163f2 198b7857c6be4a3190844a74a7d6f753--c057e4c40c2144f8a1607dbfde4163f2 e4581887c35849a6a679e0bd3af54d03 X c057e4c40c2144f8a1607dbfde4163f2--e4581887c35849a6a679e0bd3af54d03 e4581887c35849a6a679e0bd3af54d03--0cfb9ffa41434545bd343fb128e0ab90 e4581887c35849a6a679e0bd3af54d03--0edd9c62f5b74b9c866ef937fd0dd684 ba5877bbf9cd4f7da4f2e12bbc1b4219 c59749d06bae4f838400f842c0d6bbee RX(theta₃) 919e277f2eb349c0aa73f74434fde05c--c59749d06bae4f838400f842c0d6bbee a3d0389b83654691a107f35ac2825772 RY(theta₇) c59749d06bae4f838400f842c0d6bbee--a3d0389b83654691a107f35ac2825772 59f3c4a1fe4a45ed911dc3b4784a4a09 RX(theta₁₁) a3d0389b83654691a107f35ac2825772--59f3c4a1fe4a45ed911dc3b4784a4a09 cf79eda0e375427281a5927748019972 X 59f3c4a1fe4a45ed911dc3b4784a4a09--cf79eda0e375427281a5927748019972 cf79eda0e375427281a5927748019972--632bc6ed91804a268d3c58ed34b67ecd 0522bef21da74a3392500cb15e139150 cf79eda0e375427281a5927748019972--0522bef21da74a3392500cb15e139150 2ebaa4bed75e4138a2c4099828d249ca RX(theta₁₅) 0522bef21da74a3392500cb15e139150--2ebaa4bed75e4138a2c4099828d249ca cd04dc4dead14e17b2e8d523847d29ed RY(theta₁₉) 2ebaa4bed75e4138a2c4099828d249ca--cd04dc4dead14e17b2e8d523847d29ed a9819df49f8e462ba59a713b8d9b1fa2 RX(theta₂₃) cd04dc4dead14e17b2e8d523847d29ed--a9819df49f8e462ba59a713b8d9b1fa2 bcbddd694e014e78857602ba31f6aa70 X a9819df49f8e462ba59a713b8d9b1fa2--bcbddd694e014e78857602ba31f6aa70 bcbddd694e014e78857602ba31f6aa70--c057e4c40c2144f8a1607dbfde4163f2 f87b0a37f950444a8ed39a179b6e0351 bcbddd694e014e78857602ba31f6aa70--f87b0a37f950444a8ed39a179b6e0351 f87b0a37f950444a8ed39a179b6e0351--ba5877bbf9cd4f7da4f2e12bbc1b4219

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_1cd02535c0db42d7b232d00d27f8aad8 HEA cluster_2f2419fb4c1341dda1ca7aabe1ecdaa0 HEA 324b64f9aa3f4b75aa1f4418c1c6d3a5 0 68b4d640ba2e47c6b87bf883e5045820 RX(theta₀) 324b64f9aa3f4b75aa1f4418c1c6d3a5--68b4d640ba2e47c6b87bf883e5045820 a1e1264d355546a7a9235a208abc6c7a 1 304a1c7c180a4780b5bb80b106a0361a RY(theta₄) 68b4d640ba2e47c6b87bf883e5045820--304a1c7c180a4780b5bb80b106a0361a 421997b87de2408cbad65f1108faf73b RX(theta₈) 304a1c7c180a4780b5bb80b106a0361a--421997b87de2408cbad65f1108faf73b 495c9e2eac314c9fa9ead497ced9bffd 421997b87de2408cbad65f1108faf73b--495c9e2eac314c9fa9ead497ced9bffd 3c0b8db622d64f1bb9428c61b42ce0aa 495c9e2eac314c9fa9ead497ced9bffd--3c0b8db622d64f1bb9428c61b42ce0aa f1c6edfe2c294fbd8421729acb5f95e7 RX(theta₁₂) 3c0b8db622d64f1bb9428c61b42ce0aa--f1c6edfe2c294fbd8421729acb5f95e7 1356f5f064fc472987b4cfa687fdb94e RY(theta₁₆) f1c6edfe2c294fbd8421729acb5f95e7--1356f5f064fc472987b4cfa687fdb94e f49009d3d4334d608253632280235c3b RX(theta₂₀) 1356f5f064fc472987b4cfa687fdb94e--f49009d3d4334d608253632280235c3b 439a7dfcae00408b90de2aa3e168fe66 f49009d3d4334d608253632280235c3b--439a7dfcae00408b90de2aa3e168fe66 73169193ac454a849521ac693c07c457 439a7dfcae00408b90de2aa3e168fe66--73169193ac454a849521ac693c07c457 0d508b5ac1c94b28a3c0c72f5666709f RX(theta₀) 73169193ac454a849521ac693c07c457--0d508b5ac1c94b28a3c0c72f5666709f af01f2b79a764ee58f2ca3d556e3de09 RY(theta₄) 0d508b5ac1c94b28a3c0c72f5666709f--af01f2b79a764ee58f2ca3d556e3de09 5da6317ebdef4612adaf9d5c8e653de7 RX(theta₈) af01f2b79a764ee58f2ca3d556e3de09--5da6317ebdef4612adaf9d5c8e653de7 b0da4c5d383744f29725c2d1e2737e55 5da6317ebdef4612adaf9d5c8e653de7--b0da4c5d383744f29725c2d1e2737e55 5b8acb66226b4075a55ddc59adc8dcb8 b0da4c5d383744f29725c2d1e2737e55--5b8acb66226b4075a55ddc59adc8dcb8 35dd1038f4114149a7d288fe516671c1 RX(theta₁₂) 5b8acb66226b4075a55ddc59adc8dcb8--35dd1038f4114149a7d288fe516671c1 fe7772cb4d4d4a39918d383105f45945 RY(theta₁₆) 35dd1038f4114149a7d288fe516671c1--fe7772cb4d4d4a39918d383105f45945 7c1eeb791e8344dfb51f51bf92013e8b RX(theta₂₀) fe7772cb4d4d4a39918d383105f45945--7c1eeb791e8344dfb51f51bf92013e8b ca53d370e8684169b64d5269e9ac1137 7c1eeb791e8344dfb51f51bf92013e8b--ca53d370e8684169b64d5269e9ac1137 7ca84e74617a400aaf47acf0b8de2f33 ca53d370e8684169b64d5269e9ac1137--7ca84e74617a400aaf47acf0b8de2f33 9744197316064c779bc955287a4dbeb8 7ca84e74617a400aaf47acf0b8de2f33--9744197316064c779bc955287a4dbeb8 e8c52d631be14a3bb7988c3c1aa1bfed 01e4dab4bd1a4002a9953ed897fa55cd RX(theta₁) a1e1264d355546a7a9235a208abc6c7a--01e4dab4bd1a4002a9953ed897fa55cd 8c42ffa37ab049c2ae9f3ca890239284 2 94741d56fcba48739912db37bf7ea882 RY(theta₅) 01e4dab4bd1a4002a9953ed897fa55cd--94741d56fcba48739912db37bf7ea882 9d522f71eb904608897df3ef0d177402 RX(theta₉) 94741d56fcba48739912db37bf7ea882--9d522f71eb904608897df3ef0d177402 1927331aed53498f820132373a71d189 X 9d522f71eb904608897df3ef0d177402--1927331aed53498f820132373a71d189 1927331aed53498f820132373a71d189--495c9e2eac314c9fa9ead497ced9bffd 92f8d258265c446883832ebacde90151 1927331aed53498f820132373a71d189--92f8d258265c446883832ebacde90151 df727e0765dc476c98ad99ce24826e11 RX(theta₁₃) 92f8d258265c446883832ebacde90151--df727e0765dc476c98ad99ce24826e11 9b7e77ea41f245429da7b6bde597ef3b RY(theta₁₇) df727e0765dc476c98ad99ce24826e11--9b7e77ea41f245429da7b6bde597ef3b f596c2b1b8c3438b8d6de24a97ed8b74 RX(theta₂₁) 9b7e77ea41f245429da7b6bde597ef3b--f596c2b1b8c3438b8d6de24a97ed8b74 f8faea248ce543d3abc96eaa55c2f946 X f596c2b1b8c3438b8d6de24a97ed8b74--f8faea248ce543d3abc96eaa55c2f946 f8faea248ce543d3abc96eaa55c2f946--439a7dfcae00408b90de2aa3e168fe66 dd72fd25440047cb8d25f9112780519c f8faea248ce543d3abc96eaa55c2f946--dd72fd25440047cb8d25f9112780519c f1f220fa94e8498eb5a6881e7f8bd1d0 RX(theta₁) dd72fd25440047cb8d25f9112780519c--f1f220fa94e8498eb5a6881e7f8bd1d0 847e2347f5004f4f994b2c3c8879d07a RY(theta₅) f1f220fa94e8498eb5a6881e7f8bd1d0--847e2347f5004f4f994b2c3c8879d07a 413393a263e64f82aea0d66b7fa32db2 RX(theta₉) 847e2347f5004f4f994b2c3c8879d07a--413393a263e64f82aea0d66b7fa32db2 41b890282ed44e36ab7dd74381f8f990 X 413393a263e64f82aea0d66b7fa32db2--41b890282ed44e36ab7dd74381f8f990 41b890282ed44e36ab7dd74381f8f990--b0da4c5d383744f29725c2d1e2737e55 841d4786fe4240d682c7c9deb69573b2 41b890282ed44e36ab7dd74381f8f990--841d4786fe4240d682c7c9deb69573b2 08561bcbe2784fc2b6b5e6a1f8d10757 RX(theta₁₃) 841d4786fe4240d682c7c9deb69573b2--08561bcbe2784fc2b6b5e6a1f8d10757 8c6a047a09444ca9b73509c14931ed5a RY(theta₁₇) 08561bcbe2784fc2b6b5e6a1f8d10757--8c6a047a09444ca9b73509c14931ed5a 3d8774cfe5bf4bbdbdacbd99fc3ba6c8 RX(theta₂₁) 8c6a047a09444ca9b73509c14931ed5a--3d8774cfe5bf4bbdbdacbd99fc3ba6c8 d2cb0030b13849cd974c41a74990b394 X 3d8774cfe5bf4bbdbdacbd99fc3ba6c8--d2cb0030b13849cd974c41a74990b394 d2cb0030b13849cd974c41a74990b394--ca53d370e8684169b64d5269e9ac1137 9ed0043638f94748b174cfe47f540a8b d2cb0030b13849cd974c41a74990b394--9ed0043638f94748b174cfe47f540a8b 9ed0043638f94748b174cfe47f540a8b--e8c52d631be14a3bb7988c3c1aa1bfed 86288babb4ee4737a5a4f25161e3817d b221da2114074a5898b38b0ce81748fd RX(theta₂) 8c42ffa37ab049c2ae9f3ca890239284--b221da2114074a5898b38b0ce81748fd 26a607cd6348428ebf787db8c193dbdc 3 a5da4b5ec6f94de4ab1b77374aa8c730 RY(theta₆) b221da2114074a5898b38b0ce81748fd--a5da4b5ec6f94de4ab1b77374aa8c730 e36f6a52831f4453b4e7c81d20012e3a RX(theta₁₀) a5da4b5ec6f94de4ab1b77374aa8c730--e36f6a52831f4453b4e7c81d20012e3a ab7c080680ab40e5a12f7bf7bb28d510 e36f6a52831f4453b4e7c81d20012e3a--ab7c080680ab40e5a12f7bf7bb28d510 2d49864480934abc88ab45533ec3ef54 X ab7c080680ab40e5a12f7bf7bb28d510--2d49864480934abc88ab45533ec3ef54 2d49864480934abc88ab45533ec3ef54--92f8d258265c446883832ebacde90151 4c3f272dcb5c44009f0aa941da45321a RX(theta₁₄) 2d49864480934abc88ab45533ec3ef54--4c3f272dcb5c44009f0aa941da45321a 92c077da5d184493840b4e9b3a3c81c7 RY(theta₁₈) 4c3f272dcb5c44009f0aa941da45321a--92c077da5d184493840b4e9b3a3c81c7 c25e00474136461497fbe138cbfb25ea RX(theta₂₂) 92c077da5d184493840b4e9b3a3c81c7--c25e00474136461497fbe138cbfb25ea e58a8cb16a6949c5abf665f5ff04aa8f c25e00474136461497fbe138cbfb25ea--e58a8cb16a6949c5abf665f5ff04aa8f bcbeaf464ab54dd68f9f5008abb9f4f4 X e58a8cb16a6949c5abf665f5ff04aa8f--bcbeaf464ab54dd68f9f5008abb9f4f4 bcbeaf464ab54dd68f9f5008abb9f4f4--dd72fd25440047cb8d25f9112780519c fc23bbf7235448409fcd31e32112844b RX(theta₂) bcbeaf464ab54dd68f9f5008abb9f4f4--fc23bbf7235448409fcd31e32112844b f0ed3f898ca542b9bfb1f2f495749d3d RY(theta₆) fc23bbf7235448409fcd31e32112844b--f0ed3f898ca542b9bfb1f2f495749d3d 060ca44f33e4497292ac0a2c2916e196 RX(theta₁₀) f0ed3f898ca542b9bfb1f2f495749d3d--060ca44f33e4497292ac0a2c2916e196 32015f4c68e94a1590171c56d0da0884 060ca44f33e4497292ac0a2c2916e196--32015f4c68e94a1590171c56d0da0884 b72da5917fb240b68a25f9df94cf4d0f X 32015f4c68e94a1590171c56d0da0884--b72da5917fb240b68a25f9df94cf4d0f b72da5917fb240b68a25f9df94cf4d0f--841d4786fe4240d682c7c9deb69573b2 880a093703a247bc926fa52d5ea1809f RX(theta₁₄) b72da5917fb240b68a25f9df94cf4d0f--880a093703a247bc926fa52d5ea1809f 2eb7965c32944231a1c2bdab3edc6451 RY(theta₁₈) 880a093703a247bc926fa52d5ea1809f--2eb7965c32944231a1c2bdab3edc6451 6e36e4c356564f32aa7db0f2cb24f557 RX(theta₂₂) 2eb7965c32944231a1c2bdab3edc6451--6e36e4c356564f32aa7db0f2cb24f557 3c4b70c204aa4d1aadaceaa9a9e7a2ae 6e36e4c356564f32aa7db0f2cb24f557--3c4b70c204aa4d1aadaceaa9a9e7a2ae 2de7829d48e241088a9101dbce897803 X 3c4b70c204aa4d1aadaceaa9a9e7a2ae--2de7829d48e241088a9101dbce897803 2de7829d48e241088a9101dbce897803--9ed0043638f94748b174cfe47f540a8b 2de7829d48e241088a9101dbce897803--86288babb4ee4737a5a4f25161e3817d d1946ce60d204cae9590de144fb2a1ed 299ea02d70464ee3944b8ac50f306486 RX(theta₃) 26a607cd6348428ebf787db8c193dbdc--299ea02d70464ee3944b8ac50f306486 13e2bff3e92742b18d4014d3298ff2f8 RY(theta₇) 299ea02d70464ee3944b8ac50f306486--13e2bff3e92742b18d4014d3298ff2f8 ddfc141fc25144d098ee6883a741b12f RX(theta₁₁) 13e2bff3e92742b18d4014d3298ff2f8--ddfc141fc25144d098ee6883a741b12f 5587acbb769341b9a452a2521b94dcad X ddfc141fc25144d098ee6883a741b12f--5587acbb769341b9a452a2521b94dcad 5587acbb769341b9a452a2521b94dcad--ab7c080680ab40e5a12f7bf7bb28d510 d4bc7c094acd4ac0acab11c0f94bc114 5587acbb769341b9a452a2521b94dcad--d4bc7c094acd4ac0acab11c0f94bc114 be22f87936ca4b8d90e7d2957631db12 RX(theta₁₅) d4bc7c094acd4ac0acab11c0f94bc114--be22f87936ca4b8d90e7d2957631db12 61eeb435e9d14c689de801dad2f743e0 RY(theta₁₉) be22f87936ca4b8d90e7d2957631db12--61eeb435e9d14c689de801dad2f743e0 3b15c5df63f8440b9b9232367ad17cd1 RX(theta₂₃) 61eeb435e9d14c689de801dad2f743e0--3b15c5df63f8440b9b9232367ad17cd1 9a89b267576243c18b2e8deac0135470 X 3b15c5df63f8440b9b9232367ad17cd1--9a89b267576243c18b2e8deac0135470 9a89b267576243c18b2e8deac0135470--e58a8cb16a6949c5abf665f5ff04aa8f 11ac6c0955144d1cac4a72fd1d128ae1 9a89b267576243c18b2e8deac0135470--11ac6c0955144d1cac4a72fd1d128ae1 f30e50a3467441c38d8bb38e2dace232 RX(theta₃) 11ac6c0955144d1cac4a72fd1d128ae1--f30e50a3467441c38d8bb38e2dace232 4bfe556e197f48f59cc11f1dc632ffcf RY(theta₇) f30e50a3467441c38d8bb38e2dace232--4bfe556e197f48f59cc11f1dc632ffcf 3cd99204e24f4ccfa6743fc19f0c27ce RX(theta₁₁) 4bfe556e197f48f59cc11f1dc632ffcf--3cd99204e24f4ccfa6743fc19f0c27ce 8e8cda1007334b74b001da926a78bb19 X 3cd99204e24f4ccfa6743fc19f0c27ce--8e8cda1007334b74b001da926a78bb19 8e8cda1007334b74b001da926a78bb19--32015f4c68e94a1590171c56d0da0884 9ac99d948684497ba3df3c3560345b46 8e8cda1007334b74b001da926a78bb19--9ac99d948684497ba3df3c3560345b46 e37150ee3c5b46fc91566b773d2dc9c4 RX(theta₁₅) 9ac99d948684497ba3df3c3560345b46--e37150ee3c5b46fc91566b773d2dc9c4 9a41264d0f014dca842c3a1975d52b50 RY(theta₁₉) e37150ee3c5b46fc91566b773d2dc9c4--9a41264d0f014dca842c3a1975d52b50 4c4cd81819e1416688331048971cb55d RX(theta₂₃) 9a41264d0f014dca842c3a1975d52b50--4c4cd81819e1416688331048971cb55d 1ea6db49c30844719361200729b5f426 X 4c4cd81819e1416688331048971cb55d--1ea6db49c30844719361200729b5f426 1ea6db49c30844719361200729b5f426--3c4b70c204aa4d1aadaceaa9a9e7a2ae 86be9f4050424022a798b75019fb5e54 1ea6db49c30844719361200729b5f426--86be9f4050424022a798b75019fb5e54 86be9f4050424022a798b75019fb5e54--d1946ce60d204cae9590de144fb2a1ed

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_ddb2bc84a67d4dd4b169ed1d33b4d451 HEA cluster_5fceb1f909c94a3494c932a778fe212b HEA 1ab4ef94e57a422c9cc37ade8d47f2e9 0 24523b8865c34ed5b78cc3206bd23044 RX(p1₀) 1ab4ef94e57a422c9cc37ade8d47f2e9--24523b8865c34ed5b78cc3206bd23044 066f7cf7d25f4d669ae12203fdc5258a 1 53b100920e4c4a4a91613981dbc64faf RY(p1₄) 24523b8865c34ed5b78cc3206bd23044--53b100920e4c4a4a91613981dbc64faf 1f0c589adfb24da8a772a4d90986b0c3 RX(p1₈) 53b100920e4c4a4a91613981dbc64faf--1f0c589adfb24da8a772a4d90986b0c3 ad5529ab57ed4e95a2e01158192d59fe 1f0c589adfb24da8a772a4d90986b0c3--ad5529ab57ed4e95a2e01158192d59fe c8c85731531b4365b4f63400f8b99611 ad5529ab57ed4e95a2e01158192d59fe--c8c85731531b4365b4f63400f8b99611 d7c7dbdb5dbf456ba45debf47d19295a RX(p1₁₂) c8c85731531b4365b4f63400f8b99611--d7c7dbdb5dbf456ba45debf47d19295a b2754a992c674bdc99fcf0bc35b854cb RY(p1₁₆) d7c7dbdb5dbf456ba45debf47d19295a--b2754a992c674bdc99fcf0bc35b854cb a0da4a8e5f2e4b9bb1f36c626b70a620 RX(p1₂₀) b2754a992c674bdc99fcf0bc35b854cb--a0da4a8e5f2e4b9bb1f36c626b70a620 c06fbe92fb9d41c89d9a588950bfc990 a0da4a8e5f2e4b9bb1f36c626b70a620--c06fbe92fb9d41c89d9a588950bfc990 2ad7465165f944648b83d16b1a480e8c c06fbe92fb9d41c89d9a588950bfc990--2ad7465165f944648b83d16b1a480e8c 746365ab2ce046c7b1b3289255aacd6e RX(p2₀) 2ad7465165f944648b83d16b1a480e8c--746365ab2ce046c7b1b3289255aacd6e eef376d059eb4fb3b4066bead0f3f6b2 RY(p2₄) 746365ab2ce046c7b1b3289255aacd6e--eef376d059eb4fb3b4066bead0f3f6b2 44ad3b1d7dad4b09852431f9844747a6 RX(p2₈) eef376d059eb4fb3b4066bead0f3f6b2--44ad3b1d7dad4b09852431f9844747a6 ba1f39fa3cea4877858334b776d13768 44ad3b1d7dad4b09852431f9844747a6--ba1f39fa3cea4877858334b776d13768 a41d234d7d2e485b9b8b5915e8fc3b5e ba1f39fa3cea4877858334b776d13768--a41d234d7d2e485b9b8b5915e8fc3b5e 38d3c06605bb4746b9f185297718fc89 RX(p2₁₂) a41d234d7d2e485b9b8b5915e8fc3b5e--38d3c06605bb4746b9f185297718fc89 8954606ccb154e2eb45718f5036e3388 RY(p2₁₆) 38d3c06605bb4746b9f185297718fc89--8954606ccb154e2eb45718f5036e3388 1a59c32ee04c46e4ab5d4b0afcaf820c RX(p2₂₀) 8954606ccb154e2eb45718f5036e3388--1a59c32ee04c46e4ab5d4b0afcaf820c 4f49053c1bde443b97d46684174c202f 1a59c32ee04c46e4ab5d4b0afcaf820c--4f49053c1bde443b97d46684174c202f 93c75bdc921b49fab2228e83a9940ecf 4f49053c1bde443b97d46684174c202f--93c75bdc921b49fab2228e83a9940ecf 35fcf5f74551416db32f092154be2111 93c75bdc921b49fab2228e83a9940ecf--35fcf5f74551416db32f092154be2111 6d6dd080292a4ef5a68dc5698da59f6a 0e25a04dae24442393dc782a5bdb4d4d RX(p1₁) 066f7cf7d25f4d669ae12203fdc5258a--0e25a04dae24442393dc782a5bdb4d4d 6e874bd915464a22962f87e9e4ff0e0a 2 ce7557fd7b4243509d67225945d2f8df RY(p1₅) 0e25a04dae24442393dc782a5bdb4d4d--ce7557fd7b4243509d67225945d2f8df d73ac2e3e3be4764a02cca4f607db4e5 RX(p1₉) ce7557fd7b4243509d67225945d2f8df--d73ac2e3e3be4764a02cca4f607db4e5 6f941024261e4ea6a352b0ea2b896517 X d73ac2e3e3be4764a02cca4f607db4e5--6f941024261e4ea6a352b0ea2b896517 6f941024261e4ea6a352b0ea2b896517--ad5529ab57ed4e95a2e01158192d59fe abc97fee3fb64baaa3577988a8095da5 6f941024261e4ea6a352b0ea2b896517--abc97fee3fb64baaa3577988a8095da5 4e2c30a6238841de909222711713ddf2 RX(p1₁₃) abc97fee3fb64baaa3577988a8095da5--4e2c30a6238841de909222711713ddf2 9abc6d0776874844ad8d05d6c39652a1 RY(p1₁₇) 4e2c30a6238841de909222711713ddf2--9abc6d0776874844ad8d05d6c39652a1 1a0dc2d6a39a4ebdb98c0d123be8474a RX(p1₂₁) 9abc6d0776874844ad8d05d6c39652a1--1a0dc2d6a39a4ebdb98c0d123be8474a 9ff9843c56be4e9e9368139869cc2db4 X 1a0dc2d6a39a4ebdb98c0d123be8474a--9ff9843c56be4e9e9368139869cc2db4 9ff9843c56be4e9e9368139869cc2db4--c06fbe92fb9d41c89d9a588950bfc990 3af6102355854fb28453482ed35af756 9ff9843c56be4e9e9368139869cc2db4--3af6102355854fb28453482ed35af756 05db0b8bab6a4fd49415db16753533d6 RX(p2₁) 3af6102355854fb28453482ed35af756--05db0b8bab6a4fd49415db16753533d6 a28eee8661e346028afe3f25a73eccbf RY(p2₅) 05db0b8bab6a4fd49415db16753533d6--a28eee8661e346028afe3f25a73eccbf de54a00365244aa0aa6822f7c7f09d39 RX(p2₉) a28eee8661e346028afe3f25a73eccbf--de54a00365244aa0aa6822f7c7f09d39 59a164b840734b4cb4a2190fab986739 X de54a00365244aa0aa6822f7c7f09d39--59a164b840734b4cb4a2190fab986739 59a164b840734b4cb4a2190fab986739--ba1f39fa3cea4877858334b776d13768 105da4e41e2e4c3a9b04bd9eaaf4da7d 59a164b840734b4cb4a2190fab986739--105da4e41e2e4c3a9b04bd9eaaf4da7d c80f9c37a5dd48e8bb33e61b00f86a7c RX(p2₁₃) 105da4e41e2e4c3a9b04bd9eaaf4da7d--c80f9c37a5dd48e8bb33e61b00f86a7c 8ced13311e134a77a36d06a399455510 RY(p2₁₇) c80f9c37a5dd48e8bb33e61b00f86a7c--8ced13311e134a77a36d06a399455510 272b8bef81b34fe3b1d428900b6a88c8 RX(p2₂₁) 8ced13311e134a77a36d06a399455510--272b8bef81b34fe3b1d428900b6a88c8 a36486164334454585ad621e3eac7e5c X 272b8bef81b34fe3b1d428900b6a88c8--a36486164334454585ad621e3eac7e5c a36486164334454585ad621e3eac7e5c--4f49053c1bde443b97d46684174c202f 823f47f2466942019c67a9da2caafcbe a36486164334454585ad621e3eac7e5c--823f47f2466942019c67a9da2caafcbe 823f47f2466942019c67a9da2caafcbe--6d6dd080292a4ef5a68dc5698da59f6a ddba77c3ef3244fb974f41e8b19bc88c 90051eed789d4ec8b5f3b2e0368f2bff RX(p1₂) 6e874bd915464a22962f87e9e4ff0e0a--90051eed789d4ec8b5f3b2e0368f2bff 3be0fd4de1f6498896ee66b351983328 3 b986f0d6ad6846b8921487b65a26bd4e RY(p1₆) 90051eed789d4ec8b5f3b2e0368f2bff--b986f0d6ad6846b8921487b65a26bd4e 9e902420e9f64a75babda301257b49dc RX(p1₁₀) b986f0d6ad6846b8921487b65a26bd4e--9e902420e9f64a75babda301257b49dc a9fa2d4eae304c4c9531f382d475e433 9e902420e9f64a75babda301257b49dc--a9fa2d4eae304c4c9531f382d475e433 dcc732a4986e444bbdb6ad79733d2f21 X a9fa2d4eae304c4c9531f382d475e433--dcc732a4986e444bbdb6ad79733d2f21 dcc732a4986e444bbdb6ad79733d2f21--abc97fee3fb64baaa3577988a8095da5 8c9646b2fab74ae88f6b7d1d11d22309 RX(p1₁₄) dcc732a4986e444bbdb6ad79733d2f21--8c9646b2fab74ae88f6b7d1d11d22309 a59d098100e7445f8d6ea17536eb486a RY(p1₁₈) 8c9646b2fab74ae88f6b7d1d11d22309--a59d098100e7445f8d6ea17536eb486a fc6f501e948e4dc68eb44160e0a59ba9 RX(p1₂₂) a59d098100e7445f8d6ea17536eb486a--fc6f501e948e4dc68eb44160e0a59ba9 24a6e7ec51f64c2caca641ffa8a22c1f fc6f501e948e4dc68eb44160e0a59ba9--24a6e7ec51f64c2caca641ffa8a22c1f 6a50e640dd7642ea8987da3215b4b700 X 24a6e7ec51f64c2caca641ffa8a22c1f--6a50e640dd7642ea8987da3215b4b700 6a50e640dd7642ea8987da3215b4b700--3af6102355854fb28453482ed35af756 424c4dbf899e4e3881ca344cc8ba2ff4 RX(p2₂) 6a50e640dd7642ea8987da3215b4b700--424c4dbf899e4e3881ca344cc8ba2ff4 ffecffe4bc134c51a788cbe12162e15b RY(p2₆) 424c4dbf899e4e3881ca344cc8ba2ff4--ffecffe4bc134c51a788cbe12162e15b 767dcdce41f0498db09c44385ca260e7 RX(p2₁₀) ffecffe4bc134c51a788cbe12162e15b--767dcdce41f0498db09c44385ca260e7 cec1124bde5c4b9bb74fb6d02251e6e1 767dcdce41f0498db09c44385ca260e7--cec1124bde5c4b9bb74fb6d02251e6e1 16a82be741084c0f94ba55e4eec813d7 X cec1124bde5c4b9bb74fb6d02251e6e1--16a82be741084c0f94ba55e4eec813d7 16a82be741084c0f94ba55e4eec813d7--105da4e41e2e4c3a9b04bd9eaaf4da7d e7815e34a05645429e87943dac0640f8 RX(p2₁₄) 16a82be741084c0f94ba55e4eec813d7--e7815e34a05645429e87943dac0640f8 5ef79eef2c6947af808b61e47ecab0dc RY(p2₁₈) e7815e34a05645429e87943dac0640f8--5ef79eef2c6947af808b61e47ecab0dc d3a57ee426b9453ebbc85bd1983a286f RX(p2₂₂) 5ef79eef2c6947af808b61e47ecab0dc--d3a57ee426b9453ebbc85bd1983a286f 12085b1f120649248e1fcc3f4c8df29b d3a57ee426b9453ebbc85bd1983a286f--12085b1f120649248e1fcc3f4c8df29b 64c588b1bbb34618b8136b39b3b3af0d X 12085b1f120649248e1fcc3f4c8df29b--64c588b1bbb34618b8136b39b3b3af0d 64c588b1bbb34618b8136b39b3b3af0d--823f47f2466942019c67a9da2caafcbe 64c588b1bbb34618b8136b39b3b3af0d--ddba77c3ef3244fb974f41e8b19bc88c 72180f1e47ae479896bff40c4208ac90 4f4aa1a301e847b7a31c7db7f0fd31ef RX(p1₃) 3be0fd4de1f6498896ee66b351983328--4f4aa1a301e847b7a31c7db7f0fd31ef 1b6370b5349140b8a2329fb8e2d14fc1 RY(p1₇) 4f4aa1a301e847b7a31c7db7f0fd31ef--1b6370b5349140b8a2329fb8e2d14fc1 54f7f07cfe764f82a907c5e2e36c6ff0 RX(p1₁₁) 1b6370b5349140b8a2329fb8e2d14fc1--54f7f07cfe764f82a907c5e2e36c6ff0 1964bd3fae19423f97433ca569cff8ee X 54f7f07cfe764f82a907c5e2e36c6ff0--1964bd3fae19423f97433ca569cff8ee 1964bd3fae19423f97433ca569cff8ee--a9fa2d4eae304c4c9531f382d475e433 5efc5d2bad314ed89776e30f38fad309 1964bd3fae19423f97433ca569cff8ee--5efc5d2bad314ed89776e30f38fad309 597eb8527b4a401d84769ecc189ab1a3 RX(p1₁₅) 5efc5d2bad314ed89776e30f38fad309--597eb8527b4a401d84769ecc189ab1a3 3c21b5b549544ed6b741a8f21cbaf80c RY(p1₁₉) 597eb8527b4a401d84769ecc189ab1a3--3c21b5b549544ed6b741a8f21cbaf80c 2f1d5a3579ac4189ac76559a10e7f212 RX(p1₂₃) 3c21b5b549544ed6b741a8f21cbaf80c--2f1d5a3579ac4189ac76559a10e7f212 98290b8d7e494c1c8d27a224f610a5d0 X 2f1d5a3579ac4189ac76559a10e7f212--98290b8d7e494c1c8d27a224f610a5d0 98290b8d7e494c1c8d27a224f610a5d0--24a6e7ec51f64c2caca641ffa8a22c1f 00634dd7fc3d4e39a36244a5bfe69b96 98290b8d7e494c1c8d27a224f610a5d0--00634dd7fc3d4e39a36244a5bfe69b96 6447774d1775442c83d1c63057cad127 RX(p2₃) 00634dd7fc3d4e39a36244a5bfe69b96--6447774d1775442c83d1c63057cad127 0914c919183e452694b846ce091cae08 RY(p2₇) 6447774d1775442c83d1c63057cad127--0914c919183e452694b846ce091cae08 fc9c8e2b8b1440c9ac02fa3c9af9be30 RX(p2₁₁) 0914c919183e452694b846ce091cae08--fc9c8e2b8b1440c9ac02fa3c9af9be30 6e9e1da0e9dd4e76852f31f382574d06 X fc9c8e2b8b1440c9ac02fa3c9af9be30--6e9e1da0e9dd4e76852f31f382574d06 6e9e1da0e9dd4e76852f31f382574d06--cec1124bde5c4b9bb74fb6d02251e6e1 c0434e9bfd6248da87021550c3f4288d 6e9e1da0e9dd4e76852f31f382574d06--c0434e9bfd6248da87021550c3f4288d 2598e4ad9baa477289902a6c592b1be7 RX(p2₁₅) c0434e9bfd6248da87021550c3f4288d--2598e4ad9baa477289902a6c592b1be7 a0b5597243894e76b60e9e587406af43 RY(p2₁₉) 2598e4ad9baa477289902a6c592b1be7--a0b5597243894e76b60e9e587406af43 98376f1d4675421ba3cef0c9136c0d16 RX(p2₂₃) a0b5597243894e76b60e9e587406af43--98376f1d4675421ba3cef0c9136c0d16 8f39e48585ce435bb66941453ed91086 X 98376f1d4675421ba3cef0c9136c0d16--8f39e48585ce435bb66941453ed91086 8f39e48585ce435bb66941453ed91086--12085b1f120649248e1fcc3f4c8df29b 4419150da10f4f52ac5728ea2f696b4e 8f39e48585ce435bb66941453ed91086--4419150da10f4f52ac5728ea2f696b4e 4419150da10f4f52ac5728ea2f696b4e--72180f1e47ae479896bff40c4208ac90

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.9608])), ('theta_0', tensor([0.6551])), ('theta_1', tensor([0.0534])), ('theta_10', tensor([0.6509])), ('theta_11', tensor([0.8235])), ('theta_12', tensor([0.2038])), ('theta_13', tensor([0.7853])), ('theta_14', tensor([0.2668])), ('theta_15', tensor([0.5797])), ('theta_16', tensor([0.4227])), ('theta_17', tensor([0.6723])), ('theta_18', tensor([0.1476])), ('theta_19', tensor([0.6309])), ('theta_2', tensor([0.6050])), ('theta_20', tensor([0.1834])), ('theta_21', tensor([0.8038])), ('theta_22', tensor([0.9408])), ('theta_23', tensor([0.4441])), ('theta_3', tensor([0.7862])), ('theta_4', tensor([0.9296])), ('theta_5', tensor([0.9995])), ('theta_6', tensor([0.9985])), ('theta_7', tensor([0.9648])), ('theta_8', tensor([0.7446])), ('theta_9', tensor([0.1812]))])

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.9598])), ('theta_0', tensor([0.6541])), ('theta_1', tensor([0.0524])), ('theta_10', tensor([0.6499])), ('theta_11', tensor([0.8225])), ('theta_12', tensor([0.2028])), ('theta_13', tensor([0.7843])), ('theta_14', tensor([0.2658])), ('theta_15', tensor([0.5787])), ('theta_16', tensor([0.4217])), ('theta_17', tensor([0.6713])), ('theta_18', tensor([0.1486])), ('theta_19', tensor([0.6319])), ('theta_2', tensor([0.6040])), ('theta_20', tensor([0.1824])), ('theta_21', tensor([0.8028])), ('theta_22', tensor([0.9398])), ('theta_23', tensor([0.4431])), ('theta_3', tensor([0.7852])), ('theta_4', tensor([0.9286])), ('theta_5', tensor([0.9985])), ('theta_6', tensor([0.9975])), ('theta_7', tensor([0.9658])), ('theta_8', tensor([0.7436])), ('theta_9', tensor([0.1802]))])

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