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 qadence import RX, run, PI

# 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_fd2e3f9611aa4370918c0d76c032e7e5 [* 2] cluster_3764877a1a88457eacc28fb9cbd29ebf Rotations 959ae593f7c04b8da01d231fc45382b5 0 e665ba6f3f1747bea84616d630936a2d RX(phi/theta) 959ae593f7c04b8da01d231fc45382b5--e665ba6f3f1747bea84616d630936a2d 928eb6cce00a42c2a5d908457ee374b8 1 bfd50508c03c4e89bc057bd75d74a82b RX(phi) e665ba6f3f1747bea84616d630936a2d--bfd50508c03c4e89bc057bd75d74a82b 90c2f0fa446a488282bf0ff137bb7cf8 RX(phi) bfd50508c03c4e89bc057bd75d74a82b--90c2f0fa446a488282bf0ff137bb7cf8 f1ccd4e4e4444e40b259897a16cb9b3d RX(phi + theta) 90c2f0fa446a488282bf0ff137bb7cf8--f1ccd4e4e4444e40b259897a16cb9b3d 43b0e82569c949e6b9e5a6e541c68e2c f1ccd4e4e4444e40b259897a16cb9b3d--43b0e82569c949e6b9e5a6e541c68e2c a5941e8c57ad457a988100a38c578153 43b0e82569c949e6b9e5a6e541c68e2c--a5941e8c57ad457a988100a38c578153 7fa6ecf999a6472498ff4c58c049c73c Z a5941e8c57ad457a988100a38c578153--7fa6ecf999a6472498ff4c58c049c73c d019727e4f584cd58ee512d2f2a4c119 7fa6ecf999a6472498ff4c58c049c73c--d019727e4f584cd58ee512d2f2a4c119 c7091a8527e248f6941bb82d1cafafdf 41fd506eed0c46619a6ef32b6aae5eff RY(2*theta) 928eb6cce00a42c2a5d908457ee374b8--41fd506eed0c46619a6ef32b6aae5eff 89d54b9923c446b78f91a94062aa5a18 2 cfe72fc204c84f49b49aad9fe23decd4 RY(theta) 41fd506eed0c46619a6ef32b6aae5eff--cfe72fc204c84f49b49aad9fe23decd4 3c5fff976a0b4ee7bf65f27113e72145 RY(theta) cfe72fc204c84f49b49aad9fe23decd4--3c5fff976a0b4ee7bf65f27113e72145 410bd9de23b24f7595533ab8ad610cae RY(theta**2) 3c5fff976a0b4ee7bf65f27113e72145--410bd9de23b24f7595533ab8ad610cae b26b02dc6c6b4b69ade0eb24c0c1616a X 410bd9de23b24f7595533ab8ad610cae--b26b02dc6c6b4b69ade0eb24c0c1616a b26b02dc6c6b4b69ade0eb24c0c1616a--43b0e82569c949e6b9e5a6e541c68e2c da2cdad985994dc78eb4734a2736ca64 b26b02dc6c6b4b69ade0eb24c0c1616a--da2cdad985994dc78eb4734a2736ca64 657d13599ade4040a136b29bd01d2489 Z da2cdad985994dc78eb4734a2736ca64--657d13599ade4040a136b29bd01d2489 657d13599ade4040a136b29bd01d2489--c7091a8527e248f6941bb82d1cafafdf 3ae17a6f315941af8f53654fb5bee9d8 de4e0a7c9176449c84a76eb0d9297f0b RZ(cos(phi)) 89d54b9923c446b78f91a94062aa5a18--de4e0a7c9176449c84a76eb0d9297f0b 676e117c19ef4c71994ce58698ad45d6 RZ(phi) de4e0a7c9176449c84a76eb0d9297f0b--676e117c19ef4c71994ce58698ad45d6 978c3aaaebfc4dc48fc2297e5e44a50b RZ(phi) 676e117c19ef4c71994ce58698ad45d6--978c3aaaebfc4dc48fc2297e5e44a50b d0a52d2565294dc79571c3b3ba79774d RZ(cos(phi)) 978c3aaaebfc4dc48fc2297e5e44a50b--d0a52d2565294dc79571c3b3ba79774d 2e0f6808a28a43d48a13054d067ac45d d0a52d2565294dc79571c3b3ba79774d--2e0f6808a28a43d48a13054d067ac45d b15cde9a6b1647e28db3a38a3ad0b355 X 2e0f6808a28a43d48a13054d067ac45d--b15cde9a6b1647e28db3a38a3ad0b355 b15cde9a6b1647e28db3a38a3ad0b355--da2cdad985994dc78eb4734a2736ca64 bbbaa276a0174768a92ce26596a0b5f2 Z b15cde9a6b1647e28db3a38a3ad0b355--bbbaa276a0174768a92ce26596a0b5f2 bbbaa276a0174768a92ce26596a0b5f2--3ae17a6f315941af8f53654fb5bee9d8

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 282fe5d51fe840f0849e586ea168c478 0 064f8fc05eeb4d6792fb35b74f9eca8c RX(theta₀) 282fe5d51fe840f0849e586ea168c478--064f8fc05eeb4d6792fb35b74f9eca8c ed6d77d45b704b0a834a0b263915821c 1 2be0c06547fa4a63806b23f472f54614 RY(theta₄) 064f8fc05eeb4d6792fb35b74f9eca8c--2be0c06547fa4a63806b23f472f54614 a6ea5e77506e427e835f572759f9d6c9 RX(theta₈) 2be0c06547fa4a63806b23f472f54614--a6ea5e77506e427e835f572759f9d6c9 e6f2739d16e94cc0833a9d07fd0af517 a6ea5e77506e427e835f572759f9d6c9--e6f2739d16e94cc0833a9d07fd0af517 82355716099f46e18d548f61a461f812 e6f2739d16e94cc0833a9d07fd0af517--82355716099f46e18d548f61a461f812 b46a36c1205b4a8ea55965da5f015b9b RX(theta₁₂) 82355716099f46e18d548f61a461f812--b46a36c1205b4a8ea55965da5f015b9b 50dafcc9a9f64668bc345bc6b7f3cde6 RY(theta₁₆) b46a36c1205b4a8ea55965da5f015b9b--50dafcc9a9f64668bc345bc6b7f3cde6 772446f072d34b36b8f2eb9a064789c0 RX(theta₂₀) 50dafcc9a9f64668bc345bc6b7f3cde6--772446f072d34b36b8f2eb9a064789c0 1d7c3955c2334b719ad482a817905356 772446f072d34b36b8f2eb9a064789c0--1d7c3955c2334b719ad482a817905356 3b85fdf5b90d434a976dd377751ee62c 1d7c3955c2334b719ad482a817905356--3b85fdf5b90d434a976dd377751ee62c 2ef74d9e21a64a8da8a682ac561aaff6 3b85fdf5b90d434a976dd377751ee62c--2ef74d9e21a64a8da8a682ac561aaff6 2b09dbf54c784137a66b144c67b5e7b5 8fb7f16220554aa7abc280392e3fd036 RX(theta₁) ed6d77d45b704b0a834a0b263915821c--8fb7f16220554aa7abc280392e3fd036 55a84e121c994f3da5ad0a658885132c 2 276d374e391d405a8076adba14361795 RY(theta₅) 8fb7f16220554aa7abc280392e3fd036--276d374e391d405a8076adba14361795 00268d5cf1744dc5811ae0c31921cfde RX(theta₉) 276d374e391d405a8076adba14361795--00268d5cf1744dc5811ae0c31921cfde 3d938e32e72d4709986b7fc669c48104 X 00268d5cf1744dc5811ae0c31921cfde--3d938e32e72d4709986b7fc669c48104 3d938e32e72d4709986b7fc669c48104--e6f2739d16e94cc0833a9d07fd0af517 e9bbda08277b4a10a4529ae97aee3218 3d938e32e72d4709986b7fc669c48104--e9bbda08277b4a10a4529ae97aee3218 f380b72b82cc4ea6bcda7de9c6994b7a RX(theta₁₃) e9bbda08277b4a10a4529ae97aee3218--f380b72b82cc4ea6bcda7de9c6994b7a 1b214424f7d5495d974ff967faedbb49 RY(theta₁₇) f380b72b82cc4ea6bcda7de9c6994b7a--1b214424f7d5495d974ff967faedbb49 a6f4a035ced541fc9eed001e8ba1b89a RX(theta₂₁) 1b214424f7d5495d974ff967faedbb49--a6f4a035ced541fc9eed001e8ba1b89a e59654830e084a95a872979c5ad565d5 X a6f4a035ced541fc9eed001e8ba1b89a--e59654830e084a95a872979c5ad565d5 e59654830e084a95a872979c5ad565d5--1d7c3955c2334b719ad482a817905356 c6b86351d5c34722b0a476fb8d85cf29 e59654830e084a95a872979c5ad565d5--c6b86351d5c34722b0a476fb8d85cf29 c6b86351d5c34722b0a476fb8d85cf29--2b09dbf54c784137a66b144c67b5e7b5 9c8f59e646ca4980b11d1c7fe200ca12 36f755c4720344d1ac82d7ca71d52e8f RX(theta₂) 55a84e121c994f3da5ad0a658885132c--36f755c4720344d1ac82d7ca71d52e8f 483eb80cd01545eda1fbdee090f69333 3 c4ec252568e34e609594dafa992f84d3 RY(theta₆) 36f755c4720344d1ac82d7ca71d52e8f--c4ec252568e34e609594dafa992f84d3 1311f5bfc96242ffb93a75d7a871d141 RX(theta₁₀) c4ec252568e34e609594dafa992f84d3--1311f5bfc96242ffb93a75d7a871d141 dc9e620cfc2e41b48f085a37205cf503 1311f5bfc96242ffb93a75d7a871d141--dc9e620cfc2e41b48f085a37205cf503 5ee05b5dd8e742b08291d555fd3546c4 X dc9e620cfc2e41b48f085a37205cf503--5ee05b5dd8e742b08291d555fd3546c4 5ee05b5dd8e742b08291d555fd3546c4--e9bbda08277b4a10a4529ae97aee3218 23b907b4aaab47df8f4d370a879cea5e RX(theta₁₄) 5ee05b5dd8e742b08291d555fd3546c4--23b907b4aaab47df8f4d370a879cea5e aceb7ad59dec4f7993f62614b9a39e5f RY(theta₁₈) 23b907b4aaab47df8f4d370a879cea5e--aceb7ad59dec4f7993f62614b9a39e5f b160135dc75e4a96afb853c9d57ec6ce RX(theta₂₂) aceb7ad59dec4f7993f62614b9a39e5f--b160135dc75e4a96afb853c9d57ec6ce dc7dec60be1940e1b91513b81ae3f604 b160135dc75e4a96afb853c9d57ec6ce--dc7dec60be1940e1b91513b81ae3f604 a49c43e2cf674ef08a0ea15c143a9c63 X dc7dec60be1940e1b91513b81ae3f604--a49c43e2cf674ef08a0ea15c143a9c63 a49c43e2cf674ef08a0ea15c143a9c63--c6b86351d5c34722b0a476fb8d85cf29 a49c43e2cf674ef08a0ea15c143a9c63--9c8f59e646ca4980b11d1c7fe200ca12 4420324410e94d639d7b41ffc098dbb7 711a893d2603416c8d6f00e30fec847d RX(theta₃) 483eb80cd01545eda1fbdee090f69333--711a893d2603416c8d6f00e30fec847d 4e29f13c6aba43779cc70a716a255ed0 RY(theta₇) 711a893d2603416c8d6f00e30fec847d--4e29f13c6aba43779cc70a716a255ed0 efe22968d2874310889124c7e81a10e3 RX(theta₁₁) 4e29f13c6aba43779cc70a716a255ed0--efe22968d2874310889124c7e81a10e3 80440e51859849faa980a57e8e3a8d3e X efe22968d2874310889124c7e81a10e3--80440e51859849faa980a57e8e3a8d3e 80440e51859849faa980a57e8e3a8d3e--dc9e620cfc2e41b48f085a37205cf503 4f33f14a09444c34953d84e407e47b00 80440e51859849faa980a57e8e3a8d3e--4f33f14a09444c34953d84e407e47b00 578a133cac55487296b1490056ee4a4a RX(theta₁₅) 4f33f14a09444c34953d84e407e47b00--578a133cac55487296b1490056ee4a4a 4c36a05438bd4727af063740210028cd RY(theta₁₉) 578a133cac55487296b1490056ee4a4a--4c36a05438bd4727af063740210028cd eb294b46f8344665b27f2fda47592269 RX(theta₂₃) 4c36a05438bd4727af063740210028cd--eb294b46f8344665b27f2fda47592269 3ff65bdf7ec648d8aafab4e83f23d254 X eb294b46f8344665b27f2fda47592269--3ff65bdf7ec648d8aafab4e83f23d254 3ff65bdf7ec648d8aafab4e83f23d254--dc7dec60be1940e1b91513b81ae3f604 256ec9ebd8174dce8ca4d2a2174a4f5d 3ff65bdf7ec648d8aafab4e83f23d254--256ec9ebd8174dce8ca4d2a2174a4f5d 256ec9ebd8174dce8ca4d2a2174a4f5d--4420324410e94d639d7b41ffc098dbb7

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_25327fba1c3f4bc9b517ddc19a8c1341 HEA cluster_94cd0ea057364a83bf7a1777a7463358 HEA 8c18d36f3e884ae087f03dca5a325516 0 b7511f7289af43f38be01d456a8a9a22 RX(theta₀) 8c18d36f3e884ae087f03dca5a325516--b7511f7289af43f38be01d456a8a9a22 5c926323af144ef786b999063cda7750 1 02ab5a4084284a639433db2713d15af8 RY(theta₄) b7511f7289af43f38be01d456a8a9a22--02ab5a4084284a639433db2713d15af8 c8e60409371c40cda4bce33595c83994 RX(theta₈) 02ab5a4084284a639433db2713d15af8--c8e60409371c40cda4bce33595c83994 efb26172055e4b14accce486feea8cce c8e60409371c40cda4bce33595c83994--efb26172055e4b14accce486feea8cce cc83a70e77684198855cf184e3e0c7b4 efb26172055e4b14accce486feea8cce--cc83a70e77684198855cf184e3e0c7b4 71c5109d6e934ff98433d1d63dd31371 RX(theta₁₂) cc83a70e77684198855cf184e3e0c7b4--71c5109d6e934ff98433d1d63dd31371 7d88750c9561418a9e9ee1137804cdd9 RY(theta₁₆) 71c5109d6e934ff98433d1d63dd31371--7d88750c9561418a9e9ee1137804cdd9 9a31f94ef24a488882543c782651a9f6 RX(theta₂₀) 7d88750c9561418a9e9ee1137804cdd9--9a31f94ef24a488882543c782651a9f6 18f3e1a31f8149688a1a5cb91159987c 9a31f94ef24a488882543c782651a9f6--18f3e1a31f8149688a1a5cb91159987c 9fbe7f69c8fb4d16b6570f5e2eabf04c 18f3e1a31f8149688a1a5cb91159987c--9fbe7f69c8fb4d16b6570f5e2eabf04c d158f3875db945bf852793014d2daf2e RX(theta₀) 9fbe7f69c8fb4d16b6570f5e2eabf04c--d158f3875db945bf852793014d2daf2e eb79475c0e4a459eb5eec5f5b57769f6 RY(theta₄) d158f3875db945bf852793014d2daf2e--eb79475c0e4a459eb5eec5f5b57769f6 ac3ef688cf614c98a69d74086e84a52c RX(theta₈) eb79475c0e4a459eb5eec5f5b57769f6--ac3ef688cf614c98a69d74086e84a52c 3b187b6b8ed441e3b6c8d3caee259235 ac3ef688cf614c98a69d74086e84a52c--3b187b6b8ed441e3b6c8d3caee259235 742a8a5dc7f54a288ec2f84228da3825 3b187b6b8ed441e3b6c8d3caee259235--742a8a5dc7f54a288ec2f84228da3825 b8b4882334c1497897ede7a504bc9acd RX(theta₁₂) 742a8a5dc7f54a288ec2f84228da3825--b8b4882334c1497897ede7a504bc9acd 3da6713ffecd43f5b5f13f505dab5bdb RY(theta₁₆) b8b4882334c1497897ede7a504bc9acd--3da6713ffecd43f5b5f13f505dab5bdb 8e1a5cf6760943f9b30f0afb63c9b1b5 RX(theta₂₀) 3da6713ffecd43f5b5f13f505dab5bdb--8e1a5cf6760943f9b30f0afb63c9b1b5 a578a7617f504ea98625ee22c0a096d9 8e1a5cf6760943f9b30f0afb63c9b1b5--a578a7617f504ea98625ee22c0a096d9 1c11c8895571430ba9b506634ee89a40 a578a7617f504ea98625ee22c0a096d9--1c11c8895571430ba9b506634ee89a40 74ab88031816461d807a006ca92a94f1 1c11c8895571430ba9b506634ee89a40--74ab88031816461d807a006ca92a94f1 95f4925e8eb84e099a32242187eee972 0c99c41e46754dbf9b5e3861f61146d2 RX(theta₁) 5c926323af144ef786b999063cda7750--0c99c41e46754dbf9b5e3861f61146d2 62c939638b8f4c1f9b6308a0da3ca2d7 2 bedafb52c080419ba1382d67cbbda4f0 RY(theta₅) 0c99c41e46754dbf9b5e3861f61146d2--bedafb52c080419ba1382d67cbbda4f0 81362af9203a4d3aa3eb5654c133ab33 RX(theta₉) bedafb52c080419ba1382d67cbbda4f0--81362af9203a4d3aa3eb5654c133ab33 7dd536a8520d48bdb730c4e49f093bce X 81362af9203a4d3aa3eb5654c133ab33--7dd536a8520d48bdb730c4e49f093bce 7dd536a8520d48bdb730c4e49f093bce--efb26172055e4b14accce486feea8cce ab30c18966b74547b7bb67063ea6a262 7dd536a8520d48bdb730c4e49f093bce--ab30c18966b74547b7bb67063ea6a262 27c32c0c62bd4d208e9b2dd52280a313 RX(theta₁₃) ab30c18966b74547b7bb67063ea6a262--27c32c0c62bd4d208e9b2dd52280a313 404dadd877d84f8190f56d9e686d84c5 RY(theta₁₇) 27c32c0c62bd4d208e9b2dd52280a313--404dadd877d84f8190f56d9e686d84c5 c86ee4dde04b4844b9f9949896c291e9 RX(theta₂₁) 404dadd877d84f8190f56d9e686d84c5--c86ee4dde04b4844b9f9949896c291e9 0445e9999a054bc7b2387e99a208470c X c86ee4dde04b4844b9f9949896c291e9--0445e9999a054bc7b2387e99a208470c 0445e9999a054bc7b2387e99a208470c--18f3e1a31f8149688a1a5cb91159987c 241a7bc4674647c4af95a7bd9d9203b6 0445e9999a054bc7b2387e99a208470c--241a7bc4674647c4af95a7bd9d9203b6 0fe35bdcfa534c3e92133017921f9b09 RX(theta₁) 241a7bc4674647c4af95a7bd9d9203b6--0fe35bdcfa534c3e92133017921f9b09 e43666915fe847b6bc87d95611a2e1a2 RY(theta₅) 0fe35bdcfa534c3e92133017921f9b09--e43666915fe847b6bc87d95611a2e1a2 07338e13c3fd4694b79fbd92f8f8ddf7 RX(theta₉) e43666915fe847b6bc87d95611a2e1a2--07338e13c3fd4694b79fbd92f8f8ddf7 f2ec3269ab0241f8b98727ee954e04e5 X 07338e13c3fd4694b79fbd92f8f8ddf7--f2ec3269ab0241f8b98727ee954e04e5 f2ec3269ab0241f8b98727ee954e04e5--3b187b6b8ed441e3b6c8d3caee259235 cc80e69312f7402fbb83932408ca021e f2ec3269ab0241f8b98727ee954e04e5--cc80e69312f7402fbb83932408ca021e 2c2f093ad14a46a39c0e0b5fb0e6dff6 RX(theta₁₃) cc80e69312f7402fbb83932408ca021e--2c2f093ad14a46a39c0e0b5fb0e6dff6 b08069fa223143ea92f6775bbfa6f07f RY(theta₁₇) 2c2f093ad14a46a39c0e0b5fb0e6dff6--b08069fa223143ea92f6775bbfa6f07f 588595d21bba407687ac36943f0a9636 RX(theta₂₁) b08069fa223143ea92f6775bbfa6f07f--588595d21bba407687ac36943f0a9636 b05382d93c2c4e4e9948d0931fd0d696 X 588595d21bba407687ac36943f0a9636--b05382d93c2c4e4e9948d0931fd0d696 b05382d93c2c4e4e9948d0931fd0d696--a578a7617f504ea98625ee22c0a096d9 47869ed852b34b2787befb2de1d0e329 b05382d93c2c4e4e9948d0931fd0d696--47869ed852b34b2787befb2de1d0e329 47869ed852b34b2787befb2de1d0e329--95f4925e8eb84e099a32242187eee972 301d28a7c8334e4fa2c58550fa4e44c9 91db2687d51f4f8eb500f9786e5f703e RX(theta₂) 62c939638b8f4c1f9b6308a0da3ca2d7--91db2687d51f4f8eb500f9786e5f703e 2e3c2370cc7a4aec810d31fa6330e1f4 3 2096b8e977b54aac816d096ca17f51b6 RY(theta₆) 91db2687d51f4f8eb500f9786e5f703e--2096b8e977b54aac816d096ca17f51b6 42b569ff06ae459c9f0521583eb19028 RX(theta₁₀) 2096b8e977b54aac816d096ca17f51b6--42b569ff06ae459c9f0521583eb19028 a0196f32f3c94683b692be1320d8b7f0 42b569ff06ae459c9f0521583eb19028--a0196f32f3c94683b692be1320d8b7f0 fd295cff8ab14724afa025a41b390dcc X a0196f32f3c94683b692be1320d8b7f0--fd295cff8ab14724afa025a41b390dcc fd295cff8ab14724afa025a41b390dcc--ab30c18966b74547b7bb67063ea6a262 8dd6705c375b4d5ea6548bd74f9a4425 RX(theta₁₄) fd295cff8ab14724afa025a41b390dcc--8dd6705c375b4d5ea6548bd74f9a4425 b0c3b3a8110d421d9ab0103d5369b451 RY(theta₁₈) 8dd6705c375b4d5ea6548bd74f9a4425--b0c3b3a8110d421d9ab0103d5369b451 a537e1545b924dca985d37a416cd6d6a RX(theta₂₂) b0c3b3a8110d421d9ab0103d5369b451--a537e1545b924dca985d37a416cd6d6a 4a2d52ef40994027815e8f47cd9b0417 a537e1545b924dca985d37a416cd6d6a--4a2d52ef40994027815e8f47cd9b0417 b059af3e30694dd9a977f51117575c7e X 4a2d52ef40994027815e8f47cd9b0417--b059af3e30694dd9a977f51117575c7e b059af3e30694dd9a977f51117575c7e--241a7bc4674647c4af95a7bd9d9203b6 7fdee82e0f3b4cbbb9bc60b55122541e RX(theta₂) b059af3e30694dd9a977f51117575c7e--7fdee82e0f3b4cbbb9bc60b55122541e b4af05d62ee54c24acc979b185addfca RY(theta₆) 7fdee82e0f3b4cbbb9bc60b55122541e--b4af05d62ee54c24acc979b185addfca 491eef480025453098299ce4401fdfeb RX(theta₁₀) b4af05d62ee54c24acc979b185addfca--491eef480025453098299ce4401fdfeb 80a1a0b532dc46e4bbadde7549237851 491eef480025453098299ce4401fdfeb--80a1a0b532dc46e4bbadde7549237851 3f12b352649a41e9af7c45643c9c495f X 80a1a0b532dc46e4bbadde7549237851--3f12b352649a41e9af7c45643c9c495f 3f12b352649a41e9af7c45643c9c495f--cc80e69312f7402fbb83932408ca021e ba890995c0c944d1a144928f77e17c90 RX(theta₁₄) 3f12b352649a41e9af7c45643c9c495f--ba890995c0c944d1a144928f77e17c90 62db3fc239bd47b9a496d9b4a570e0f1 RY(theta₁₈) ba890995c0c944d1a144928f77e17c90--62db3fc239bd47b9a496d9b4a570e0f1 2e26e2c89ce34f46b1db4ae19f99dd35 RX(theta₂₂) 62db3fc239bd47b9a496d9b4a570e0f1--2e26e2c89ce34f46b1db4ae19f99dd35 52f94fa19c0b470b8d0ab05db279663e 2e26e2c89ce34f46b1db4ae19f99dd35--52f94fa19c0b470b8d0ab05db279663e ca033e376d6746b1af971798fd09f85d X 52f94fa19c0b470b8d0ab05db279663e--ca033e376d6746b1af971798fd09f85d ca033e376d6746b1af971798fd09f85d--47869ed852b34b2787befb2de1d0e329 ca033e376d6746b1af971798fd09f85d--301d28a7c8334e4fa2c58550fa4e44c9 47932cab833147bfb807156f7b052955 a46d8053da224bce92df12871d7f388b RX(theta₃) 2e3c2370cc7a4aec810d31fa6330e1f4--a46d8053da224bce92df12871d7f388b 1f8c6f803d084c61bde140e85dd28c11 RY(theta₇) a46d8053da224bce92df12871d7f388b--1f8c6f803d084c61bde140e85dd28c11 5067b66a1d01449793a585402d2efa2b RX(theta₁₁) 1f8c6f803d084c61bde140e85dd28c11--5067b66a1d01449793a585402d2efa2b 0c930bf0c0c04440a4611fb6d97dc30f X 5067b66a1d01449793a585402d2efa2b--0c930bf0c0c04440a4611fb6d97dc30f 0c930bf0c0c04440a4611fb6d97dc30f--a0196f32f3c94683b692be1320d8b7f0 c17a6961641f4f2c875ea3afe4938e4b 0c930bf0c0c04440a4611fb6d97dc30f--c17a6961641f4f2c875ea3afe4938e4b cc752148735c4259b8bc04d02d0fc752 RX(theta₁₅) c17a6961641f4f2c875ea3afe4938e4b--cc752148735c4259b8bc04d02d0fc752 cfb4c1c563ec4012a08265fa1f337d4e RY(theta₁₉) cc752148735c4259b8bc04d02d0fc752--cfb4c1c563ec4012a08265fa1f337d4e ac5714d353974c879af375b458c5e5e8 RX(theta₂₃) cfb4c1c563ec4012a08265fa1f337d4e--ac5714d353974c879af375b458c5e5e8 a1e829218b014ff7972f3f7f84b0a1fa X ac5714d353974c879af375b458c5e5e8--a1e829218b014ff7972f3f7f84b0a1fa a1e829218b014ff7972f3f7f84b0a1fa--4a2d52ef40994027815e8f47cd9b0417 e9587b242024474cafd99275846fa90f a1e829218b014ff7972f3f7f84b0a1fa--e9587b242024474cafd99275846fa90f 851f49265bb946d4bbf4622b175d9e01 RX(theta₃) e9587b242024474cafd99275846fa90f--851f49265bb946d4bbf4622b175d9e01 2ae6f8cfe5d24c7f9080b157606a6e7f RY(theta₇) 851f49265bb946d4bbf4622b175d9e01--2ae6f8cfe5d24c7f9080b157606a6e7f 2572f509fc6846bcae103d6593143f75 RX(theta₁₁) 2ae6f8cfe5d24c7f9080b157606a6e7f--2572f509fc6846bcae103d6593143f75 7194b008aca240b496312fa19a697d5b X 2572f509fc6846bcae103d6593143f75--7194b008aca240b496312fa19a697d5b 7194b008aca240b496312fa19a697d5b--80a1a0b532dc46e4bbadde7549237851 e710c06a2dec448285fca0e0f251e271 7194b008aca240b496312fa19a697d5b--e710c06a2dec448285fca0e0f251e271 218f07ef64c04860b65ab8cc3ec5ff65 RX(theta₁₅) e710c06a2dec448285fca0e0f251e271--218f07ef64c04860b65ab8cc3ec5ff65 73b970fc14ec4abe9eccc0bc030cda9c RY(theta₁₉) 218f07ef64c04860b65ab8cc3ec5ff65--73b970fc14ec4abe9eccc0bc030cda9c 76dae23ee83a4cd8ab2ff04ba127aace RX(theta₂₃) 73b970fc14ec4abe9eccc0bc030cda9c--76dae23ee83a4cd8ab2ff04ba127aace 4a16eb62a7e348b49153dfd3aa355eeb X 76dae23ee83a4cd8ab2ff04ba127aace--4a16eb62a7e348b49153dfd3aa355eeb 4a16eb62a7e348b49153dfd3aa355eeb--52f94fa19c0b470b8d0ab05db279663e d3ef7271f0204644bef67162a693ef1e 4a16eb62a7e348b49153dfd3aa355eeb--d3ef7271f0204644bef67162a693ef1e d3ef7271f0204644bef67162a693ef1e--47932cab833147bfb807156f7b052955

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_4e450df5efe24faa9086c864a4e3e5bd HEA cluster_68245fbaba734c8cb1cb77a377c3b11c HEA b36fb2f289244e24a730f8fb5efe9268 0 271b3672aa6d49a4a2edaef84313cc34 RX(p1₀) b36fb2f289244e24a730f8fb5efe9268--271b3672aa6d49a4a2edaef84313cc34 2b193c1f347847e9962bbbb2678466e4 1 bf484086035f4517bdd3c3f15df28921 RY(p1₄) 271b3672aa6d49a4a2edaef84313cc34--bf484086035f4517bdd3c3f15df28921 99298681d84942f6829262955e862e76 RX(p1₈) bf484086035f4517bdd3c3f15df28921--99298681d84942f6829262955e862e76 9468f8c13baa48329a040d7fe422ad61 99298681d84942f6829262955e862e76--9468f8c13baa48329a040d7fe422ad61 5034d8d8d5b846a0b460f5656776964c 9468f8c13baa48329a040d7fe422ad61--5034d8d8d5b846a0b460f5656776964c 2a7ca364975945b8ae4554c14af7064c RX(p1₁₂) 5034d8d8d5b846a0b460f5656776964c--2a7ca364975945b8ae4554c14af7064c 49686c716047446083aebed07e54e997 RY(p1₁₆) 2a7ca364975945b8ae4554c14af7064c--49686c716047446083aebed07e54e997 47a624b21c01497babb301a0e587a8d6 RX(p1₂₀) 49686c716047446083aebed07e54e997--47a624b21c01497babb301a0e587a8d6 b4e032f8b7a1472294272a6d878850c6 47a624b21c01497babb301a0e587a8d6--b4e032f8b7a1472294272a6d878850c6 5d5009a244fb4ccaa30ff5f8f130d886 b4e032f8b7a1472294272a6d878850c6--5d5009a244fb4ccaa30ff5f8f130d886 8abb290ec39944eb9e29949d6cdcbb42 RX(p2₀) 5d5009a244fb4ccaa30ff5f8f130d886--8abb290ec39944eb9e29949d6cdcbb42 1b58a905ce244a9da4e5e1c72e55d4b2 RY(p2₄) 8abb290ec39944eb9e29949d6cdcbb42--1b58a905ce244a9da4e5e1c72e55d4b2 22cfbb1d946449e78c0946e3ce5bc43b RX(p2₈) 1b58a905ce244a9da4e5e1c72e55d4b2--22cfbb1d946449e78c0946e3ce5bc43b 96deac68cab14eff9ec2a8aa106218ac 22cfbb1d946449e78c0946e3ce5bc43b--96deac68cab14eff9ec2a8aa106218ac 5a194886a67c457c90d17c831c4917ff 96deac68cab14eff9ec2a8aa106218ac--5a194886a67c457c90d17c831c4917ff 78a4a2d8763d41119d7903bf41ab7571 RX(p2₁₂) 5a194886a67c457c90d17c831c4917ff--78a4a2d8763d41119d7903bf41ab7571 7719f58f27f04feb942f6e4b866c5c04 RY(p2₁₆) 78a4a2d8763d41119d7903bf41ab7571--7719f58f27f04feb942f6e4b866c5c04 025659bb1a924f288a16d3a4a20a2648 RX(p2₂₀) 7719f58f27f04feb942f6e4b866c5c04--025659bb1a924f288a16d3a4a20a2648 a6b1dfe174134c7cac6269fa38fd2428 025659bb1a924f288a16d3a4a20a2648--a6b1dfe174134c7cac6269fa38fd2428 030a719f5f1e4e0b91f192b6cf086ddd a6b1dfe174134c7cac6269fa38fd2428--030a719f5f1e4e0b91f192b6cf086ddd 3d85c4167e74427aaff97307598aef2a 030a719f5f1e4e0b91f192b6cf086ddd--3d85c4167e74427aaff97307598aef2a ca314e6290c9446eaf08debe0df92ec3 45e42004e44941038349a0aebdcc1307 RX(p1₁) 2b193c1f347847e9962bbbb2678466e4--45e42004e44941038349a0aebdcc1307 a0df2ecaaa284fab9a75ae5b1f75a532 2 97fe7cc4ad5a4baeac583b7803c8245f RY(p1₅) 45e42004e44941038349a0aebdcc1307--97fe7cc4ad5a4baeac583b7803c8245f 0eee308a48e54db0989d49e636124398 RX(p1₉) 97fe7cc4ad5a4baeac583b7803c8245f--0eee308a48e54db0989d49e636124398 7762bc0d00964c21b246b02e5de20e15 X 0eee308a48e54db0989d49e636124398--7762bc0d00964c21b246b02e5de20e15 7762bc0d00964c21b246b02e5de20e15--9468f8c13baa48329a040d7fe422ad61 55b88f51407e403a81a739026488135b 7762bc0d00964c21b246b02e5de20e15--55b88f51407e403a81a739026488135b 445383d4a18c4f25af4b26b710839d61 RX(p1₁₃) 55b88f51407e403a81a739026488135b--445383d4a18c4f25af4b26b710839d61 ef73c6e632d34319aea4f9da32c69222 RY(p1₁₇) 445383d4a18c4f25af4b26b710839d61--ef73c6e632d34319aea4f9da32c69222 4247f7ebd3be4d55a7ac9f9118f2d8cb RX(p1₂₁) ef73c6e632d34319aea4f9da32c69222--4247f7ebd3be4d55a7ac9f9118f2d8cb 66c5d797cb01426f816a94072eb40d3a X 4247f7ebd3be4d55a7ac9f9118f2d8cb--66c5d797cb01426f816a94072eb40d3a 66c5d797cb01426f816a94072eb40d3a--b4e032f8b7a1472294272a6d878850c6 26d006daa06548ce9b2ef45f8630ce49 66c5d797cb01426f816a94072eb40d3a--26d006daa06548ce9b2ef45f8630ce49 e74cd0075eb64fa18e669ddce89cdd07 RX(p2₁) 26d006daa06548ce9b2ef45f8630ce49--e74cd0075eb64fa18e669ddce89cdd07 3cb5b67e3bbc48b78ca4fabb7d9aeac5 RY(p2₅) e74cd0075eb64fa18e669ddce89cdd07--3cb5b67e3bbc48b78ca4fabb7d9aeac5 1af076630afb4160be60e093616edcf2 RX(p2₉) 3cb5b67e3bbc48b78ca4fabb7d9aeac5--1af076630afb4160be60e093616edcf2 ce597f12180142589a7041cb7d0e9d0d X 1af076630afb4160be60e093616edcf2--ce597f12180142589a7041cb7d0e9d0d ce597f12180142589a7041cb7d0e9d0d--96deac68cab14eff9ec2a8aa106218ac ec8597d537bc46f7a30ac7568a520212 ce597f12180142589a7041cb7d0e9d0d--ec8597d537bc46f7a30ac7568a520212 acb3fbfef5fe4cd9b6a30304b88d7db3 RX(p2₁₃) ec8597d537bc46f7a30ac7568a520212--acb3fbfef5fe4cd9b6a30304b88d7db3 7cef317830504c8fb476388e193f6496 RY(p2₁₇) acb3fbfef5fe4cd9b6a30304b88d7db3--7cef317830504c8fb476388e193f6496 42ec8761dea44e0abac9dedd5ca4515a RX(p2₂₁) 7cef317830504c8fb476388e193f6496--42ec8761dea44e0abac9dedd5ca4515a 7f792e188bbc463bbcee1385a1219ecc X 42ec8761dea44e0abac9dedd5ca4515a--7f792e188bbc463bbcee1385a1219ecc 7f792e188bbc463bbcee1385a1219ecc--a6b1dfe174134c7cac6269fa38fd2428 1505ae4e5bf644ab887f1624cd69a5e5 7f792e188bbc463bbcee1385a1219ecc--1505ae4e5bf644ab887f1624cd69a5e5 1505ae4e5bf644ab887f1624cd69a5e5--ca314e6290c9446eaf08debe0df92ec3 c95ba5c17a35470d946971957557b501 dc6725a2784444fb8cecf67adff5a582 RX(p1₂) a0df2ecaaa284fab9a75ae5b1f75a532--dc6725a2784444fb8cecf67adff5a582 be5082ab97204f2493ae2b795ae1e75f 3 b6061167df354f869d5ca2eb436ba360 RY(p1₆) dc6725a2784444fb8cecf67adff5a582--b6061167df354f869d5ca2eb436ba360 08ae83c80b34440786064a015da19e26 RX(p1₁₀) b6061167df354f869d5ca2eb436ba360--08ae83c80b34440786064a015da19e26 ce54f5d91bd74a03b230c41160580a1f 08ae83c80b34440786064a015da19e26--ce54f5d91bd74a03b230c41160580a1f a9369f62136446799fca6da484f34a07 X ce54f5d91bd74a03b230c41160580a1f--a9369f62136446799fca6da484f34a07 a9369f62136446799fca6da484f34a07--55b88f51407e403a81a739026488135b a5ac849498ee49399f35d014cb5a908d RX(p1₁₄) a9369f62136446799fca6da484f34a07--a5ac849498ee49399f35d014cb5a908d 3065223da0cb406e8497ca8f20ada009 RY(p1₁₈) a5ac849498ee49399f35d014cb5a908d--3065223da0cb406e8497ca8f20ada009 bae05a60407942cc9eaf3319c072d6d2 RX(p1₂₂) 3065223da0cb406e8497ca8f20ada009--bae05a60407942cc9eaf3319c072d6d2 6c7e056c44fa446eb6a2ec0ac611f158 bae05a60407942cc9eaf3319c072d6d2--6c7e056c44fa446eb6a2ec0ac611f158 ee7106fb7fd74a5f9c2ddd9023c97505 X 6c7e056c44fa446eb6a2ec0ac611f158--ee7106fb7fd74a5f9c2ddd9023c97505 ee7106fb7fd74a5f9c2ddd9023c97505--26d006daa06548ce9b2ef45f8630ce49 faadff439ff94cc78259777b82b633ff RX(p2₂) ee7106fb7fd74a5f9c2ddd9023c97505--faadff439ff94cc78259777b82b633ff 05f6d83b525d40fca790d1db19397f3a RY(p2₆) faadff439ff94cc78259777b82b633ff--05f6d83b525d40fca790d1db19397f3a 208819b270474768b79ffc4d1c6225cf RX(p2₁₀) 05f6d83b525d40fca790d1db19397f3a--208819b270474768b79ffc4d1c6225cf 288f361b5cb741cbaec09ccd8306cf4f 208819b270474768b79ffc4d1c6225cf--288f361b5cb741cbaec09ccd8306cf4f 0bc18ee7b88641128abf96a25105d827 X 288f361b5cb741cbaec09ccd8306cf4f--0bc18ee7b88641128abf96a25105d827 0bc18ee7b88641128abf96a25105d827--ec8597d537bc46f7a30ac7568a520212 4f3199a08c3843e98c4e140a4a905431 RX(p2₁₄) 0bc18ee7b88641128abf96a25105d827--4f3199a08c3843e98c4e140a4a905431 0c14e88f068446978c5778e68e877c43 RY(p2₁₈) 4f3199a08c3843e98c4e140a4a905431--0c14e88f068446978c5778e68e877c43 0c11f64099bd4c69b7387f6bdac2f183 RX(p2₂₂) 0c14e88f068446978c5778e68e877c43--0c11f64099bd4c69b7387f6bdac2f183 5f5458af301143f2adce48045870e5a6 0c11f64099bd4c69b7387f6bdac2f183--5f5458af301143f2adce48045870e5a6 df8b04a6a5e34437a03884b6b30b9b02 X 5f5458af301143f2adce48045870e5a6--df8b04a6a5e34437a03884b6b30b9b02 df8b04a6a5e34437a03884b6b30b9b02--1505ae4e5bf644ab887f1624cd69a5e5 df8b04a6a5e34437a03884b6b30b9b02--c95ba5c17a35470d946971957557b501 a4c8ae104c8944768dce8c4f40030daf a6ff7821217b46f6bca46cd4ffe70805 RX(p1₃) be5082ab97204f2493ae2b795ae1e75f--a6ff7821217b46f6bca46cd4ffe70805 742e6d8cc2044510b4255aa2e2464815 RY(p1₇) a6ff7821217b46f6bca46cd4ffe70805--742e6d8cc2044510b4255aa2e2464815 f5baedd6196c4c4386dbc5148620bb26 RX(p1₁₁) 742e6d8cc2044510b4255aa2e2464815--f5baedd6196c4c4386dbc5148620bb26 848811f80ea44813aa2f2034f40ab990 X f5baedd6196c4c4386dbc5148620bb26--848811f80ea44813aa2f2034f40ab990 848811f80ea44813aa2f2034f40ab990--ce54f5d91bd74a03b230c41160580a1f e82d92d7e41f4e28883a149da0346c8a 848811f80ea44813aa2f2034f40ab990--e82d92d7e41f4e28883a149da0346c8a 29b13fa04b4e4c0ea06880a55ea00607 RX(p1₁₅) e82d92d7e41f4e28883a149da0346c8a--29b13fa04b4e4c0ea06880a55ea00607 9dae632c4791498f821c5e565d40139f RY(p1₁₉) 29b13fa04b4e4c0ea06880a55ea00607--9dae632c4791498f821c5e565d40139f 87b49ed7d8b646309ba8c3110d3d7a8c RX(p1₂₃) 9dae632c4791498f821c5e565d40139f--87b49ed7d8b646309ba8c3110d3d7a8c 64d01f95754740f08bb160a504c6bf7a X 87b49ed7d8b646309ba8c3110d3d7a8c--64d01f95754740f08bb160a504c6bf7a 64d01f95754740f08bb160a504c6bf7a--6c7e056c44fa446eb6a2ec0ac611f158 a31fe305290445c8b0ab0bbef225b6c2 64d01f95754740f08bb160a504c6bf7a--a31fe305290445c8b0ab0bbef225b6c2 7ec6e389c5f2411db4bcbf71f6be9c7d RX(p2₃) a31fe305290445c8b0ab0bbef225b6c2--7ec6e389c5f2411db4bcbf71f6be9c7d 2595f52e63de4378bd13cd3d836aaae7 RY(p2₇) 7ec6e389c5f2411db4bcbf71f6be9c7d--2595f52e63de4378bd13cd3d836aaae7 e80281fc3a76491cb1e175f694705c99 RX(p2₁₁) 2595f52e63de4378bd13cd3d836aaae7--e80281fc3a76491cb1e175f694705c99 9c726c7e229b491db663600199c06907 X e80281fc3a76491cb1e175f694705c99--9c726c7e229b491db663600199c06907 9c726c7e229b491db663600199c06907--288f361b5cb741cbaec09ccd8306cf4f 51dccfd4b249436fb0ff660904319696 9c726c7e229b491db663600199c06907--51dccfd4b249436fb0ff660904319696 3730b1c7f3a7493e98dac1b518180c6d RX(p2₁₅) 51dccfd4b249436fb0ff660904319696--3730b1c7f3a7493e98dac1b518180c6d 797c357a62054d9a8f7d7191a8e27fc6 RY(p2₁₉) 3730b1c7f3a7493e98dac1b518180c6d--797c357a62054d9a8f7d7191a8e27fc6 8ad1ec734bcb47e4bda63e290fc94cb4 RX(p2₂₃) 797c357a62054d9a8f7d7191a8e27fc6--8ad1ec734bcb47e4bda63e290fc94cb4 b5bb1306f98d42afa7d0d31f1bee9a6d X 8ad1ec734bcb47e4bda63e290fc94cb4--b5bb1306f98d42afa7d0d31f1bee9a6d b5bb1306f98d42afa7d0d31f1bee9a6d--5f5458af301143f2adce48045870e5a6 b10fc4f195224a8bbd986314d10cec23 b5bb1306f98d42afa7d0d31f1bee9a6d--b10fc4f195224a8bbd986314d10cec23 b10fc4f195224a8bbd986314d10cec23--a4c8ae104c8944768dce8c4f40030daf

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