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.9895+0.0000j, 0.0000-0.1448j]])

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.8811+0.0000j, 0.0000-0.4730j],
        [0.9812+0.0000j, 0.0000-0.1931j]])

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.8543+0.0000j, 0.3484+0.0000j, 0.0000-0.3572j, 0.0000-0.1457j]])

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_dfe375d8132740509441d749380475b3 [* 2] cluster_b603a0939e574ec4b85a116096f2fce3 Rotations 5260ccef0f2e41768bc207903d310650 0 028a521968374f95bfcf201e67d60f17 RX(phi/theta) 5260ccef0f2e41768bc207903d310650--028a521968374f95bfcf201e67d60f17 dd30abe9ebeb4854bc6caee1b67d2f1e 1 0f0b77c6685f4049aca195b80c73f29c RX(phi) 028a521968374f95bfcf201e67d60f17--0f0b77c6685f4049aca195b80c73f29c c3e146f1108e4be585434755d6a51519 RX(phi) 0f0b77c6685f4049aca195b80c73f29c--c3e146f1108e4be585434755d6a51519 9b2baab232d04bfe9d922c32b588ec60 RX(phi + theta) c3e146f1108e4be585434755d6a51519--9b2baab232d04bfe9d922c32b588ec60 c70ad9c5138f4390bfa758f31788bfff 9b2baab232d04bfe9d922c32b588ec60--c70ad9c5138f4390bfa758f31788bfff 0b1c6093849b452282cba668d31618ec c70ad9c5138f4390bfa758f31788bfff--0b1c6093849b452282cba668d31618ec e7e7d1cf04e7480b93f755e9fa311a6c Z 0b1c6093849b452282cba668d31618ec--e7e7d1cf04e7480b93f755e9fa311a6c 84e8ea06458a483c8832c2c67ba82e83 e7e7d1cf04e7480b93f755e9fa311a6c--84e8ea06458a483c8832c2c67ba82e83 c4fe6b6b45594b82b6aaf7270407cc5c d932286dc4c64808a6aa1ff9e602354a RY(2*theta) dd30abe9ebeb4854bc6caee1b67d2f1e--d932286dc4c64808a6aa1ff9e602354a 1bfbefde28d546dbaf25fecd26ae877a 2 25cb3fc90c2f4af2a40ebc8c50bb4329 RY(theta) d932286dc4c64808a6aa1ff9e602354a--25cb3fc90c2f4af2a40ebc8c50bb4329 fc37fffde0cf47949f5b04b876e73fac RY(theta) 25cb3fc90c2f4af2a40ebc8c50bb4329--fc37fffde0cf47949f5b04b876e73fac 171e4c4e194743538e682867edc48ef1 RY(theta**2) fc37fffde0cf47949f5b04b876e73fac--171e4c4e194743538e682867edc48ef1 afcffa770355456286f9d0cb4fa77db9 X 171e4c4e194743538e682867edc48ef1--afcffa770355456286f9d0cb4fa77db9 afcffa770355456286f9d0cb4fa77db9--c70ad9c5138f4390bfa758f31788bfff 03aaa28f3c5047dfa71bde320ec5ac38 afcffa770355456286f9d0cb4fa77db9--03aaa28f3c5047dfa71bde320ec5ac38 e5306a202fb449a5b43b13cc25f11c43 Z 03aaa28f3c5047dfa71bde320ec5ac38--e5306a202fb449a5b43b13cc25f11c43 e5306a202fb449a5b43b13cc25f11c43--c4fe6b6b45594b82b6aaf7270407cc5c 073c3f26562d4e258993d2acc1601cf4 092076ee82e24e978162e98ad505f149 RZ(cos(phi)) 1bfbefde28d546dbaf25fecd26ae877a--092076ee82e24e978162e98ad505f149 2f617df2993a44caab93e6574724bd41 RZ(phi) 092076ee82e24e978162e98ad505f149--2f617df2993a44caab93e6574724bd41 3659afc7465d4b57ae30aca9255aba3e RZ(phi) 2f617df2993a44caab93e6574724bd41--3659afc7465d4b57ae30aca9255aba3e 5ed549676d2145c5ada9dacdf0723b3a RZ(cos(phi)) 3659afc7465d4b57ae30aca9255aba3e--5ed549676d2145c5ada9dacdf0723b3a 954b54094acd49d8bccad34709e48a63 5ed549676d2145c5ada9dacdf0723b3a--954b54094acd49d8bccad34709e48a63 d8b09e41bddf409b9c84a8ffa0955235 X 954b54094acd49d8bccad34709e48a63--d8b09e41bddf409b9c84a8ffa0955235 d8b09e41bddf409b9c84a8ffa0955235--03aaa28f3c5047dfa71bde320ec5ac38 eb28ade19bd94ee0b3689fb98edaac84 Z d8b09e41bddf409b9c84a8ffa0955235--eb28ade19bd94ee0b3689fb98edaac84 eb28ade19bd94ee0b3689fb98edaac84--073c3f26562d4e258993d2acc1601cf4

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

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.4423+0.0000j, 0.4967+0.0000j, 0.0000-0.4967j, 0.0000-0.5577j],
        [0.5495+0.0000j, 0.4975+0.0000j, 0.0000-0.4975j, 0.0000-0.4505j],
        [0.8138+0.0000j, 0.3893+0.0000j, 0.0000-0.3893j, 0.0000-0.1862j]],
       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 bc9d05ede5944d5bb4b8cb352ace4bcb 0 f611f26851d840bd951bfa6588040a32 RX(theta₀) bc9d05ede5944d5bb4b8cb352ace4bcb--f611f26851d840bd951bfa6588040a32 dd1ecd17790541e5b725b2547d313e87 1 ced308b9b96642c8bfcbafa86a122b11 RY(theta₄) f611f26851d840bd951bfa6588040a32--ced308b9b96642c8bfcbafa86a122b11 16d2bc829fac42c291e5a1d3e8e801af RX(theta₈) ced308b9b96642c8bfcbafa86a122b11--16d2bc829fac42c291e5a1d3e8e801af d6c1d197bc0644bf8d1cf1d54864db56 16d2bc829fac42c291e5a1d3e8e801af--d6c1d197bc0644bf8d1cf1d54864db56 e5cc704b7b354208a6949423bb582c15 d6c1d197bc0644bf8d1cf1d54864db56--e5cc704b7b354208a6949423bb582c15 3536869f52a94d9eb7e1642e28e12908 RX(theta₁₂) e5cc704b7b354208a6949423bb582c15--3536869f52a94d9eb7e1642e28e12908 9664d6fdcf5e4b40b8832355d77cd2bb RY(theta₁₆) 3536869f52a94d9eb7e1642e28e12908--9664d6fdcf5e4b40b8832355d77cd2bb 0c4d50f990d64f5a86f9c8545f4c3547 RX(theta₂₀) 9664d6fdcf5e4b40b8832355d77cd2bb--0c4d50f990d64f5a86f9c8545f4c3547 5d83ae1866d04c3ca98bdb6bd578f01b 0c4d50f990d64f5a86f9c8545f4c3547--5d83ae1866d04c3ca98bdb6bd578f01b f4425bd6ad744b49a377c4c70f3d6aea 5d83ae1866d04c3ca98bdb6bd578f01b--f4425bd6ad744b49a377c4c70f3d6aea 5bda6a75d7094604b54aa9e80745b6d0 f4425bd6ad744b49a377c4c70f3d6aea--5bda6a75d7094604b54aa9e80745b6d0 26fe24de0e3b41deb807a4dbe8609f15 676a87d54adb4834b1c859ecd17ae864 RX(theta₁) dd1ecd17790541e5b725b2547d313e87--676a87d54adb4834b1c859ecd17ae864 440248f7f05340699422031c824e0075 2 82b29df4280046589aac004bf6b15156 RY(theta₅) 676a87d54adb4834b1c859ecd17ae864--82b29df4280046589aac004bf6b15156 2ba20e07e1424b97b207f5edce79d81a RX(theta₉) 82b29df4280046589aac004bf6b15156--2ba20e07e1424b97b207f5edce79d81a 74ec352be1ae4bfa8558cc438d39ad4c X 2ba20e07e1424b97b207f5edce79d81a--74ec352be1ae4bfa8558cc438d39ad4c 74ec352be1ae4bfa8558cc438d39ad4c--d6c1d197bc0644bf8d1cf1d54864db56 da9efa008afd43b9b15b1ba2db893ca5 74ec352be1ae4bfa8558cc438d39ad4c--da9efa008afd43b9b15b1ba2db893ca5 3c035f4e7dda40ab8e961a6bacc3c914 RX(theta₁₃) da9efa008afd43b9b15b1ba2db893ca5--3c035f4e7dda40ab8e961a6bacc3c914 270685efd93a4365a6dbdb7b65a2ded4 RY(theta₁₇) 3c035f4e7dda40ab8e961a6bacc3c914--270685efd93a4365a6dbdb7b65a2ded4 4b742461b32b4a5994e932152704cacb RX(theta₂₁) 270685efd93a4365a6dbdb7b65a2ded4--4b742461b32b4a5994e932152704cacb 15c5ecac19cf49a2a6a90e66a43e952d X 4b742461b32b4a5994e932152704cacb--15c5ecac19cf49a2a6a90e66a43e952d 15c5ecac19cf49a2a6a90e66a43e952d--5d83ae1866d04c3ca98bdb6bd578f01b 4458120e5ecd49318de01d72d3c5fa9b 15c5ecac19cf49a2a6a90e66a43e952d--4458120e5ecd49318de01d72d3c5fa9b 4458120e5ecd49318de01d72d3c5fa9b--26fe24de0e3b41deb807a4dbe8609f15 f8152ab8beed4193895cd05f5a4c0d98 c19411479d72488e9e277421cb5afd18 RX(theta₂) 440248f7f05340699422031c824e0075--c19411479d72488e9e277421cb5afd18 3db4524c454c40bba6725c777e24ed2a 3 1f120487c2c841999ce2a1998ce8bd92 RY(theta₆) c19411479d72488e9e277421cb5afd18--1f120487c2c841999ce2a1998ce8bd92 59a22a6d2401453ba8399d0f1c1ee4ff RX(theta₁₀) 1f120487c2c841999ce2a1998ce8bd92--59a22a6d2401453ba8399d0f1c1ee4ff 69c77b87c9294937b01d8bb7008a1be8 59a22a6d2401453ba8399d0f1c1ee4ff--69c77b87c9294937b01d8bb7008a1be8 5c4b9eb88eb24352ab44e2f11234f939 X 69c77b87c9294937b01d8bb7008a1be8--5c4b9eb88eb24352ab44e2f11234f939 5c4b9eb88eb24352ab44e2f11234f939--da9efa008afd43b9b15b1ba2db893ca5 3e8c3eb223dd405397fc34cd5ed05e0f RX(theta₁₄) 5c4b9eb88eb24352ab44e2f11234f939--3e8c3eb223dd405397fc34cd5ed05e0f 8f63b33347254118a63e4a7c0bb48d63 RY(theta₁₈) 3e8c3eb223dd405397fc34cd5ed05e0f--8f63b33347254118a63e4a7c0bb48d63 df032503be7a415887562d62df5863c8 RX(theta₂₂) 8f63b33347254118a63e4a7c0bb48d63--df032503be7a415887562d62df5863c8 feccd62fcc4f4b5993d825df02d575dd df032503be7a415887562d62df5863c8--feccd62fcc4f4b5993d825df02d575dd 5d8c8525a7634aada39ea0d2dade9e22 X feccd62fcc4f4b5993d825df02d575dd--5d8c8525a7634aada39ea0d2dade9e22 5d8c8525a7634aada39ea0d2dade9e22--4458120e5ecd49318de01d72d3c5fa9b 5d8c8525a7634aada39ea0d2dade9e22--f8152ab8beed4193895cd05f5a4c0d98 8a0429d440064676bcf94f160f6e23ed d5ef10a1815b40a1a1984bcd15748f85 RX(theta₃) 3db4524c454c40bba6725c777e24ed2a--d5ef10a1815b40a1a1984bcd15748f85 e76e4a972f964c86ab216e03a4815c9a RY(theta₇) d5ef10a1815b40a1a1984bcd15748f85--e76e4a972f964c86ab216e03a4815c9a d47e78ea540a496aad41e9f8f9cdc948 RX(theta₁₁) e76e4a972f964c86ab216e03a4815c9a--d47e78ea540a496aad41e9f8f9cdc948 60c6fdbc012b4833827f262e40ef0433 X d47e78ea540a496aad41e9f8f9cdc948--60c6fdbc012b4833827f262e40ef0433 60c6fdbc012b4833827f262e40ef0433--69c77b87c9294937b01d8bb7008a1be8 188a7155ea634283afeef97d822fdef1 60c6fdbc012b4833827f262e40ef0433--188a7155ea634283afeef97d822fdef1 314e70c154f34ff79a030a057f900238 RX(theta₁₅) 188a7155ea634283afeef97d822fdef1--314e70c154f34ff79a030a057f900238 0c28a88a228d4f42a11f1f481c31baad RY(theta₁₉) 314e70c154f34ff79a030a057f900238--0c28a88a228d4f42a11f1f481c31baad 6cbeac8f30114035a5a0b48558eb79fe RX(theta₂₃) 0c28a88a228d4f42a11f1f481c31baad--6cbeac8f30114035a5a0b48558eb79fe 886b572e2d8445619857a74d761862a2 X 6cbeac8f30114035a5a0b48558eb79fe--886b572e2d8445619857a74d761862a2 886b572e2d8445619857a74d761862a2--feccd62fcc4f4b5993d825df02d575dd 664ebec1a63a4a9da8681b20596cd577 886b572e2d8445619857a74d761862a2--664ebec1a63a4a9da8681b20596cd577 664ebec1a63a4a9da8681b20596cd577--8a0429d440064676bcf94f160f6e23ed

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_351e4fee9bc544b18aa05f81d4503000 HEA cluster_695d56cf12fa4bd0acc887c1fa4dd90a HEA a37f9183ee354e4aa0f95344c4d98cdd 0 2a06e94656ff44b8922384c285a633f1 RX(theta₀) a37f9183ee354e4aa0f95344c4d98cdd--2a06e94656ff44b8922384c285a633f1 fc2d7b6ccba649a791490369888670aa 1 6b8b790976464a07a220a27a2bdd1085 RY(theta₄) 2a06e94656ff44b8922384c285a633f1--6b8b790976464a07a220a27a2bdd1085 bb1e4e61b1ab4b7c87da9720dd5a2067 RX(theta₈) 6b8b790976464a07a220a27a2bdd1085--bb1e4e61b1ab4b7c87da9720dd5a2067 81150532f15d4601b00cb059ed56068c bb1e4e61b1ab4b7c87da9720dd5a2067--81150532f15d4601b00cb059ed56068c 96b60e002d2c460f836960337274c2dc 81150532f15d4601b00cb059ed56068c--96b60e002d2c460f836960337274c2dc 2f8cb79431054e26835e867376e38acd RX(theta₁₂) 96b60e002d2c460f836960337274c2dc--2f8cb79431054e26835e867376e38acd 0bc6e3e1353c45c48c74d745aa9228f8 RY(theta₁₆) 2f8cb79431054e26835e867376e38acd--0bc6e3e1353c45c48c74d745aa9228f8 dffa1e5375504e158dff26c284705b24 RX(theta₂₀) 0bc6e3e1353c45c48c74d745aa9228f8--dffa1e5375504e158dff26c284705b24 9efa4189db724b02a88e163e59c4e980 dffa1e5375504e158dff26c284705b24--9efa4189db724b02a88e163e59c4e980 c9a213d1dcff44d58122f41da9d95942 9efa4189db724b02a88e163e59c4e980--c9a213d1dcff44d58122f41da9d95942 e91f73abfea64d868a38e1f2fab0c8cc RX(theta₀) c9a213d1dcff44d58122f41da9d95942--e91f73abfea64d868a38e1f2fab0c8cc eeb9da96f75b431caaab00c17e992a9b RY(theta₄) e91f73abfea64d868a38e1f2fab0c8cc--eeb9da96f75b431caaab00c17e992a9b f5bdadccc2974b5bba2763fb194c6de4 RX(theta₈) eeb9da96f75b431caaab00c17e992a9b--f5bdadccc2974b5bba2763fb194c6de4 fa84ba0ccfe4490eba5d0fdd4fdce86c f5bdadccc2974b5bba2763fb194c6de4--fa84ba0ccfe4490eba5d0fdd4fdce86c 0f037f28f294436f88c68fae86a177a2 fa84ba0ccfe4490eba5d0fdd4fdce86c--0f037f28f294436f88c68fae86a177a2 ee08dee4ab984ee2a8803466ce93d006 RX(theta₁₂) 0f037f28f294436f88c68fae86a177a2--ee08dee4ab984ee2a8803466ce93d006 1340e9fdd26043eeabab842dbdfd40d9 RY(theta₁₆) ee08dee4ab984ee2a8803466ce93d006--1340e9fdd26043eeabab842dbdfd40d9 a93892a5e6ee4516b41391f4f58f17ea RX(theta₂₀) 1340e9fdd26043eeabab842dbdfd40d9--a93892a5e6ee4516b41391f4f58f17ea 1e5d2a50d85b4d7cb8e82078dac530c0 a93892a5e6ee4516b41391f4f58f17ea--1e5d2a50d85b4d7cb8e82078dac530c0 27678222331d40858d36d7f8a18aa6f4 1e5d2a50d85b4d7cb8e82078dac530c0--27678222331d40858d36d7f8a18aa6f4 07accd54cf5240b98bc6c93e5cd0a1d2 27678222331d40858d36d7f8a18aa6f4--07accd54cf5240b98bc6c93e5cd0a1d2 281734dbfeb74ba69a6bb5d974da3db4 5de109aa4cdb48daba9a8703d5f6d11d RX(theta₁) fc2d7b6ccba649a791490369888670aa--5de109aa4cdb48daba9a8703d5f6d11d 6eb5d418c04b4b1b8390d6c33468e8d6 2 b7e6d55b084d4503ad93756dcafab395 RY(theta₅) 5de109aa4cdb48daba9a8703d5f6d11d--b7e6d55b084d4503ad93756dcafab395 46b88b0e56e44e719ec36b5e89bba40e RX(theta₉) b7e6d55b084d4503ad93756dcafab395--46b88b0e56e44e719ec36b5e89bba40e 621f875368ae419aa1d4e23af526f389 X 46b88b0e56e44e719ec36b5e89bba40e--621f875368ae419aa1d4e23af526f389 621f875368ae419aa1d4e23af526f389--81150532f15d4601b00cb059ed56068c 5fbbf11e6da64695a20c43533ff39987 621f875368ae419aa1d4e23af526f389--5fbbf11e6da64695a20c43533ff39987 06152d3c8ac34c939d4dae6d1a6e9ce5 RX(theta₁₃) 5fbbf11e6da64695a20c43533ff39987--06152d3c8ac34c939d4dae6d1a6e9ce5 06e9d5ec067b4d47867a7513db07035e RY(theta₁₇) 06152d3c8ac34c939d4dae6d1a6e9ce5--06e9d5ec067b4d47867a7513db07035e 41e6955f75b94d2d9f2152d7c079c689 RX(theta₂₁) 06e9d5ec067b4d47867a7513db07035e--41e6955f75b94d2d9f2152d7c079c689 25e5c77859324633b79d279406e13eaf X 41e6955f75b94d2d9f2152d7c079c689--25e5c77859324633b79d279406e13eaf 25e5c77859324633b79d279406e13eaf--9efa4189db724b02a88e163e59c4e980 750b4b0d82884339a9698b60d6ba6fc1 25e5c77859324633b79d279406e13eaf--750b4b0d82884339a9698b60d6ba6fc1 f0005f6209484ba3a9750494be1f55e5 RX(theta₁) 750b4b0d82884339a9698b60d6ba6fc1--f0005f6209484ba3a9750494be1f55e5 2f3546da27fd406d863647c4c81a6d38 RY(theta₅) f0005f6209484ba3a9750494be1f55e5--2f3546da27fd406d863647c4c81a6d38 a101bbb76c6d4442be5a40f4b2f85f12 RX(theta₉) 2f3546da27fd406d863647c4c81a6d38--a101bbb76c6d4442be5a40f4b2f85f12 57b3eba755c6414a95f68c22c43ef113 X a101bbb76c6d4442be5a40f4b2f85f12--57b3eba755c6414a95f68c22c43ef113 57b3eba755c6414a95f68c22c43ef113--fa84ba0ccfe4490eba5d0fdd4fdce86c c5a28b25659f46968bec426185ad9d20 57b3eba755c6414a95f68c22c43ef113--c5a28b25659f46968bec426185ad9d20 a87017ad175843cdaf54bfaa9c01b29e RX(theta₁₃) c5a28b25659f46968bec426185ad9d20--a87017ad175843cdaf54bfaa9c01b29e d18cc3260d9a40178032862158293716 RY(theta₁₇) a87017ad175843cdaf54bfaa9c01b29e--d18cc3260d9a40178032862158293716 7ee356e0b8de465c9a622b20322cb85b RX(theta₂₁) d18cc3260d9a40178032862158293716--7ee356e0b8de465c9a622b20322cb85b 6dbb0641103c4d36ae1b2b71696016ad X 7ee356e0b8de465c9a622b20322cb85b--6dbb0641103c4d36ae1b2b71696016ad 6dbb0641103c4d36ae1b2b71696016ad--1e5d2a50d85b4d7cb8e82078dac530c0 7f84aa4563b245478e50142542fdccd6 6dbb0641103c4d36ae1b2b71696016ad--7f84aa4563b245478e50142542fdccd6 7f84aa4563b245478e50142542fdccd6--281734dbfeb74ba69a6bb5d974da3db4 f22ea65eec994ef3ae10791baad19738 bfc8d7c784d346dabc9feae2bdb23ed5 RX(theta₂) 6eb5d418c04b4b1b8390d6c33468e8d6--bfc8d7c784d346dabc9feae2bdb23ed5 630f6d88d00e449784050f8223d19a1b 3 c62e98d0abb34fcda4b0890b5c0ffea3 RY(theta₆) bfc8d7c784d346dabc9feae2bdb23ed5--c62e98d0abb34fcda4b0890b5c0ffea3 8394bbd7081843c5813d066cf6decc53 RX(theta₁₀) c62e98d0abb34fcda4b0890b5c0ffea3--8394bbd7081843c5813d066cf6decc53 d731dc523d1c473d9d75da84db20c381 8394bbd7081843c5813d066cf6decc53--d731dc523d1c473d9d75da84db20c381 7182c183dc6940638392fd3f0fc6a964 X d731dc523d1c473d9d75da84db20c381--7182c183dc6940638392fd3f0fc6a964 7182c183dc6940638392fd3f0fc6a964--5fbbf11e6da64695a20c43533ff39987 43e5c85ee1e74ec789b543a096461c16 RX(theta₁₄) 7182c183dc6940638392fd3f0fc6a964--43e5c85ee1e74ec789b543a096461c16 cfa6beeecd254d46a08d1cc934e4d71f RY(theta₁₈) 43e5c85ee1e74ec789b543a096461c16--cfa6beeecd254d46a08d1cc934e4d71f 94325b3ccc124369909e9d733de9dff0 RX(theta₂₂) cfa6beeecd254d46a08d1cc934e4d71f--94325b3ccc124369909e9d733de9dff0 3b157041271e46978fc6f789e43160a4 94325b3ccc124369909e9d733de9dff0--3b157041271e46978fc6f789e43160a4 75af1796f1534ca88d570ca75561783f X 3b157041271e46978fc6f789e43160a4--75af1796f1534ca88d570ca75561783f 75af1796f1534ca88d570ca75561783f--750b4b0d82884339a9698b60d6ba6fc1 34ce622679ca448292d5017398202d4e RX(theta₂) 75af1796f1534ca88d570ca75561783f--34ce622679ca448292d5017398202d4e d093ac017935479b945e8d677f613d49 RY(theta₆) 34ce622679ca448292d5017398202d4e--d093ac017935479b945e8d677f613d49 109f0bee41c64b02ac8d5affe3c367ac RX(theta₁₀) d093ac017935479b945e8d677f613d49--109f0bee41c64b02ac8d5affe3c367ac 333a4deb4b164374915a28d053cde912 109f0bee41c64b02ac8d5affe3c367ac--333a4deb4b164374915a28d053cde912 922beee076954713bacff6b45a19fdc8 X 333a4deb4b164374915a28d053cde912--922beee076954713bacff6b45a19fdc8 922beee076954713bacff6b45a19fdc8--c5a28b25659f46968bec426185ad9d20 3eb468f85a154c59a6ecf73f1c6db0d4 RX(theta₁₄) 922beee076954713bacff6b45a19fdc8--3eb468f85a154c59a6ecf73f1c6db0d4 3edb333c544f4a88bc0824f842cae909 RY(theta₁₈) 3eb468f85a154c59a6ecf73f1c6db0d4--3edb333c544f4a88bc0824f842cae909 c7ef62e62e3a457d9be1ba5053e836c9 RX(theta₂₂) 3edb333c544f4a88bc0824f842cae909--c7ef62e62e3a457d9be1ba5053e836c9 eca3ec5cba5f4d2db67c3798522b5ef7 c7ef62e62e3a457d9be1ba5053e836c9--eca3ec5cba5f4d2db67c3798522b5ef7 1f0f8ca0b276449e8512926a8c4b1aa0 X eca3ec5cba5f4d2db67c3798522b5ef7--1f0f8ca0b276449e8512926a8c4b1aa0 1f0f8ca0b276449e8512926a8c4b1aa0--7f84aa4563b245478e50142542fdccd6 1f0f8ca0b276449e8512926a8c4b1aa0--f22ea65eec994ef3ae10791baad19738 7a131d691b8542d1b162b592a36ddaac 13344361d8494ae0978b2064ea608147 RX(theta₃) 630f6d88d00e449784050f8223d19a1b--13344361d8494ae0978b2064ea608147 5ff112fcae1a4d799aac98b962d49277 RY(theta₇) 13344361d8494ae0978b2064ea608147--5ff112fcae1a4d799aac98b962d49277 c02f56e4e2774a87847c6dc129545b2e RX(theta₁₁) 5ff112fcae1a4d799aac98b962d49277--c02f56e4e2774a87847c6dc129545b2e 5f077882774b498796b5714ecd06b0b2 X c02f56e4e2774a87847c6dc129545b2e--5f077882774b498796b5714ecd06b0b2 5f077882774b498796b5714ecd06b0b2--d731dc523d1c473d9d75da84db20c381 0c87a90d77b548e9bd04c98f51beb975 5f077882774b498796b5714ecd06b0b2--0c87a90d77b548e9bd04c98f51beb975 4e1b590b22cf4a3a8ebde687eadc61be RX(theta₁₅) 0c87a90d77b548e9bd04c98f51beb975--4e1b590b22cf4a3a8ebde687eadc61be 38d0b0ed1c0f4823ac78ba80ae526882 RY(theta₁₉) 4e1b590b22cf4a3a8ebde687eadc61be--38d0b0ed1c0f4823ac78ba80ae526882 510370e8e34d41c8aa9f7c650531ee82 RX(theta₂₃) 38d0b0ed1c0f4823ac78ba80ae526882--510370e8e34d41c8aa9f7c650531ee82 9c2ab9b39ac243fba4e0c9aedbb36787 X 510370e8e34d41c8aa9f7c650531ee82--9c2ab9b39ac243fba4e0c9aedbb36787 9c2ab9b39ac243fba4e0c9aedbb36787--3b157041271e46978fc6f789e43160a4 bd5a153ace76466d902b945bda98c740 9c2ab9b39ac243fba4e0c9aedbb36787--bd5a153ace76466d902b945bda98c740 af57d5b49c004ec594ee4dd87c8373e3 RX(theta₃) bd5a153ace76466d902b945bda98c740--af57d5b49c004ec594ee4dd87c8373e3 84898892225b462595eacc23422bda3f RY(theta₇) af57d5b49c004ec594ee4dd87c8373e3--84898892225b462595eacc23422bda3f a97d4b0b47714f3bac4b0743cfc7a46b RX(theta₁₁) 84898892225b462595eacc23422bda3f--a97d4b0b47714f3bac4b0743cfc7a46b 270112b5990d460aafea4ca2973d7a8c X a97d4b0b47714f3bac4b0743cfc7a46b--270112b5990d460aafea4ca2973d7a8c 270112b5990d460aafea4ca2973d7a8c--333a4deb4b164374915a28d053cde912 f9c9383e1b5f479891d37cfa39427a6c 270112b5990d460aafea4ca2973d7a8c--f9c9383e1b5f479891d37cfa39427a6c 34b426677c43420eb7dbfa0ceb8dabb3 RX(theta₁₅) f9c9383e1b5f479891d37cfa39427a6c--34b426677c43420eb7dbfa0ceb8dabb3 3f49070113484dd1b10536cff9baba11 RY(theta₁₉) 34b426677c43420eb7dbfa0ceb8dabb3--3f49070113484dd1b10536cff9baba11 d8aa8f0cd5d647749b26e67aad48eba1 RX(theta₂₃) 3f49070113484dd1b10536cff9baba11--d8aa8f0cd5d647749b26e67aad48eba1 d4e925661db5495ab0293f7bec6080ad X d8aa8f0cd5d647749b26e67aad48eba1--d4e925661db5495ab0293f7bec6080ad d4e925661db5495ab0293f7bec6080ad--eca3ec5cba5f4d2db67c3798522b5ef7 6dd39e92e52440a3956e0fc7b315fe67 d4e925661db5495ab0293f7bec6080ad--6dd39e92e52440a3956e0fc7b315fe67 6dd39e92e52440a3956e0fc7b315fe67--7a131d691b8542d1b162b592a36ddaac

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_48ae310aa7bc4eaa9d2d4c8a8442d9ed HEA cluster_3c5ce23f0aa047bbbaae2996a0a6d27b HEA 480f8151d41b4f98a527cbdb80151e9e 0 e66ae45428c94109bee0820c47c1e14e RX(p1₀) 480f8151d41b4f98a527cbdb80151e9e--e66ae45428c94109bee0820c47c1e14e 3bc58a02e4f143c0a64ded157cc7273c 1 a63ea47e46f64923bc0a457eb5338767 RY(p1₄) e66ae45428c94109bee0820c47c1e14e--a63ea47e46f64923bc0a457eb5338767 8bb23a31695441139c0dd7ccfd0e781a RX(p1₈) a63ea47e46f64923bc0a457eb5338767--8bb23a31695441139c0dd7ccfd0e781a 3bb6aa31b81048178c374e7e909a4f43 8bb23a31695441139c0dd7ccfd0e781a--3bb6aa31b81048178c374e7e909a4f43 162d1e5036b546ec95ec7f0cd91630fc 3bb6aa31b81048178c374e7e909a4f43--162d1e5036b546ec95ec7f0cd91630fc f5001a6755df47da9cb6916595d99d7b RX(p1₁₂) 162d1e5036b546ec95ec7f0cd91630fc--f5001a6755df47da9cb6916595d99d7b c7b2ba850a1f4ffa968d90a6bd6da81a RY(p1₁₆) f5001a6755df47da9cb6916595d99d7b--c7b2ba850a1f4ffa968d90a6bd6da81a fdca7d209cc44f32877f7e26cee4a094 RX(p1₂₀) c7b2ba850a1f4ffa968d90a6bd6da81a--fdca7d209cc44f32877f7e26cee4a094 c414b801815a4da181ed8c20fa905cfe fdca7d209cc44f32877f7e26cee4a094--c414b801815a4da181ed8c20fa905cfe 4197335972964742b4db07ea7921d0b1 c414b801815a4da181ed8c20fa905cfe--4197335972964742b4db07ea7921d0b1 9396d2d7f52047a0827b99fea70dc53e RX(p2₀) 4197335972964742b4db07ea7921d0b1--9396d2d7f52047a0827b99fea70dc53e 62b9af498d3b42d09edc4aa3e0a11ce6 RY(p2₄) 9396d2d7f52047a0827b99fea70dc53e--62b9af498d3b42d09edc4aa3e0a11ce6 a576d84f4d7c4a91bb35f1b570cd5ad4 RX(p2₈) 62b9af498d3b42d09edc4aa3e0a11ce6--a576d84f4d7c4a91bb35f1b570cd5ad4 c6d33fdbc942450695c34d72f11036d5 a576d84f4d7c4a91bb35f1b570cd5ad4--c6d33fdbc942450695c34d72f11036d5 04b5f4ee85e84c0db3ef3b38836be49a c6d33fdbc942450695c34d72f11036d5--04b5f4ee85e84c0db3ef3b38836be49a d235f365019f431e82cf87ca7c1ea189 RX(p2₁₂) 04b5f4ee85e84c0db3ef3b38836be49a--d235f365019f431e82cf87ca7c1ea189 d29e39e2328247c08cef5d8ffea2f278 RY(p2₁₆) d235f365019f431e82cf87ca7c1ea189--d29e39e2328247c08cef5d8ffea2f278 a5dc2f673b9f4beaa48f1e491454b7aa RX(p2₂₀) d29e39e2328247c08cef5d8ffea2f278--a5dc2f673b9f4beaa48f1e491454b7aa ac2388d1fc884d10bb60227917932af4 a5dc2f673b9f4beaa48f1e491454b7aa--ac2388d1fc884d10bb60227917932af4 4184fc7f54fd4511aa988e4f94786bb4 ac2388d1fc884d10bb60227917932af4--4184fc7f54fd4511aa988e4f94786bb4 900f137aecad4e94887e2d0727288a77 4184fc7f54fd4511aa988e4f94786bb4--900f137aecad4e94887e2d0727288a77 63858d1909a2476e9616331b11d19226 0fa76547f1dd4671a3467f2c20319779 RX(p1₁) 3bc58a02e4f143c0a64ded157cc7273c--0fa76547f1dd4671a3467f2c20319779 71d114e04dba4635a638e12a42733edb 2 4529777449584198be9f6739466efdee RY(p1₅) 0fa76547f1dd4671a3467f2c20319779--4529777449584198be9f6739466efdee 9260f9bdd2a640cbbf49e1df37bbc4e7 RX(p1₉) 4529777449584198be9f6739466efdee--9260f9bdd2a640cbbf49e1df37bbc4e7 19db2bfd688446d5936497c0e424ebc3 X 9260f9bdd2a640cbbf49e1df37bbc4e7--19db2bfd688446d5936497c0e424ebc3 19db2bfd688446d5936497c0e424ebc3--3bb6aa31b81048178c374e7e909a4f43 e5cf937e770a4f4fbe0343043341c0b3 19db2bfd688446d5936497c0e424ebc3--e5cf937e770a4f4fbe0343043341c0b3 ebe088f1d7844199adce6ad900d60ed3 RX(p1₁₃) e5cf937e770a4f4fbe0343043341c0b3--ebe088f1d7844199adce6ad900d60ed3 af97495732bf4215b44da686a8835c91 RY(p1₁₇) ebe088f1d7844199adce6ad900d60ed3--af97495732bf4215b44da686a8835c91 02a0ec6062344a3aa8d5d3b62b6a00bc RX(p1₂₁) af97495732bf4215b44da686a8835c91--02a0ec6062344a3aa8d5d3b62b6a00bc c098019ffcb34b7f920a02e809d6e194 X 02a0ec6062344a3aa8d5d3b62b6a00bc--c098019ffcb34b7f920a02e809d6e194 c098019ffcb34b7f920a02e809d6e194--c414b801815a4da181ed8c20fa905cfe 02581279e4c14ba28ebda89be6b7c428 c098019ffcb34b7f920a02e809d6e194--02581279e4c14ba28ebda89be6b7c428 509168da1f0945aba2e40eeaa7a53c45 RX(p2₁) 02581279e4c14ba28ebda89be6b7c428--509168da1f0945aba2e40eeaa7a53c45 fdbfaf3732c24c9495d09926c3b75a25 RY(p2₅) 509168da1f0945aba2e40eeaa7a53c45--fdbfaf3732c24c9495d09926c3b75a25 edd06c6bc160455f90dcb6fbd81b1633 RX(p2₉) fdbfaf3732c24c9495d09926c3b75a25--edd06c6bc160455f90dcb6fbd81b1633 472d63b5bd6845bda09f6e5f402a0738 X edd06c6bc160455f90dcb6fbd81b1633--472d63b5bd6845bda09f6e5f402a0738 472d63b5bd6845bda09f6e5f402a0738--c6d33fdbc942450695c34d72f11036d5 d5148dc65ce24249b43c1792c2d50b6b 472d63b5bd6845bda09f6e5f402a0738--d5148dc65ce24249b43c1792c2d50b6b 086e365c7bd6440ab9f059ff6e34c484 RX(p2₁₃) d5148dc65ce24249b43c1792c2d50b6b--086e365c7bd6440ab9f059ff6e34c484 12cd6cc315ee4ee080f1ec17e1ad89ee RY(p2₁₇) 086e365c7bd6440ab9f059ff6e34c484--12cd6cc315ee4ee080f1ec17e1ad89ee 7bd881df6d8e4e38afd72e3fbe04f596 RX(p2₂₁) 12cd6cc315ee4ee080f1ec17e1ad89ee--7bd881df6d8e4e38afd72e3fbe04f596 79f6da2b8e0e4c3aa5bb72f0e9bd8f2a X 7bd881df6d8e4e38afd72e3fbe04f596--79f6da2b8e0e4c3aa5bb72f0e9bd8f2a 79f6da2b8e0e4c3aa5bb72f0e9bd8f2a--ac2388d1fc884d10bb60227917932af4 0d68907e78754b81905c36bc1578fa56 79f6da2b8e0e4c3aa5bb72f0e9bd8f2a--0d68907e78754b81905c36bc1578fa56 0d68907e78754b81905c36bc1578fa56--63858d1909a2476e9616331b11d19226 f1515e0b5d0148c69fb01e4b8c39455d 1c21f829a4684133a25ef92d761bc789 RX(p1₂) 71d114e04dba4635a638e12a42733edb--1c21f829a4684133a25ef92d761bc789 2effa892e9f0441aad00327df823e56a 3 fd51502a22f5460d8fb60f7fa95f0d64 RY(p1₆) 1c21f829a4684133a25ef92d761bc789--fd51502a22f5460d8fb60f7fa95f0d64 46c826dca1e948a08fae4163ae1c6ea9 RX(p1₁₀) fd51502a22f5460d8fb60f7fa95f0d64--46c826dca1e948a08fae4163ae1c6ea9 a839ff0a8b2941e9968b69c47980fa65 46c826dca1e948a08fae4163ae1c6ea9--a839ff0a8b2941e9968b69c47980fa65 79d5f574cee245de9cdc38eda6db55be X a839ff0a8b2941e9968b69c47980fa65--79d5f574cee245de9cdc38eda6db55be 79d5f574cee245de9cdc38eda6db55be--e5cf937e770a4f4fbe0343043341c0b3 b33b13a5bac844a3bdc5a17a53c43925 RX(p1₁₄) 79d5f574cee245de9cdc38eda6db55be--b33b13a5bac844a3bdc5a17a53c43925 2f4bb22aab1b4a9eb9af5f0077bbd5b6 RY(p1₁₈) b33b13a5bac844a3bdc5a17a53c43925--2f4bb22aab1b4a9eb9af5f0077bbd5b6 d97e67e33b0f4e5c969b03587b1697a1 RX(p1₂₂) 2f4bb22aab1b4a9eb9af5f0077bbd5b6--d97e67e33b0f4e5c969b03587b1697a1 cd4b35deb0d44f8abddf7abea51c5024 d97e67e33b0f4e5c969b03587b1697a1--cd4b35deb0d44f8abddf7abea51c5024 03902a0a73104828a67bf1da026e998a X cd4b35deb0d44f8abddf7abea51c5024--03902a0a73104828a67bf1da026e998a 03902a0a73104828a67bf1da026e998a--02581279e4c14ba28ebda89be6b7c428 7f29db652966457494c9dcccdb6f2a3c RX(p2₂) 03902a0a73104828a67bf1da026e998a--7f29db652966457494c9dcccdb6f2a3c b5cba69ed6c247a4a889c38e9e45f29b RY(p2₆) 7f29db652966457494c9dcccdb6f2a3c--b5cba69ed6c247a4a889c38e9e45f29b 516097304ae3422aba82ace55c904d0d RX(p2₁₀) b5cba69ed6c247a4a889c38e9e45f29b--516097304ae3422aba82ace55c904d0d b5e6fdc3c1894bcf9d5422c99848de05 516097304ae3422aba82ace55c904d0d--b5e6fdc3c1894bcf9d5422c99848de05 2c30fc83555a4d3081e23cb7bada6d89 X b5e6fdc3c1894bcf9d5422c99848de05--2c30fc83555a4d3081e23cb7bada6d89 2c30fc83555a4d3081e23cb7bada6d89--d5148dc65ce24249b43c1792c2d50b6b 391586b7785b44919d9968bed4e245bd RX(p2₁₄) 2c30fc83555a4d3081e23cb7bada6d89--391586b7785b44919d9968bed4e245bd 8b960dfabb61427087d6356476a5ec2f RY(p2₁₈) 391586b7785b44919d9968bed4e245bd--8b960dfabb61427087d6356476a5ec2f f9c53c5c9d83415493cdd38f9e12a9c8 RX(p2₂₂) 8b960dfabb61427087d6356476a5ec2f--f9c53c5c9d83415493cdd38f9e12a9c8 498d36d9b0064cbb8a927eed4731458a f9c53c5c9d83415493cdd38f9e12a9c8--498d36d9b0064cbb8a927eed4731458a cf97a85fd3244d019e15b9390919481d X 498d36d9b0064cbb8a927eed4731458a--cf97a85fd3244d019e15b9390919481d cf97a85fd3244d019e15b9390919481d--0d68907e78754b81905c36bc1578fa56 cf97a85fd3244d019e15b9390919481d--f1515e0b5d0148c69fb01e4b8c39455d 92343b8cbc6e45fe823d78457d21c594 f496840267de4a319100ee6c12dc5adb RX(p1₃) 2effa892e9f0441aad00327df823e56a--f496840267de4a319100ee6c12dc5adb d73a8c989ebb4680bbb6d44d4d091302 RY(p1₇) f496840267de4a319100ee6c12dc5adb--d73a8c989ebb4680bbb6d44d4d091302 bb0a5429ac85477a859088e66ce31146 RX(p1₁₁) d73a8c989ebb4680bbb6d44d4d091302--bb0a5429ac85477a859088e66ce31146 53656acd575847e78002199345e7f014 X bb0a5429ac85477a859088e66ce31146--53656acd575847e78002199345e7f014 53656acd575847e78002199345e7f014--a839ff0a8b2941e9968b69c47980fa65 fc3c0378d248479db91f135f9e5e0759 53656acd575847e78002199345e7f014--fc3c0378d248479db91f135f9e5e0759 7705962ed73747a99f9e7f3fcaac0b14 RX(p1₁₅) fc3c0378d248479db91f135f9e5e0759--7705962ed73747a99f9e7f3fcaac0b14 f4f94792f1bf4824b72724c3c56408e0 RY(p1₁₉) 7705962ed73747a99f9e7f3fcaac0b14--f4f94792f1bf4824b72724c3c56408e0 20a75ac1a5324955bca66b97a517c72d RX(p1₂₃) f4f94792f1bf4824b72724c3c56408e0--20a75ac1a5324955bca66b97a517c72d a8b17402c0b24640930f2f3d9ba6835c X 20a75ac1a5324955bca66b97a517c72d--a8b17402c0b24640930f2f3d9ba6835c a8b17402c0b24640930f2f3d9ba6835c--cd4b35deb0d44f8abddf7abea51c5024 ecc55adfa5054102b637baf15f860f9c a8b17402c0b24640930f2f3d9ba6835c--ecc55adfa5054102b637baf15f860f9c c1c7704457ec4b5ab70a5ea927cd669d RX(p2₃) ecc55adfa5054102b637baf15f860f9c--c1c7704457ec4b5ab70a5ea927cd669d 0aca44ca95b94d0aa3d2a8cb5daf33d9 RY(p2₇) c1c7704457ec4b5ab70a5ea927cd669d--0aca44ca95b94d0aa3d2a8cb5daf33d9 27b33ff5d08a426b887fde851c76c580 RX(p2₁₁) 0aca44ca95b94d0aa3d2a8cb5daf33d9--27b33ff5d08a426b887fde851c76c580 9cb063a179984d218947c6d02e510cc5 X 27b33ff5d08a426b887fde851c76c580--9cb063a179984d218947c6d02e510cc5 9cb063a179984d218947c6d02e510cc5--b5e6fdc3c1894bcf9d5422c99848de05 1c9bb29bc6e542ee8803bb1901b25452 9cb063a179984d218947c6d02e510cc5--1c9bb29bc6e542ee8803bb1901b25452 aa27a91abc0e41a98876b2270d9d6315 RX(p2₁₅) 1c9bb29bc6e542ee8803bb1901b25452--aa27a91abc0e41a98876b2270d9d6315 bf4bb453f591416c9caeac9cb9114217 RY(p2₁₉) aa27a91abc0e41a98876b2270d9d6315--bf4bb453f591416c9caeac9cb9114217 86013838cff6437fa986324521892166 RX(p2₂₃) bf4bb453f591416c9caeac9cb9114217--86013838cff6437fa986324521892166 ad6592c121294b45b9d7efce88c23f15 X 86013838cff6437fa986324521892166--ad6592c121294b45b9d7efce88c23f15 ad6592c121294b45b9d7efce88c23f15--498d36d9b0064cbb8a927eed4731458a 2094bc70ae954cd19c3874647a7bbf7b ad6592c121294b45b9d7efce88c23f15--2094bc70ae954cd19c3874647a7bbf7b 2094bc70ae954cd19c3874647a7bbf7b--92343b8cbc6e45fe823d78457d21c594

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.6215])), ('theta_0', tensor([0.2697])), ('theta_1', tensor([0.6950])), ('theta_10', tensor([0.3464])), ('theta_11', tensor([0.9241])), ('theta_12', tensor([0.7898])), ('theta_13', tensor([0.9776])), ('theta_14', tensor([0.7308])), ('theta_15', tensor([0.7334])), ('theta_16', tensor([0.7720])), ('theta_17', tensor([0.0300])), ('theta_18', tensor([0.1428])), ('theta_19', tensor([0.2618])), ('theta_2', tensor([0.9746])), ('theta_20', tensor([0.4202])), ('theta_21', tensor([0.7802])), ('theta_22', tensor([0.2414])), ('theta_23', tensor([0.8382])), ('theta_3', tensor([0.5333])), ('theta_4', tensor([0.6383])), ('theta_5', tensor([0.0999])), ('theta_6', tensor([0.3065])), ('theta_7', tensor([0.3257])), ('theta_8', tensor([0.7024])), ('theta_9', tensor([0.8767]))])

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.6205])), ('theta_0', tensor([0.2707])), ('theta_1', tensor([0.6940])), ('theta_10', tensor([0.3474])), ('theta_11', tensor([0.9251])), ('theta_12', tensor([0.7908])), ('theta_13', tensor([0.9786])), ('theta_14', tensor([0.7318])), ('theta_15', tensor([0.7344])), ('theta_16', tensor([0.7730])), ('theta_17', tensor([0.0310])), ('theta_18', tensor([0.1418])), ('theta_19', tensor([0.2628])), ('theta_2', tensor([0.9756])), ('theta_20', tensor([0.4212])), ('theta_21', tensor([0.7812])), ('theta_22', tensor([0.2424])), ('theta_23', tensor([0.8392])), ('theta_3', tensor([0.5343])), ('theta_4', tensor([0.6373])), ('theta_5', tensor([0.1009])), ('theta_6', tensor([0.3075])), ('theta_7', tensor([0.3247])), ('theta_8', tensor([0.7034])), ('theta_9', tensor([0.8757]))])

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