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.9754+0.0000j, 0.0000-0.2203j]])

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.9058+0.0000j, 0.0000-0.4237j],
        [0.9047+0.0000j, 0.0000-0.4260j]])

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.5444+0.0000j, 0.8070+0.0000j, 0.0000-0.1279j, 0.0000-0.1896j]])

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_a39c867237f4410f8fb4f69736301413 [* 2] cluster_880527009ffa40fa8f9e035791c88f69 Rotations bb45549fb74e4441b7f14a9b36430664 0 8347f58efe4c493ea9d38f9ea0ddec91 RX(phi/theta) bb45549fb74e4441b7f14a9b36430664--8347f58efe4c493ea9d38f9ea0ddec91 f60704c17c6b457b8ec7b654420e1490 1 0a220245648f4c5e9c35856ec7e8da47 RX(phi) 8347f58efe4c493ea9d38f9ea0ddec91--0a220245648f4c5e9c35856ec7e8da47 01192982625245c29a33e6802a40da26 RX(phi) 0a220245648f4c5e9c35856ec7e8da47--01192982625245c29a33e6802a40da26 262939f8e6784098b9956d2f2832a244 RX(phi + theta) 01192982625245c29a33e6802a40da26--262939f8e6784098b9956d2f2832a244 5ef017d7694d48c8a6af55b05877c901 262939f8e6784098b9956d2f2832a244--5ef017d7694d48c8a6af55b05877c901 8141adbbf6694b3ba282fc6870458dc8 5ef017d7694d48c8a6af55b05877c901--8141adbbf6694b3ba282fc6870458dc8 676a2cf8e9134d2499074684d3864266 Z 8141adbbf6694b3ba282fc6870458dc8--676a2cf8e9134d2499074684d3864266 5bb1ea75f9e3443e9f07cdbaafff2190 676a2cf8e9134d2499074684d3864266--5bb1ea75f9e3443e9f07cdbaafff2190 e8d2758ec0af4a349a94d0d6cbb7e805 7102aef7295b4565b1e4abb4fe4101a9 RY(2*theta) f60704c17c6b457b8ec7b654420e1490--7102aef7295b4565b1e4abb4fe4101a9 93bf6f7e96654efb8e89c3c7a0edca93 2 7cc9b6186f8d4a7c8670d6dff0074438 RY(theta) 7102aef7295b4565b1e4abb4fe4101a9--7cc9b6186f8d4a7c8670d6dff0074438 c0fbe39e7d7e40f98625b6f371cd4d07 RY(theta) 7cc9b6186f8d4a7c8670d6dff0074438--c0fbe39e7d7e40f98625b6f371cd4d07 f213f0110cf046f89015cf52677af915 RY(theta**2) c0fbe39e7d7e40f98625b6f371cd4d07--f213f0110cf046f89015cf52677af915 2d7c196fe2c04463a23be69c9c61db2c X f213f0110cf046f89015cf52677af915--2d7c196fe2c04463a23be69c9c61db2c 2d7c196fe2c04463a23be69c9c61db2c--5ef017d7694d48c8a6af55b05877c901 c9c3aa02188946c2b27ef4671edfa616 2d7c196fe2c04463a23be69c9c61db2c--c9c3aa02188946c2b27ef4671edfa616 784610f65f074e2cad968bbaeefb483d Z c9c3aa02188946c2b27ef4671edfa616--784610f65f074e2cad968bbaeefb483d 784610f65f074e2cad968bbaeefb483d--e8d2758ec0af4a349a94d0d6cbb7e805 8d9ad7fafd0249f882243c49b4fc81ed 060c4cb78f534cec98f7dead3edaa18e RZ(cos(phi)) 93bf6f7e96654efb8e89c3c7a0edca93--060c4cb78f534cec98f7dead3edaa18e e87d9ec889544cb283ac63c908c29848 RZ(phi) 060c4cb78f534cec98f7dead3edaa18e--e87d9ec889544cb283ac63c908c29848 e42938b7a54e4980afd224060292e120 RZ(phi) e87d9ec889544cb283ac63c908c29848--e42938b7a54e4980afd224060292e120 e3049c23ad87448fb994f76a08924fea RZ(cos(phi)) e42938b7a54e4980afd224060292e120--e3049c23ad87448fb994f76a08924fea 4bf59aeb9f2d4d249d127e02d0274122 e3049c23ad87448fb994f76a08924fea--4bf59aeb9f2d4d249d127e02d0274122 9e23cca88afd46bab6023a044521e57a X 4bf59aeb9f2d4d249d127e02d0274122--9e23cca88afd46bab6023a044521e57a 9e23cca88afd46bab6023a044521e57a--c9c3aa02188946c2b27ef4671edfa616 1865b3ac7fe74520a9f05a4a7902b280 Z 9e23cca88afd46bab6023a044521e57a--1865b3ac7fe74520a9f05a4a7902b280 1865b3ac7fe74520a9f05a4a7902b280--8d9ad7fafd0249f882243c49b4fc81ed

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

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.9192+0.0000j, 0.2725+0.0000j, 0.0000-0.2725j, 0.0000-0.0808j],
        [0.7623+0.0000j, 0.4257+0.0000j, 0.0000-0.4257j, 0.0000-0.2377j],
        [0.7010+0.0000j, 0.4578+0.0000j, 0.0000-0.4578j, 0.0000-0.2990j]],
       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 ba5022654aef474fa89c7d4b5c8cf1a7 0 f308d3cfc3de4faebe5620995f4778ec RX(theta₀) ba5022654aef474fa89c7d4b5c8cf1a7--f308d3cfc3de4faebe5620995f4778ec b32639bfc3fc4cbbbf81031b1599fc62 1 7b65878828f444029ff76082ae6326c0 RY(theta₄) f308d3cfc3de4faebe5620995f4778ec--7b65878828f444029ff76082ae6326c0 438e437afe3d4826af7942752622b05f RX(theta₈) 7b65878828f444029ff76082ae6326c0--438e437afe3d4826af7942752622b05f 81aaa99b1dc1469680caf150b07be04d 438e437afe3d4826af7942752622b05f--81aaa99b1dc1469680caf150b07be04d d82032b370434aafa39085f2082165d5 81aaa99b1dc1469680caf150b07be04d--d82032b370434aafa39085f2082165d5 a32f3be887ab462ebdfa982e5a328ab2 RX(theta₁₂) d82032b370434aafa39085f2082165d5--a32f3be887ab462ebdfa982e5a328ab2 3a3fb4579171494a8d246dd695c583d5 RY(theta₁₆) a32f3be887ab462ebdfa982e5a328ab2--3a3fb4579171494a8d246dd695c583d5 abbdf85857eb4017b66d13b6d361b1db RX(theta₂₀) 3a3fb4579171494a8d246dd695c583d5--abbdf85857eb4017b66d13b6d361b1db 7480eee4b0424d92b3cfa878d1d75e53 abbdf85857eb4017b66d13b6d361b1db--7480eee4b0424d92b3cfa878d1d75e53 afcdf11464eb4490b472ace19e9f4eb9 7480eee4b0424d92b3cfa878d1d75e53--afcdf11464eb4490b472ace19e9f4eb9 18b3e700d30f459e9d5ebc45944e7c8f afcdf11464eb4490b472ace19e9f4eb9--18b3e700d30f459e9d5ebc45944e7c8f 07fbbf4c4980410faeae1261fa634ba1 67b258c81e994db99b1800953a52671e RX(theta₁) b32639bfc3fc4cbbbf81031b1599fc62--67b258c81e994db99b1800953a52671e 6e494e11cbd34b588b0abefe1504ab15 2 2d5ea3a9b4db4d6ab4669a78ad82b2d1 RY(theta₅) 67b258c81e994db99b1800953a52671e--2d5ea3a9b4db4d6ab4669a78ad82b2d1 df8deab1526449e689deb784accbac4e RX(theta₉) 2d5ea3a9b4db4d6ab4669a78ad82b2d1--df8deab1526449e689deb784accbac4e d37e1b6c5afd453fb4ac3f8f8d7899e9 X df8deab1526449e689deb784accbac4e--d37e1b6c5afd453fb4ac3f8f8d7899e9 d37e1b6c5afd453fb4ac3f8f8d7899e9--81aaa99b1dc1469680caf150b07be04d 37ff174debff46d481be753d8df8e864 d37e1b6c5afd453fb4ac3f8f8d7899e9--37ff174debff46d481be753d8df8e864 085b8e83cbc24fe48e61992da8a30d79 RX(theta₁₃) 37ff174debff46d481be753d8df8e864--085b8e83cbc24fe48e61992da8a30d79 b32aa6f2b9a04840ab69f20890fd0b3d RY(theta₁₇) 085b8e83cbc24fe48e61992da8a30d79--b32aa6f2b9a04840ab69f20890fd0b3d 0e8cc7c036bb4e9680abd212ab173d0d RX(theta₂₁) b32aa6f2b9a04840ab69f20890fd0b3d--0e8cc7c036bb4e9680abd212ab173d0d 6bc025230f5a44e5bac229ccac64fed1 X 0e8cc7c036bb4e9680abd212ab173d0d--6bc025230f5a44e5bac229ccac64fed1 6bc025230f5a44e5bac229ccac64fed1--7480eee4b0424d92b3cfa878d1d75e53 cccc65affa934d6981b70e3299055f67 6bc025230f5a44e5bac229ccac64fed1--cccc65affa934d6981b70e3299055f67 cccc65affa934d6981b70e3299055f67--07fbbf4c4980410faeae1261fa634ba1 d05c3eeb05a849c4a5ee50b8b587c3cc 95a61e4a8cee439d88453392e0f49a52 RX(theta₂) 6e494e11cbd34b588b0abefe1504ab15--95a61e4a8cee439d88453392e0f49a52 f321d632d4f64b248e66312c09527a74 3 4dca3af6a59548f2a5dc5aa31dafc2ce RY(theta₆) 95a61e4a8cee439d88453392e0f49a52--4dca3af6a59548f2a5dc5aa31dafc2ce a5ddcb3ab4014636853cfb2b46bcc95c RX(theta₁₀) 4dca3af6a59548f2a5dc5aa31dafc2ce--a5ddcb3ab4014636853cfb2b46bcc95c bd6dfebb79dc46a4bf64edbc46e5a489 a5ddcb3ab4014636853cfb2b46bcc95c--bd6dfebb79dc46a4bf64edbc46e5a489 bf0c3781ac094c8e9579898bcafa872b X bd6dfebb79dc46a4bf64edbc46e5a489--bf0c3781ac094c8e9579898bcafa872b bf0c3781ac094c8e9579898bcafa872b--37ff174debff46d481be753d8df8e864 246a42180f0d408a9bea092650ec9a42 RX(theta₁₄) bf0c3781ac094c8e9579898bcafa872b--246a42180f0d408a9bea092650ec9a42 d7d8efc1e834490980ea9442ca50cbdf RY(theta₁₈) 246a42180f0d408a9bea092650ec9a42--d7d8efc1e834490980ea9442ca50cbdf 607b84ced91c4ec5882b1c4147f596ca RX(theta₂₂) d7d8efc1e834490980ea9442ca50cbdf--607b84ced91c4ec5882b1c4147f596ca 3086c147d27d418cbfdf2331fd643d60 607b84ced91c4ec5882b1c4147f596ca--3086c147d27d418cbfdf2331fd643d60 ee3d6c7c333f4dfc86f2af09f34045af X 3086c147d27d418cbfdf2331fd643d60--ee3d6c7c333f4dfc86f2af09f34045af ee3d6c7c333f4dfc86f2af09f34045af--cccc65affa934d6981b70e3299055f67 ee3d6c7c333f4dfc86f2af09f34045af--d05c3eeb05a849c4a5ee50b8b587c3cc 283e99ea5a6f439c8907cda609a31b73 d2764670a1b741eca55797f9c94cad77 RX(theta₃) f321d632d4f64b248e66312c09527a74--d2764670a1b741eca55797f9c94cad77 33090468fbe647a88d95484b8b1b5054 RY(theta₇) d2764670a1b741eca55797f9c94cad77--33090468fbe647a88d95484b8b1b5054 e4b72e5139a544b0875cb116d2c2fd4f RX(theta₁₁) 33090468fbe647a88d95484b8b1b5054--e4b72e5139a544b0875cb116d2c2fd4f d1aa37379dc34df4932ba718418f6ef7 X e4b72e5139a544b0875cb116d2c2fd4f--d1aa37379dc34df4932ba718418f6ef7 d1aa37379dc34df4932ba718418f6ef7--bd6dfebb79dc46a4bf64edbc46e5a489 aeac3a2307614e40b6698d2d019eed6c d1aa37379dc34df4932ba718418f6ef7--aeac3a2307614e40b6698d2d019eed6c b279936280c6430b99df463151d4fa9b RX(theta₁₅) aeac3a2307614e40b6698d2d019eed6c--b279936280c6430b99df463151d4fa9b 24fa765e3d854148bf6ca2d91472b2c0 RY(theta₁₉) b279936280c6430b99df463151d4fa9b--24fa765e3d854148bf6ca2d91472b2c0 24bf6495b4324dde9bddf47692be5f94 RX(theta₂₃) 24fa765e3d854148bf6ca2d91472b2c0--24bf6495b4324dde9bddf47692be5f94 7b8b3fb6d5944f5eb3e7cd81b81da1a0 X 24bf6495b4324dde9bddf47692be5f94--7b8b3fb6d5944f5eb3e7cd81b81da1a0 7b8b3fb6d5944f5eb3e7cd81b81da1a0--3086c147d27d418cbfdf2331fd643d60 ed06f335dcff4181b4e61abf06233e45 7b8b3fb6d5944f5eb3e7cd81b81da1a0--ed06f335dcff4181b4e61abf06233e45 ed06f335dcff4181b4e61abf06233e45--283e99ea5a6f439c8907cda609a31b73

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_6f539518b2c84487be1540ad57882102 HEA cluster_70cc803c9b3e4e8ca59661d755b512b3 HEA 2f8dcba216454c6a9e1805b66b62abab 0 d9212ae88e91494593faf4476fbd4d74 RX(theta₀) 2f8dcba216454c6a9e1805b66b62abab--d9212ae88e91494593faf4476fbd4d74 e3d7939ecfbf4647b09ff369ec76f090 1 14db1da304974201bbc698d21b0e2121 RY(theta₄) d9212ae88e91494593faf4476fbd4d74--14db1da304974201bbc698d21b0e2121 68b4275ad7e0443684cc13ebfda9ea6c RX(theta₈) 14db1da304974201bbc698d21b0e2121--68b4275ad7e0443684cc13ebfda9ea6c 4e1f82320a61407ca53c4ac06a44de98 68b4275ad7e0443684cc13ebfda9ea6c--4e1f82320a61407ca53c4ac06a44de98 b464bf8460844b028610ef0157f20eb0 4e1f82320a61407ca53c4ac06a44de98--b464bf8460844b028610ef0157f20eb0 04c7415c186949e29c754ea32a899e83 RX(theta₁₂) b464bf8460844b028610ef0157f20eb0--04c7415c186949e29c754ea32a899e83 47a8e43d153b4c7b8a57898a552e00af RY(theta₁₆) 04c7415c186949e29c754ea32a899e83--47a8e43d153b4c7b8a57898a552e00af fcc68830f8fa486284236eac2d39b3c0 RX(theta₂₀) 47a8e43d153b4c7b8a57898a552e00af--fcc68830f8fa486284236eac2d39b3c0 e71ab9fe456e493bb3e5fd997b74d447 fcc68830f8fa486284236eac2d39b3c0--e71ab9fe456e493bb3e5fd997b74d447 40200ab361a54fa4b7f6fd168ebbdc44 e71ab9fe456e493bb3e5fd997b74d447--40200ab361a54fa4b7f6fd168ebbdc44 d8dee128a89c4650994c5277ec0d8c3f RX(theta₀) 40200ab361a54fa4b7f6fd168ebbdc44--d8dee128a89c4650994c5277ec0d8c3f 4e473d66460b4e2a900cd8720560bb8b RY(theta₄) d8dee128a89c4650994c5277ec0d8c3f--4e473d66460b4e2a900cd8720560bb8b c581acf9319147cc89f342d6b149a95a RX(theta₈) 4e473d66460b4e2a900cd8720560bb8b--c581acf9319147cc89f342d6b149a95a 1e3ec6c4bd6b419abf4edcef9ef8b94f c581acf9319147cc89f342d6b149a95a--1e3ec6c4bd6b419abf4edcef9ef8b94f da875a59669c41148af553aee76b99e8 1e3ec6c4bd6b419abf4edcef9ef8b94f--da875a59669c41148af553aee76b99e8 7b5e9e5a0c7f414895ca42e90854cabc RX(theta₁₂) da875a59669c41148af553aee76b99e8--7b5e9e5a0c7f414895ca42e90854cabc 223995287c4a4448b4829beb91cf86ce RY(theta₁₆) 7b5e9e5a0c7f414895ca42e90854cabc--223995287c4a4448b4829beb91cf86ce d3c46010d8044d6baeb7363c63f4d45f RX(theta₂₀) 223995287c4a4448b4829beb91cf86ce--d3c46010d8044d6baeb7363c63f4d45f 5319fecd2a1d40f4b8d8354a4e2ffe3c d3c46010d8044d6baeb7363c63f4d45f--5319fecd2a1d40f4b8d8354a4e2ffe3c 50cd2aecc33d47639898582879d12721 5319fecd2a1d40f4b8d8354a4e2ffe3c--50cd2aecc33d47639898582879d12721 72751ce039d2456b9add2002d0cdfa1c 50cd2aecc33d47639898582879d12721--72751ce039d2456b9add2002d0cdfa1c 93c26031b31640db832ff779bdc4c1d3 595154b048ea4921af7881800762ddfb RX(theta₁) e3d7939ecfbf4647b09ff369ec76f090--595154b048ea4921af7881800762ddfb 058fa49a919c438796a8425cc06883ed 2 8bfa02af62f54d7493c2fa04ec05a14d RY(theta₅) 595154b048ea4921af7881800762ddfb--8bfa02af62f54d7493c2fa04ec05a14d 52cf04b5fa164dc893f915974c568bb6 RX(theta₉) 8bfa02af62f54d7493c2fa04ec05a14d--52cf04b5fa164dc893f915974c568bb6 f860ac0ea07c497ba075907992f92fbb X 52cf04b5fa164dc893f915974c568bb6--f860ac0ea07c497ba075907992f92fbb f860ac0ea07c497ba075907992f92fbb--4e1f82320a61407ca53c4ac06a44de98 7584a94161ef47f5883dfae2792c6c1a f860ac0ea07c497ba075907992f92fbb--7584a94161ef47f5883dfae2792c6c1a c5586bf5dd1243f2895571266ac876f3 RX(theta₁₃) 7584a94161ef47f5883dfae2792c6c1a--c5586bf5dd1243f2895571266ac876f3 9a6739434b414b579d9cb82a0e3e0d97 RY(theta₁₇) c5586bf5dd1243f2895571266ac876f3--9a6739434b414b579d9cb82a0e3e0d97 8687257f4a1f47a69686fd81cf0370fa RX(theta₂₁) 9a6739434b414b579d9cb82a0e3e0d97--8687257f4a1f47a69686fd81cf0370fa 0607a452941d44079569e98013d666ba X 8687257f4a1f47a69686fd81cf0370fa--0607a452941d44079569e98013d666ba 0607a452941d44079569e98013d666ba--e71ab9fe456e493bb3e5fd997b74d447 cfa18356c3f542178612115f07004fc4 0607a452941d44079569e98013d666ba--cfa18356c3f542178612115f07004fc4 5b624563c41c450b82ee21e13d93508a RX(theta₁) cfa18356c3f542178612115f07004fc4--5b624563c41c450b82ee21e13d93508a 3f4e3ea75a0442b7aecadd76dea8ec2b RY(theta₅) 5b624563c41c450b82ee21e13d93508a--3f4e3ea75a0442b7aecadd76dea8ec2b be42b1c81bcb4e7d98c48297235a85ca RX(theta₉) 3f4e3ea75a0442b7aecadd76dea8ec2b--be42b1c81bcb4e7d98c48297235a85ca 33a6e61bac2648a4a16fd4bcac3d339d X be42b1c81bcb4e7d98c48297235a85ca--33a6e61bac2648a4a16fd4bcac3d339d 33a6e61bac2648a4a16fd4bcac3d339d--1e3ec6c4bd6b419abf4edcef9ef8b94f e934e674e596420b912dae2fa01e6293 33a6e61bac2648a4a16fd4bcac3d339d--e934e674e596420b912dae2fa01e6293 2e2519f7701348e19ab43ab64dbdfae1 RX(theta₁₃) e934e674e596420b912dae2fa01e6293--2e2519f7701348e19ab43ab64dbdfae1 965547ad69db41b6b731612fcf9b91dc RY(theta₁₇) 2e2519f7701348e19ab43ab64dbdfae1--965547ad69db41b6b731612fcf9b91dc df59aec1f7ba4fc38357d9af661ea65d RX(theta₂₁) 965547ad69db41b6b731612fcf9b91dc--df59aec1f7ba4fc38357d9af661ea65d 2492bf49c3184684b5858a907255c3db X df59aec1f7ba4fc38357d9af661ea65d--2492bf49c3184684b5858a907255c3db 2492bf49c3184684b5858a907255c3db--5319fecd2a1d40f4b8d8354a4e2ffe3c a66beb3e763a4ee18c1a63e8fffbe576 2492bf49c3184684b5858a907255c3db--a66beb3e763a4ee18c1a63e8fffbe576 a66beb3e763a4ee18c1a63e8fffbe576--93c26031b31640db832ff779bdc4c1d3 66643f46d88e4317b128cb55ad145324 02b79a638c4846858a12784f510620e5 RX(theta₂) 058fa49a919c438796a8425cc06883ed--02b79a638c4846858a12784f510620e5 19f05295c5e1469e83f1165d87699454 3 7f99a76166f44265af6abbb033131e6d RY(theta₆) 02b79a638c4846858a12784f510620e5--7f99a76166f44265af6abbb033131e6d 02b9365a86bf4af8b3b3fe6a49d9623e RX(theta₁₀) 7f99a76166f44265af6abbb033131e6d--02b9365a86bf4af8b3b3fe6a49d9623e cdb1a6c583444d459a9f77d1e95d7cd0 02b9365a86bf4af8b3b3fe6a49d9623e--cdb1a6c583444d459a9f77d1e95d7cd0 aab42bc5b22945a2bf412526b2755391 X cdb1a6c583444d459a9f77d1e95d7cd0--aab42bc5b22945a2bf412526b2755391 aab42bc5b22945a2bf412526b2755391--7584a94161ef47f5883dfae2792c6c1a 47e0955ff3284b58b22467433b1f1d43 RX(theta₁₄) aab42bc5b22945a2bf412526b2755391--47e0955ff3284b58b22467433b1f1d43 262224ec9af842d883bdf069ba9e8e71 RY(theta₁₈) 47e0955ff3284b58b22467433b1f1d43--262224ec9af842d883bdf069ba9e8e71 996af01b4d4745918b0c5de302ba6a61 RX(theta₂₂) 262224ec9af842d883bdf069ba9e8e71--996af01b4d4745918b0c5de302ba6a61 9803c4bdc43949ecbf6632fca2dc9661 996af01b4d4745918b0c5de302ba6a61--9803c4bdc43949ecbf6632fca2dc9661 0bc8bac1be344ca2855988d9d627d279 X 9803c4bdc43949ecbf6632fca2dc9661--0bc8bac1be344ca2855988d9d627d279 0bc8bac1be344ca2855988d9d627d279--cfa18356c3f542178612115f07004fc4 1fc28e16adf14f19adf82ef26445a0d2 RX(theta₂) 0bc8bac1be344ca2855988d9d627d279--1fc28e16adf14f19adf82ef26445a0d2 e7f6cd4309574df3b3a4214e70b53a81 RY(theta₆) 1fc28e16adf14f19adf82ef26445a0d2--e7f6cd4309574df3b3a4214e70b53a81 64ff197f6961486790047747caf78e86 RX(theta₁₀) e7f6cd4309574df3b3a4214e70b53a81--64ff197f6961486790047747caf78e86 6f922fdb424242f2adab4d77ee9b393b 64ff197f6961486790047747caf78e86--6f922fdb424242f2adab4d77ee9b393b 008f9303bc4e4dabafb5aaf4c684cb6e X 6f922fdb424242f2adab4d77ee9b393b--008f9303bc4e4dabafb5aaf4c684cb6e 008f9303bc4e4dabafb5aaf4c684cb6e--e934e674e596420b912dae2fa01e6293 f6b31ce6883647be8f109f5ac8ccf2df RX(theta₁₄) 008f9303bc4e4dabafb5aaf4c684cb6e--f6b31ce6883647be8f109f5ac8ccf2df 8c99afd2f79146af9cc02f6a54ca37fc RY(theta₁₈) f6b31ce6883647be8f109f5ac8ccf2df--8c99afd2f79146af9cc02f6a54ca37fc 6debc978ab694bec8ce2bc5e2cea38be RX(theta₂₂) 8c99afd2f79146af9cc02f6a54ca37fc--6debc978ab694bec8ce2bc5e2cea38be 543e23d5bf86457982a715b6d94762bf 6debc978ab694bec8ce2bc5e2cea38be--543e23d5bf86457982a715b6d94762bf 6aa46321d5e74b4d906acc524c2fa2cb X 543e23d5bf86457982a715b6d94762bf--6aa46321d5e74b4d906acc524c2fa2cb 6aa46321d5e74b4d906acc524c2fa2cb--a66beb3e763a4ee18c1a63e8fffbe576 6aa46321d5e74b4d906acc524c2fa2cb--66643f46d88e4317b128cb55ad145324 4fcdbc9b58fb4dbc98cef719aa6dd2c5 56a3419263e94c4bb28a7eb1c2c2fcba RX(theta₃) 19f05295c5e1469e83f1165d87699454--56a3419263e94c4bb28a7eb1c2c2fcba 93ecd3deb0db47239ebe002a1ec7bbbc RY(theta₇) 56a3419263e94c4bb28a7eb1c2c2fcba--93ecd3deb0db47239ebe002a1ec7bbbc d12a406e0941424f98e48f89d41e9dfa RX(theta₁₁) 93ecd3deb0db47239ebe002a1ec7bbbc--d12a406e0941424f98e48f89d41e9dfa 1b9552101093400883866ea2ac971bd3 X d12a406e0941424f98e48f89d41e9dfa--1b9552101093400883866ea2ac971bd3 1b9552101093400883866ea2ac971bd3--cdb1a6c583444d459a9f77d1e95d7cd0 fdaba70985e347e8830fea6c2c4f5777 1b9552101093400883866ea2ac971bd3--fdaba70985e347e8830fea6c2c4f5777 a36176b170014d9e9fd95827f4c0db10 RX(theta₁₅) fdaba70985e347e8830fea6c2c4f5777--a36176b170014d9e9fd95827f4c0db10 be695c27b1b8432290739518bcf967f8 RY(theta₁₉) a36176b170014d9e9fd95827f4c0db10--be695c27b1b8432290739518bcf967f8 e79a8c3d04f14339af2069cbbc7de197 RX(theta₂₃) be695c27b1b8432290739518bcf967f8--e79a8c3d04f14339af2069cbbc7de197 015e207d2f2140d8ab6fef3bd38a9b4e X e79a8c3d04f14339af2069cbbc7de197--015e207d2f2140d8ab6fef3bd38a9b4e 015e207d2f2140d8ab6fef3bd38a9b4e--9803c4bdc43949ecbf6632fca2dc9661 b4d78506ab0c4efcb299ee9a38883252 015e207d2f2140d8ab6fef3bd38a9b4e--b4d78506ab0c4efcb299ee9a38883252 bf41dc6c39cf48d4ad9597b14c5167c2 RX(theta₃) b4d78506ab0c4efcb299ee9a38883252--bf41dc6c39cf48d4ad9597b14c5167c2 7337f210894c4ecd84a82601de9d39ec RY(theta₇) bf41dc6c39cf48d4ad9597b14c5167c2--7337f210894c4ecd84a82601de9d39ec 295671416b70412a8dbbc5bf3e555fbb RX(theta₁₁) 7337f210894c4ecd84a82601de9d39ec--295671416b70412a8dbbc5bf3e555fbb 5113c9c90a7446dc9d5ff0d8c885f815 X 295671416b70412a8dbbc5bf3e555fbb--5113c9c90a7446dc9d5ff0d8c885f815 5113c9c90a7446dc9d5ff0d8c885f815--6f922fdb424242f2adab4d77ee9b393b 9bf4a26dcf8240d781205c2b5a4aabf5 5113c9c90a7446dc9d5ff0d8c885f815--9bf4a26dcf8240d781205c2b5a4aabf5 9d81e3f2e2c241cfb43e344bc8f7195d RX(theta₁₅) 9bf4a26dcf8240d781205c2b5a4aabf5--9d81e3f2e2c241cfb43e344bc8f7195d 0d464c3f4b514f519ad8dc4621eeb9ad RY(theta₁₉) 9d81e3f2e2c241cfb43e344bc8f7195d--0d464c3f4b514f519ad8dc4621eeb9ad bebfa40134fd4da7976f55080bc68fc7 RX(theta₂₃) 0d464c3f4b514f519ad8dc4621eeb9ad--bebfa40134fd4da7976f55080bc68fc7 c2d2fb8dfda742deb51c3872da0cf242 X bebfa40134fd4da7976f55080bc68fc7--c2d2fb8dfda742deb51c3872da0cf242 c2d2fb8dfda742deb51c3872da0cf242--543e23d5bf86457982a715b6d94762bf 770fad8d87e540109c9d86e4d941e383 c2d2fb8dfda742deb51c3872da0cf242--770fad8d87e540109c9d86e4d941e383 770fad8d87e540109c9d86e4d941e383--4fcdbc9b58fb4dbc98cef719aa6dd2c5

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_9cd1fbaab3d8425d8283333d3fcd86b9 HEA cluster_dd75c95354fd4796a77c62e95e44b0dc HEA 3c5ed0d996ca4291b4c1b0e9d50d29f1 0 21195e057aa34f3bb98db204ad17a87e RX(p1₀) 3c5ed0d996ca4291b4c1b0e9d50d29f1--21195e057aa34f3bb98db204ad17a87e cbcdbe98954042d286e316ce9a77dba5 1 48f796215aaa40d693d7f702e9a89a1e RY(p1₄) 21195e057aa34f3bb98db204ad17a87e--48f796215aaa40d693d7f702e9a89a1e 168061ff343047e9b5564e0e8a7e1259 RX(p1₈) 48f796215aaa40d693d7f702e9a89a1e--168061ff343047e9b5564e0e8a7e1259 79c1b741c65343d799af7d95f1c2b375 168061ff343047e9b5564e0e8a7e1259--79c1b741c65343d799af7d95f1c2b375 f2855f6a56764cd9957bc2765f1baafd 79c1b741c65343d799af7d95f1c2b375--f2855f6a56764cd9957bc2765f1baafd 8a3a4769082d413995d3d6b14f1469d5 RX(p1₁₂) f2855f6a56764cd9957bc2765f1baafd--8a3a4769082d413995d3d6b14f1469d5 8aa9c91e315f433d93a45e548d0293c3 RY(p1₁₆) 8a3a4769082d413995d3d6b14f1469d5--8aa9c91e315f433d93a45e548d0293c3 e1da5ed8a6124c418a5cf877228c64e3 RX(p1₂₀) 8aa9c91e315f433d93a45e548d0293c3--e1da5ed8a6124c418a5cf877228c64e3 dbaeeb972f2a43059304765dcc787cdc e1da5ed8a6124c418a5cf877228c64e3--dbaeeb972f2a43059304765dcc787cdc 94c2f5be23924cf79358aa438576d2c0 dbaeeb972f2a43059304765dcc787cdc--94c2f5be23924cf79358aa438576d2c0 df385951ef684de0ac665648a293842e RX(p2₀) 94c2f5be23924cf79358aa438576d2c0--df385951ef684de0ac665648a293842e 5d5dec9e70f64b67b4659915774b2147 RY(p2₄) df385951ef684de0ac665648a293842e--5d5dec9e70f64b67b4659915774b2147 8ae7754c169747ef92119901da63ae46 RX(p2₈) 5d5dec9e70f64b67b4659915774b2147--8ae7754c169747ef92119901da63ae46 ed2969ea71984ba0b21fe002549d48a8 8ae7754c169747ef92119901da63ae46--ed2969ea71984ba0b21fe002549d48a8 534878a05499438bb9eb5e7e8bf10089 ed2969ea71984ba0b21fe002549d48a8--534878a05499438bb9eb5e7e8bf10089 75c7efa5907749069840710ebe62702c RX(p2₁₂) 534878a05499438bb9eb5e7e8bf10089--75c7efa5907749069840710ebe62702c d25b731baf53457a9bdd178ce26cf6c9 RY(p2₁₆) 75c7efa5907749069840710ebe62702c--d25b731baf53457a9bdd178ce26cf6c9 d896fc6622044b6e9976a8868c363495 RX(p2₂₀) d25b731baf53457a9bdd178ce26cf6c9--d896fc6622044b6e9976a8868c363495 a5a871b7ecc14ae8824eceeb87ee9dec d896fc6622044b6e9976a8868c363495--a5a871b7ecc14ae8824eceeb87ee9dec ad71c0543b9b407a9da340677131fd7d a5a871b7ecc14ae8824eceeb87ee9dec--ad71c0543b9b407a9da340677131fd7d 4cf1eeaaa30b4875895b6aa962b3208f ad71c0543b9b407a9da340677131fd7d--4cf1eeaaa30b4875895b6aa962b3208f b838cdcc3770453cbfa7e72ce90c2c06 e87b6bb5256042f99d1a636f6405aff9 RX(p1₁) cbcdbe98954042d286e316ce9a77dba5--e87b6bb5256042f99d1a636f6405aff9 0efc9fe5b9d14357aac443bd050ad8fd 2 2fd4de19c2864abd8da8b319ebd2f416 RY(p1₅) e87b6bb5256042f99d1a636f6405aff9--2fd4de19c2864abd8da8b319ebd2f416 80e62a30c33b46b6b638c6e908c6d73b RX(p1₉) 2fd4de19c2864abd8da8b319ebd2f416--80e62a30c33b46b6b638c6e908c6d73b 92a1b557377d4faa8212e0ee296c0fe5 X 80e62a30c33b46b6b638c6e908c6d73b--92a1b557377d4faa8212e0ee296c0fe5 92a1b557377d4faa8212e0ee296c0fe5--79c1b741c65343d799af7d95f1c2b375 1e74640b2e534b2aa67ec611c0d4d852 92a1b557377d4faa8212e0ee296c0fe5--1e74640b2e534b2aa67ec611c0d4d852 fe3046092b8d42c784d843be36e54974 RX(p1₁₃) 1e74640b2e534b2aa67ec611c0d4d852--fe3046092b8d42c784d843be36e54974 6f2c50b0c2ea401cb9ff4ab824320dcf RY(p1₁₇) fe3046092b8d42c784d843be36e54974--6f2c50b0c2ea401cb9ff4ab824320dcf e6bd86f6b1b948f8a4de9e7419028f56 RX(p1₂₁) 6f2c50b0c2ea401cb9ff4ab824320dcf--e6bd86f6b1b948f8a4de9e7419028f56 206a96a992d645ecb3540c8b53b95ef1 X e6bd86f6b1b948f8a4de9e7419028f56--206a96a992d645ecb3540c8b53b95ef1 206a96a992d645ecb3540c8b53b95ef1--dbaeeb972f2a43059304765dcc787cdc ce0161424347415885017bb11ef9fe3f 206a96a992d645ecb3540c8b53b95ef1--ce0161424347415885017bb11ef9fe3f f5aae61dd1474fca8667d92bf473d052 RX(p2₁) ce0161424347415885017bb11ef9fe3f--f5aae61dd1474fca8667d92bf473d052 a395547476d84076b2d44f8c3d1cdf8d RY(p2₅) f5aae61dd1474fca8667d92bf473d052--a395547476d84076b2d44f8c3d1cdf8d cbf19c041dcf4455b695667149ac229e RX(p2₉) a395547476d84076b2d44f8c3d1cdf8d--cbf19c041dcf4455b695667149ac229e 9a5b34cf09bf48b08e247ab9ef22d971 X cbf19c041dcf4455b695667149ac229e--9a5b34cf09bf48b08e247ab9ef22d971 9a5b34cf09bf48b08e247ab9ef22d971--ed2969ea71984ba0b21fe002549d48a8 f625752fe53444a1b3064b1e58eb4024 9a5b34cf09bf48b08e247ab9ef22d971--f625752fe53444a1b3064b1e58eb4024 cc5c448742b24a0ba701cab7eb809c26 RX(p2₁₃) f625752fe53444a1b3064b1e58eb4024--cc5c448742b24a0ba701cab7eb809c26 9d192dd5fcb04d18a7f822d6a6040716 RY(p2₁₇) cc5c448742b24a0ba701cab7eb809c26--9d192dd5fcb04d18a7f822d6a6040716 3131eff5117e434988607bbc5dc3bd9b RX(p2₂₁) 9d192dd5fcb04d18a7f822d6a6040716--3131eff5117e434988607bbc5dc3bd9b b7936b996aa64e4eb2cd80142e7bd383 X 3131eff5117e434988607bbc5dc3bd9b--b7936b996aa64e4eb2cd80142e7bd383 b7936b996aa64e4eb2cd80142e7bd383--a5a871b7ecc14ae8824eceeb87ee9dec 488f20e7226548f3a322c662bd421e07 b7936b996aa64e4eb2cd80142e7bd383--488f20e7226548f3a322c662bd421e07 488f20e7226548f3a322c662bd421e07--b838cdcc3770453cbfa7e72ce90c2c06 dd168719c9b842bcaecd8b35f77f17f8 585d66e894f34ed2a9c27138d3135859 RX(p1₂) 0efc9fe5b9d14357aac443bd050ad8fd--585d66e894f34ed2a9c27138d3135859 923e05400410432fb24e8a3cd247ff57 3 fb5b11f70c3641859748d5544648b610 RY(p1₆) 585d66e894f34ed2a9c27138d3135859--fb5b11f70c3641859748d5544648b610 e2c49702dde14518bd6ee750f7831da6 RX(p1₁₀) fb5b11f70c3641859748d5544648b610--e2c49702dde14518bd6ee750f7831da6 e12a6564f07c436489a6be309f663c0b e2c49702dde14518bd6ee750f7831da6--e12a6564f07c436489a6be309f663c0b b102d49fc73f4b8fa049d23050ff35c3 X e12a6564f07c436489a6be309f663c0b--b102d49fc73f4b8fa049d23050ff35c3 b102d49fc73f4b8fa049d23050ff35c3--1e74640b2e534b2aa67ec611c0d4d852 1d5dc6800e764b709293ec18820a4435 RX(p1₁₄) b102d49fc73f4b8fa049d23050ff35c3--1d5dc6800e764b709293ec18820a4435 1037b308b9e647ae8eee43b1a9450811 RY(p1₁₈) 1d5dc6800e764b709293ec18820a4435--1037b308b9e647ae8eee43b1a9450811 f5af8181f6784309a5912a557793980a RX(p1₂₂) 1037b308b9e647ae8eee43b1a9450811--f5af8181f6784309a5912a557793980a e63e77be399c47cda8f053fc98f50c4e f5af8181f6784309a5912a557793980a--e63e77be399c47cda8f053fc98f50c4e bf6f46c5afe64b94b63fee1fd5979912 X e63e77be399c47cda8f053fc98f50c4e--bf6f46c5afe64b94b63fee1fd5979912 bf6f46c5afe64b94b63fee1fd5979912--ce0161424347415885017bb11ef9fe3f 66935f41da4842eebe6d069a54dd67ce RX(p2₂) bf6f46c5afe64b94b63fee1fd5979912--66935f41da4842eebe6d069a54dd67ce f65ce27103e349b2a1b6cf78517c55e5 RY(p2₆) 66935f41da4842eebe6d069a54dd67ce--f65ce27103e349b2a1b6cf78517c55e5 414c54ffab0b411d954a3fec150c782b RX(p2₁₀) f65ce27103e349b2a1b6cf78517c55e5--414c54ffab0b411d954a3fec150c782b 905f3dcfe479488ca0e885d9693f4b04 414c54ffab0b411d954a3fec150c782b--905f3dcfe479488ca0e885d9693f4b04 76c06d5522844962a688157558d8ffd6 X 905f3dcfe479488ca0e885d9693f4b04--76c06d5522844962a688157558d8ffd6 76c06d5522844962a688157558d8ffd6--f625752fe53444a1b3064b1e58eb4024 49433a05952046bf8757bdfd5df0f08e RX(p2₁₄) 76c06d5522844962a688157558d8ffd6--49433a05952046bf8757bdfd5df0f08e 75956f07ba304a8a8a68a89813d6e31e RY(p2₁₈) 49433a05952046bf8757bdfd5df0f08e--75956f07ba304a8a8a68a89813d6e31e f4da5f9b230344188235442964b1b801 RX(p2₂₂) 75956f07ba304a8a8a68a89813d6e31e--f4da5f9b230344188235442964b1b801 dbdc8d15cba7480ea27fbc67beb39de0 f4da5f9b230344188235442964b1b801--dbdc8d15cba7480ea27fbc67beb39de0 32aeeb33666048368965e61680e2babf X dbdc8d15cba7480ea27fbc67beb39de0--32aeeb33666048368965e61680e2babf 32aeeb33666048368965e61680e2babf--488f20e7226548f3a322c662bd421e07 32aeeb33666048368965e61680e2babf--dd168719c9b842bcaecd8b35f77f17f8 ca30066c34434552b018d7e3ffbf154b 8681e946a2724541b77713b78af34072 RX(p1₃) 923e05400410432fb24e8a3cd247ff57--8681e946a2724541b77713b78af34072 0e98414718fa41efb05bce54a8f9de4d RY(p1₇) 8681e946a2724541b77713b78af34072--0e98414718fa41efb05bce54a8f9de4d 151a1f7d03a74784802a7cc544043863 RX(p1₁₁) 0e98414718fa41efb05bce54a8f9de4d--151a1f7d03a74784802a7cc544043863 2fc6a1ff61e44b399621d01ab93fea0e X 151a1f7d03a74784802a7cc544043863--2fc6a1ff61e44b399621d01ab93fea0e 2fc6a1ff61e44b399621d01ab93fea0e--e12a6564f07c436489a6be309f663c0b f901d158e9c94f2b93310fd5c7202876 2fc6a1ff61e44b399621d01ab93fea0e--f901d158e9c94f2b93310fd5c7202876 6e23d2cb335c4858ba2dec9eda6b548c RX(p1₁₅) f901d158e9c94f2b93310fd5c7202876--6e23d2cb335c4858ba2dec9eda6b548c a0e8c20a51ee4f9c985baf55b16c55e4 RY(p1₁₉) 6e23d2cb335c4858ba2dec9eda6b548c--a0e8c20a51ee4f9c985baf55b16c55e4 aef75b09db5549eda5424440a9a3a342 RX(p1₂₃) a0e8c20a51ee4f9c985baf55b16c55e4--aef75b09db5549eda5424440a9a3a342 cab50551d0af49ee92303e28ab7110f5 X aef75b09db5549eda5424440a9a3a342--cab50551d0af49ee92303e28ab7110f5 cab50551d0af49ee92303e28ab7110f5--e63e77be399c47cda8f053fc98f50c4e 68e67a0c1c2f48909e212f6d1106697d cab50551d0af49ee92303e28ab7110f5--68e67a0c1c2f48909e212f6d1106697d a654d0cb35a144e5952ef261a8e27564 RX(p2₃) 68e67a0c1c2f48909e212f6d1106697d--a654d0cb35a144e5952ef261a8e27564 c782c11a18374f69917f763f7be372fa RY(p2₇) a654d0cb35a144e5952ef261a8e27564--c782c11a18374f69917f763f7be372fa dee0ea47280a4705a83e6cc7144ae806 RX(p2₁₁) c782c11a18374f69917f763f7be372fa--dee0ea47280a4705a83e6cc7144ae806 4947f98c804c4d7f81efc4afde9ce468 X dee0ea47280a4705a83e6cc7144ae806--4947f98c804c4d7f81efc4afde9ce468 4947f98c804c4d7f81efc4afde9ce468--905f3dcfe479488ca0e885d9693f4b04 8f361623e2fa4d048a4382c4c9fa21ba 4947f98c804c4d7f81efc4afde9ce468--8f361623e2fa4d048a4382c4c9fa21ba 34a42884c2224b8d807bdfa6f757bd89 RX(p2₁₅) 8f361623e2fa4d048a4382c4c9fa21ba--34a42884c2224b8d807bdfa6f757bd89 fdd3f29c3e924a7b987a53d98c5157b7 RY(p2₁₉) 34a42884c2224b8d807bdfa6f757bd89--fdd3f29c3e924a7b987a53d98c5157b7 d68f2a8fada645de8f1900ce168888d4 RX(p2₂₃) fdd3f29c3e924a7b987a53d98c5157b7--d68f2a8fada645de8f1900ce168888d4 1dc37f9ac818433985c9def4827e1859 X d68f2a8fada645de8f1900ce168888d4--1dc37f9ac818433985c9def4827e1859 1dc37f9ac818433985c9def4827e1859--dbdc8d15cba7480ea27fbc67beb39de0 645560549e2845629ff84aaf9f92ff54 1dc37f9ac818433985c9def4827e1859--645560549e2845629ff84aaf9f92ff54 645560549e2845629ff84aaf9f92ff54--ca30066c34434552b018d7e3ffbf154b

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.6723])), ('theta_0', tensor([0.1476])), ('theta_1', tensor([0.6309])), ('theta_10', tensor([0.8657])), ('theta_11', tensor([0.8418])), ('theta_12', tensor([0.1063])), ('theta_13', tensor([0.6077])), ('theta_14', tensor([0.8846])), ('theta_15', tensor([0.9668])), ('theta_16', tensor([0.2565])), ('theta_17', tensor([0.1043])), ('theta_18', tensor([0.9783])), ('theta_19', tensor([0.0618])), ('theta_2', tensor([0.1834])), ('theta_20', tensor([0.4442])), ('theta_21', tensor([0.6389])), ('theta_22', tensor([0.6250])), ('theta_23', tensor([0.5487])), ('theta_3', tensor([0.8038])), ('theta_4', tensor([0.9408])), ('theta_5', tensor([0.4441])), ('theta_6', tensor([0.6926])), ('theta_7', tensor([0.3457])), ('theta_8', tensor([0.6128])), ('theta_9', tensor([0.6174]))])

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.6713])), ('theta_0', tensor([0.1486])), ('theta_1', tensor([0.6319])), ('theta_10', tensor([0.8667])), ('theta_11', tensor([0.8428])), ('theta_12', tensor([0.1073])), ('theta_13', tensor([0.6067])), ('theta_14', tensor([0.8856])), ('theta_15', tensor([0.9678])), ('theta_16', tensor([0.2575])), ('theta_17', tensor([0.1033])), ('theta_18', tensor([0.9773])), ('theta_19', tensor([0.0608])), ('theta_2', tensor([0.1844])), ('theta_20', tensor([0.4452])), ('theta_21', tensor([0.6379])), ('theta_22', tensor([0.6260])), ('theta_23', tensor([0.5497])), ('theta_3', tensor([0.8048])), ('theta_4', tensor([0.9418])), ('theta_5', tensor([0.4451])), ('theta_6', tensor([0.6936])), ('theta_7', tensor([0.3467])), ('theta_8', tensor([0.6138])), ('theta_9', tensor([0.6184]))])

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