Skip to content

Quantum machine learning constructors

Besides the arbitrary Hamiltonian constructors, Qadence also provides a complete set of program constructors useful for digital-analog quantum machine learning programs.

Feature maps

The feature_map function can easily create several types of data-encoding blocks. The two main types of feature maps use a Fourier basis or a Chebyshev basis.

from qadence import feature_map, BasisSet, chain
from qadence.draw import display

n_qubits = 3

fourier_fm = feature_map(n_qubits, fm_type=BasisSet.FOURIER)

chebyshev_fm = feature_map(n_qubits, fm_type=BasisSet.CHEBYSHEV)

block = chain(fourier_fm, chebyshev_fm)
%3 cluster_350ba08ff9cb463089c276cbc2d4c8e6 Constant Chebyshev FM cluster_4317d85f3dce4f6c9b36a26d74d8b985 Constant Fourier FM cc86284a4bea426aabdf5de6cd533e8a 0 ef508573b7264e78aa728453f10f1129 RX(phi) cc86284a4bea426aabdf5de6cd533e8a--ef508573b7264e78aa728453f10f1129 eb1b2fd7a39a4f32ac2bac9199ea53f0 1 a9374494c8dd407184a06c43664da8c8 RX(acos(phi)) ef508573b7264e78aa728453f10f1129--a9374494c8dd407184a06c43664da8c8 8a91cc231e5c4acf9d06c72ece941754 a9374494c8dd407184a06c43664da8c8--8a91cc231e5c4acf9d06c72ece941754 ea10c05ef25a4b4398eb414251d26a94 d84d20d67c1c429c9ffa81a0e9433dd6 RX(phi) eb1b2fd7a39a4f32ac2bac9199ea53f0--d84d20d67c1c429c9ffa81a0e9433dd6 24090c6c08db4109bd587ccbb0ffee28 2 2690e26fe55e496ea145745e9b7cbf3b RX(acos(phi)) d84d20d67c1c429c9ffa81a0e9433dd6--2690e26fe55e496ea145745e9b7cbf3b 2690e26fe55e496ea145745e9b7cbf3b--ea10c05ef25a4b4398eb414251d26a94 4f33af69c87443079217676e059c9268 0f503aa4068f4b6ba956d49590e28e68 RX(phi) 24090c6c08db4109bd587ccbb0ffee28--0f503aa4068f4b6ba956d49590e28e68 2ccde7a0b48a49bbbe145c016c88f777 RX(acos(phi)) 0f503aa4068f4b6ba956d49590e28e68--2ccde7a0b48a49bbbe145c016c88f777 2ccde7a0b48a49bbbe145c016c88f777--4f33af69c87443079217676e059c9268

A custom encoding function can also be passed with sympy

from sympy import asin, Function

n_qubits = 3

# Using a pre-defined sympy Function
custom_fm_0 = feature_map(n_qubits, fm_type=asin)

# Creating a custom sub-class of Function
class custom_func(Function):
    @classmethod
    def eval(cls, x):
        return asin(x) + x**2

custom_fm_1 = feature_map(n_qubits, fm_type=custom_func)

block = chain(custom_fm_0, custom_fm_1)
%3 cluster_3be9a431962944a3ade4b130944cf9d4 Constant custom_func FM cluster_4417026a7ed84aa18074b3058d00475f Constant asin FM 289772639c594d5c9c0779604667083a 0 bf3ffb347aff42c58d88978b893324e9 RX(asin(phi)) 289772639c594d5c9c0779604667083a--bf3ffb347aff42c58d88978b893324e9 e4295776a9744f4a96ed8262f0a77e95 1 9f0fd3fcc885421297aed634fbda5fc9 RX(phi**2 + asin(phi)) bf3ffb347aff42c58d88978b893324e9--9f0fd3fcc885421297aed634fbda5fc9 bd4818b0b05042738b038a6f66f73515 9f0fd3fcc885421297aed634fbda5fc9--bd4818b0b05042738b038a6f66f73515 046cc74cfd58431895a2bc32db8540f3 ceca6e6e6c454ab8a44849d290371c90 RX(asin(phi)) e4295776a9744f4a96ed8262f0a77e95--ceca6e6e6c454ab8a44849d290371c90 02f48bc507f343dd8d6c5deb42adc914 2 17e63bc87aa44927a497dca0dc86b889 RX(phi**2 + asin(phi)) ceca6e6e6c454ab8a44849d290371c90--17e63bc87aa44927a497dca0dc86b889 17e63bc87aa44927a497dca0dc86b889--046cc74cfd58431895a2bc32db8540f3 0d57c71a7c774812a63d9cd40c72f6af 5786ce3b132841e2960688c1bd8602d5 RX(asin(phi)) 02f48bc507f343dd8d6c5deb42adc914--5786ce3b132841e2960688c1bd8602d5 cb51103389d74a43849265408b6ee6e1 RX(phi**2 + asin(phi)) 5786ce3b132841e2960688c1bd8602d5--cb51103389d74a43849265408b6ee6e1 cb51103389d74a43849265408b6ee6e1--0d57c71a7c774812a63d9cd40c72f6af

Furthermore, the reupload_scaling argument can be used to change the scaling applied to each qubit in the support of the feature map. The default scalings can be chosen from the ReuploadScaling enumeration.

from qadence import ReuploadScaling
from qadence.draw import display

n_qubits = 5

# Default constant value
fm_constant = feature_map(n_qubits, fm_type=BasisSet.FOURIER, reupload_scaling=ReuploadScaling.CONSTANT)

# Linearly increasing scaling
fm_tower = feature_map(n_qubits, fm_type=BasisSet.FOURIER, reupload_scaling=ReuploadScaling.TOWER)

# Exponentially increasing scaling
fm_exp = feature_map(n_qubits, fm_type=BasisSet.FOURIER, reupload_scaling=ReuploadScaling.EXP)

block = chain(fm_constant, fm_tower, fm_exp)
%3 cluster_4d14f74e52934a468df0d9e16e6be9bf Exponential Fourier FM cluster_3714cddb91a44bf897d184bd9d110e72 Constant Fourier FM cluster_01bcad2d2d824a0790edced052aa5617 Tower Fourier FM 1c4e1860d750435fb1555b9586bcd305 0 b5aa4bb4661446dda153df713fd61361 RX(phi) 1c4e1860d750435fb1555b9586bcd305--b5aa4bb4661446dda153df713fd61361 6816ff0a19d346fab289caf1858d9b10 1 6cb89d71fff246c08461394579dbf3eb RX(1.0*phi) b5aa4bb4661446dda153df713fd61361--6cb89d71fff246c08461394579dbf3eb bfbaa83b091e46ef8e35066fbda58cbd RX(1.0*phi) 6cb89d71fff246c08461394579dbf3eb--bfbaa83b091e46ef8e35066fbda58cbd 7157d5fb158f41a6857e1a4053794ed2 bfbaa83b091e46ef8e35066fbda58cbd--7157d5fb158f41a6857e1a4053794ed2 7c0ad40be63847d0aacc56f1b1da860d 45bddfb0b7b84196b7cd55a7364bb26d RX(phi) 6816ff0a19d346fab289caf1858d9b10--45bddfb0b7b84196b7cd55a7364bb26d 4ff2113dd14c49c88cd9fc4012d27af1 2 93ee3018557242ce8d93160aa2b79950 RX(2.0*phi) 45bddfb0b7b84196b7cd55a7364bb26d--93ee3018557242ce8d93160aa2b79950 5e58391508d14d788329d32165816130 RX(2.0*phi) 93ee3018557242ce8d93160aa2b79950--5e58391508d14d788329d32165816130 5e58391508d14d788329d32165816130--7c0ad40be63847d0aacc56f1b1da860d 9bdcd5803c1f45669c48cb7334587315 7e8851f6399f4233885c351a9ff8cdf8 RX(phi) 4ff2113dd14c49c88cd9fc4012d27af1--7e8851f6399f4233885c351a9ff8cdf8 9b223676c9c549b189edd79a43b526ad 3 c53e55209b6b4686ab0f5b591389c7c5 RX(3.0*phi) 7e8851f6399f4233885c351a9ff8cdf8--c53e55209b6b4686ab0f5b591389c7c5 ff12a9e3aa154b2e89e02a219061d4b3 RX(4.0*phi) c53e55209b6b4686ab0f5b591389c7c5--ff12a9e3aa154b2e89e02a219061d4b3 ff12a9e3aa154b2e89e02a219061d4b3--9bdcd5803c1f45669c48cb7334587315 3376d3958d0d447399de576060d65e9c acd0469ab767498492e9501aa051b905 RX(phi) 9b223676c9c549b189edd79a43b526ad--acd0469ab767498492e9501aa051b905 1081566b43364ee3b919c3f060bb9d22 4 f86cc6f1dff945e8944feba003f14185 RX(4.0*phi) acd0469ab767498492e9501aa051b905--f86cc6f1dff945e8944feba003f14185 38b4d746be784775b6993470e81a7b22 RX(8.0*phi) f86cc6f1dff945e8944feba003f14185--38b4d746be784775b6993470e81a7b22 38b4d746be784775b6993470e81a7b22--3376d3958d0d447399de576060d65e9c e94ba18da4b14fd298fb56d4d41781c8 ae770bf9e26c4253b8fde6566f8be951 RX(phi) 1081566b43364ee3b919c3f060bb9d22--ae770bf9e26c4253b8fde6566f8be951 5624b278bae6400faafbd51467e39dcd RX(5.0*phi) ae770bf9e26c4253b8fde6566f8be951--5624b278bae6400faafbd51467e39dcd 103e2eae10f546eead316669461d7cc0 RX(16.0*phi) 5624b278bae6400faafbd51467e39dcd--103e2eae10f546eead316669461d7cc0 103e2eae10f546eead316669461d7cc0--e94ba18da4b14fd298fb56d4d41781c8

A custom scaling can also be defined with a function with an int input and int or float output.

n_qubits = 5

def custom_scaling(i: int) -> int | float:
    """Sqrt(i+1)"""
    return (i+1) ** (0.5)

# Custom scaling function
fm_custom = feature_map(n_qubits, fm_type=BasisSet.CHEBYSHEV, reupload_scaling=custom_scaling)
%3 f4ef25442f384ec5b16ea776fce29c0c 0 d3943e35b30c4aabab6d0243fbf65a45 RX(1.0*acos(phi)) f4ef25442f384ec5b16ea776fce29c0c--d3943e35b30c4aabab6d0243fbf65a45 16854b6976a34d918579f1a961f20869 1 178816f24ab34b7a80ff5c04d148b4ca d3943e35b30c4aabab6d0243fbf65a45--178816f24ab34b7a80ff5c04d148b4ca 53a2233dc1ff41e8970766cdcb5d1ad6 0c4f0d3a9f944c68b25f7f4263d84057 RX(1.414*acos(phi)) 16854b6976a34d918579f1a961f20869--0c4f0d3a9f944c68b25f7f4263d84057 a4226da978394c10a112678417104318 2 0c4f0d3a9f944c68b25f7f4263d84057--53a2233dc1ff41e8970766cdcb5d1ad6 e873cd04ab65489c89fc88a1255367a4 2b011deba47447f0afa069519748f040 RX(1.732*acos(phi)) a4226da978394c10a112678417104318--2b011deba47447f0afa069519748f040 1e52e3c3e577466dadd8727c15f00f42 3 2b011deba47447f0afa069519748f040--e873cd04ab65489c89fc88a1255367a4 862db48e390347838cbbbc2c4d795f53 d1445e1daaeb49f98317016cab30f552 RX(2.0*acos(phi)) 1e52e3c3e577466dadd8727c15f00f42--d1445e1daaeb49f98317016cab30f552 b5873664a9ac467ab8105f36e0518d2d 4 d1445e1daaeb49f98317016cab30f552--862db48e390347838cbbbc2c4d795f53 5a5f9244283b405d9b90b922594de2a1 4b333db643aa4c0fbf561ead5f51eccb RX(2.236*acos(phi)) b5873664a9ac467ab8105f36e0518d2d--4b333db643aa4c0fbf561ead5f51eccb 4b333db643aa4c0fbf561ead5f51eccb--5a5f9244283b405d9b90b922594de2a1

A full description of the remaining arguments can be found in the feature_map API reference. We provide an example below.

from qadence import RY

n_qubits = 5

# Custom scaling function
fm_full = feature_map(
    n_qubits = n_qubits,
    support = tuple(reversed(range(n_qubits))), # Reverse the qubit support to run the scaling from bottom to top
    param = "x", # Change the name of the parameter
    op = RY, # Change the rotation gate between RX, RY, RZ or PHASE
    fm_type = BasisSet.CHEBYSHEV,
    reupload_scaling = ReuploadScaling.EXP,
    feature_range = (-1.0, 2.0), # Range from which the input data comes from
    target_range = (1.0, 3.0), # Range the encoder assumes as the natural range
    multiplier = 5.0 # Extra multiplier, which can also be a Parameter
)
%3 b5632aa308f84128bc847859d440f9f4 0 de458fa4ac68465a9463c160fe4d75fb RY(80.0*acos(0.667*x + 1.667)) b5632aa308f84128bc847859d440f9f4--de458fa4ac68465a9463c160fe4d75fb cc11c85e46d84ebe9bf26ac49a94df50 1 f90117d3b912409c921c5c1b6209ca6d de458fa4ac68465a9463c160fe4d75fb--f90117d3b912409c921c5c1b6209ca6d a4c87b10be9c4d62ac51cf9fcaa72e90 7becff7a4ed947dbb0e56191ca5e3339 RY(40.0*acos(0.667*x + 1.667)) cc11c85e46d84ebe9bf26ac49a94df50--7becff7a4ed947dbb0e56191ca5e3339 974d95ff83b84768a5c87c8a060659ed 2 7becff7a4ed947dbb0e56191ca5e3339--a4c87b10be9c4d62ac51cf9fcaa72e90 e4776c60cd6d4b2a81674aa19a9aa370 83c03faf96ae431bb3a82d3fe12d5ca9 RY(20.0*acos(0.667*x + 1.667)) 974d95ff83b84768a5c87c8a060659ed--83c03faf96ae431bb3a82d3fe12d5ca9 d7459a19aa3b4ea694726989366e90d0 3 83c03faf96ae431bb3a82d3fe12d5ca9--e4776c60cd6d4b2a81674aa19a9aa370 28863647b06e47889c46a343172e85a3 0454ff49b6cc454e935c50b66038b2ce RY(10.0*acos(0.667*x + 1.667)) d7459a19aa3b4ea694726989366e90d0--0454ff49b6cc454e935c50b66038b2ce c87a3e3bd93a48bfa8148010f7a5e121 4 0454ff49b6cc454e935c50b66038b2ce--28863647b06e47889c46a343172e85a3 8d3d49cfa5af4229a7c9c4377395d235 4163c577150840cb83fe7b675a283017 RY(5.0*acos(0.667*x + 1.667)) c87a3e3bd93a48bfa8148010f7a5e121--4163c577150840cb83fe7b675a283017 4163c577150840cb83fe7b675a283017--8d3d49cfa5af4229a7c9c4377395d235

Hardware-efficient ansatz

Ansatze blocks for quantum machine-learning are typically built following the Hardware-Efficient Ansatz formalism (HEA). Both fully digital and digital-analog HEAs can easily be built with the hea function. By default, the digital version is returned:

from qadence import hea
from qadence.draw import display

n_qubits = 3
depth = 2

ansatz = hea(n_qubits, depth)
%3 e21c24fc052542edb6a47053a1c0a4a3 0 439516cc68cc461b9467842b1fd48f0b RX(theta₀) e21c24fc052542edb6a47053a1c0a4a3--439516cc68cc461b9467842b1fd48f0b 7e2013782b9449e78729d03838845a95 1 ee837d7db5c544e4b92eca6935c647ed RY(theta₃) 439516cc68cc461b9467842b1fd48f0b--ee837d7db5c544e4b92eca6935c647ed 76ccb20cffcc46d2b7cf9da73b2cf0d1 RX(theta₆) ee837d7db5c544e4b92eca6935c647ed--76ccb20cffcc46d2b7cf9da73b2cf0d1 89c1a526c6824ceeb58a4021bba46191 76ccb20cffcc46d2b7cf9da73b2cf0d1--89c1a526c6824ceeb58a4021bba46191 8fce1d1889164094ac579186ecc3a051 89c1a526c6824ceeb58a4021bba46191--8fce1d1889164094ac579186ecc3a051 a60ec11d4cec4ae481a0a0d9f3516c96 RX(theta₉) 8fce1d1889164094ac579186ecc3a051--a60ec11d4cec4ae481a0a0d9f3516c96 0c0192107ce547c8878f13bbbc5ddf0e RY(theta₁₂) a60ec11d4cec4ae481a0a0d9f3516c96--0c0192107ce547c8878f13bbbc5ddf0e 3b3c056095ac497a8f7c19ca36ba3c9f RX(theta₁₅) 0c0192107ce547c8878f13bbbc5ddf0e--3b3c056095ac497a8f7c19ca36ba3c9f 86ab8d8f23b24483b4e7fb6ee02bb775 3b3c056095ac497a8f7c19ca36ba3c9f--86ab8d8f23b24483b4e7fb6ee02bb775 2cb9c961b11749d9ac512fb0c7f7862f 86ab8d8f23b24483b4e7fb6ee02bb775--2cb9c961b11749d9ac512fb0c7f7862f 2b1ebe2ead92452c96b32c6ddbcac6c4 2cb9c961b11749d9ac512fb0c7f7862f--2b1ebe2ead92452c96b32c6ddbcac6c4 c01a4f0f27354085a0c86ad41295c812 105be152b5994071aa12c97745544a14 RX(theta₁) 7e2013782b9449e78729d03838845a95--105be152b5994071aa12c97745544a14 ae8bb4471e5d4d1ea06a7ff7abc8518e 2 9f214d09ce5745d193b372cf1d984272 RY(theta₄) 105be152b5994071aa12c97745544a14--9f214d09ce5745d193b372cf1d984272 dcbf7200ab514f94bcfa8bf040344936 RX(theta₇) 9f214d09ce5745d193b372cf1d984272--dcbf7200ab514f94bcfa8bf040344936 310ff1772d5d4a7185f4303abfdc8990 X dcbf7200ab514f94bcfa8bf040344936--310ff1772d5d4a7185f4303abfdc8990 310ff1772d5d4a7185f4303abfdc8990--89c1a526c6824ceeb58a4021bba46191 718e73c0f2584e5d841f80eb24379666 310ff1772d5d4a7185f4303abfdc8990--718e73c0f2584e5d841f80eb24379666 0f23eab12e4540569bd5018f98fa1140 RX(theta₁₀) 718e73c0f2584e5d841f80eb24379666--0f23eab12e4540569bd5018f98fa1140 4c7295beec0c4f05966e3488d449cac0 RY(theta₁₃) 0f23eab12e4540569bd5018f98fa1140--4c7295beec0c4f05966e3488d449cac0 875eaf3284cd484897b41542fc5ea6fd RX(theta₁₆) 4c7295beec0c4f05966e3488d449cac0--875eaf3284cd484897b41542fc5ea6fd 9f08692120fa452c96c9f49b6888c425 X 875eaf3284cd484897b41542fc5ea6fd--9f08692120fa452c96c9f49b6888c425 9f08692120fa452c96c9f49b6888c425--86ab8d8f23b24483b4e7fb6ee02bb775 92ba5826adc0425794855d89aa530c6f 9f08692120fa452c96c9f49b6888c425--92ba5826adc0425794855d89aa530c6f 92ba5826adc0425794855d89aa530c6f--c01a4f0f27354085a0c86ad41295c812 f820eeadcdb7420d94f6c126645e2a23 cfaa46beabf1489b93207868005ca2e5 RX(theta₂) ae8bb4471e5d4d1ea06a7ff7abc8518e--cfaa46beabf1489b93207868005ca2e5 a71f8fb557154eb39e06a609034dfc68 RY(theta₅) cfaa46beabf1489b93207868005ca2e5--a71f8fb557154eb39e06a609034dfc68 b1e533493d994de68fde91aa962611c0 RX(theta₈) a71f8fb557154eb39e06a609034dfc68--b1e533493d994de68fde91aa962611c0 bc7d6a2580d74aabb82c60fe7fcacd7f b1e533493d994de68fde91aa962611c0--bc7d6a2580d74aabb82c60fe7fcacd7f 5ccb00bcbb2749ada884eec1d750c3b0 X bc7d6a2580d74aabb82c60fe7fcacd7f--5ccb00bcbb2749ada884eec1d750c3b0 5ccb00bcbb2749ada884eec1d750c3b0--718e73c0f2584e5d841f80eb24379666 ceed0891a8a4409682993386089dbedd RX(theta₁₁) 5ccb00bcbb2749ada884eec1d750c3b0--ceed0891a8a4409682993386089dbedd a016b4ae924b40bf90247bb9398778cf RY(theta₁₄) ceed0891a8a4409682993386089dbedd--a016b4ae924b40bf90247bb9398778cf c01b8419044e46b99bc70649609da8dc RX(theta₁₇) a016b4ae924b40bf90247bb9398778cf--c01b8419044e46b99bc70649609da8dc e895f74f9b6f4a9e8b7ee04e2acbb1b6 c01b8419044e46b99bc70649609da8dc--e895f74f9b6f4a9e8b7ee04e2acbb1b6 6b3267617bdf40f792d349f8bd6c635b X e895f74f9b6f4a9e8b7ee04e2acbb1b6--6b3267617bdf40f792d349f8bd6c635b 6b3267617bdf40f792d349f8bd6c635b--92ba5826adc0425794855d89aa530c6f 6b3267617bdf40f792d349f8bd6c635b--f820eeadcdb7420d94f6c126645e2a23

As seen above, the rotation layers are automatically parameterized, and the prefix "theta" can be changed with the param_prefix argument.

Furthermore, both the single-qubit rotations and the two-qubit entangler can be customized with the operations and entangler argument. The operations can be passed as a list of single-qubit rotations, while the entangler should be either CNOT, CZ, CRX, CRY, CRZ or CPHASE.

from qadence import RX, RY, CPHASE

ansatz = hea(
    n_qubits=n_qubits,
    depth=depth,
    param_prefix="phi",
    operations=[RX, RY, RX],
    entangler=CPHASE
)
%3 791318d59d7843bebc04275ffb0be549 0 b9dd1ba1b324495490ff0000c9ba127f RX(phi₀) 791318d59d7843bebc04275ffb0be549--b9dd1ba1b324495490ff0000c9ba127f 9b4f676b5df441ea8d0de4d37f7cdca0 1 9934e30d6d8e4b9fb13df91336f00520 RY(phi₃) b9dd1ba1b324495490ff0000c9ba127f--9934e30d6d8e4b9fb13df91336f00520 1ff04adf8f804ea6b55c18c3ac929091 RX(phi₆) 9934e30d6d8e4b9fb13df91336f00520--1ff04adf8f804ea6b55c18c3ac929091 335b8f84cac344a9a1db3e8e6a1b607a 1ff04adf8f804ea6b55c18c3ac929091--335b8f84cac344a9a1db3e8e6a1b607a 1e0ddfe2e2de4a92bbadf3d4f3680de7 335b8f84cac344a9a1db3e8e6a1b607a--1e0ddfe2e2de4a92bbadf3d4f3680de7 df2bc4855bca4491b98767573b56eab8 RX(phi₉) 1e0ddfe2e2de4a92bbadf3d4f3680de7--df2bc4855bca4491b98767573b56eab8 fa417801d3a5491aafd044883d231b9c RY(phi₁₂) df2bc4855bca4491b98767573b56eab8--fa417801d3a5491aafd044883d231b9c ab7a82c692bc44b8be4878f412c0536c RX(phi₁₅) fa417801d3a5491aafd044883d231b9c--ab7a82c692bc44b8be4878f412c0536c 143adf944e2d460ea81d7543e00846e0 ab7a82c692bc44b8be4878f412c0536c--143adf944e2d460ea81d7543e00846e0 48669bd562fb4b979de366ee22582399 143adf944e2d460ea81d7543e00846e0--48669bd562fb4b979de366ee22582399 0e5f844df50046259a0a2dfd9ae1b039 48669bd562fb4b979de366ee22582399--0e5f844df50046259a0a2dfd9ae1b039 b88b70728859409f834bbe38b798d5ce c5e44b9856bd4fc7a92f914927d7f51b RX(phi₁) 9b4f676b5df441ea8d0de4d37f7cdca0--c5e44b9856bd4fc7a92f914927d7f51b 91134d634614441a923419111080d0f6 2 2526fd7f7fa447a6a5ac4fe0247ed2e7 RY(phi₄) c5e44b9856bd4fc7a92f914927d7f51b--2526fd7f7fa447a6a5ac4fe0247ed2e7 41e23ef2c0b24f08a53de839c1660f48 RX(phi₇) 2526fd7f7fa447a6a5ac4fe0247ed2e7--41e23ef2c0b24f08a53de839c1660f48 32a2e692e0df4528886a080bf8a15cfc PHASE(phi_ent₀) 41e23ef2c0b24f08a53de839c1660f48--32a2e692e0df4528886a080bf8a15cfc 32a2e692e0df4528886a080bf8a15cfc--335b8f84cac344a9a1db3e8e6a1b607a 61bcd5924af044af840c110f18e185d8 32a2e692e0df4528886a080bf8a15cfc--61bcd5924af044af840c110f18e185d8 13f0ba3e0a014a2799f2f7783248c229 RX(phi₁₀) 61bcd5924af044af840c110f18e185d8--13f0ba3e0a014a2799f2f7783248c229 a2ec1b1b6a984af5bc22b4d2a4abd0fe RY(phi₁₃) 13f0ba3e0a014a2799f2f7783248c229--a2ec1b1b6a984af5bc22b4d2a4abd0fe 36c97328e4d94d00b594b6c5f7c3793d RX(phi₁₆) a2ec1b1b6a984af5bc22b4d2a4abd0fe--36c97328e4d94d00b594b6c5f7c3793d e2f5aa585fed474d9a83abd2addeb7a2 PHASE(phi_ent₂) 36c97328e4d94d00b594b6c5f7c3793d--e2f5aa585fed474d9a83abd2addeb7a2 e2f5aa585fed474d9a83abd2addeb7a2--143adf944e2d460ea81d7543e00846e0 777217e22e4940dab7bd052304f12354 e2f5aa585fed474d9a83abd2addeb7a2--777217e22e4940dab7bd052304f12354 777217e22e4940dab7bd052304f12354--b88b70728859409f834bbe38b798d5ce 9477c897bc8e4610861afd4f9ad269aa df2151d5d7a2456792c7004fc05b6936 RX(phi₂) 91134d634614441a923419111080d0f6--df2151d5d7a2456792c7004fc05b6936 6103d2ed02fc41c08b827e1d883021eb RY(phi₅) df2151d5d7a2456792c7004fc05b6936--6103d2ed02fc41c08b827e1d883021eb 212980bf3c434ceea993f807941ea05d RX(phi₈) 6103d2ed02fc41c08b827e1d883021eb--212980bf3c434ceea993f807941ea05d 010afdf9d15447018695ffba56cc2330 212980bf3c434ceea993f807941ea05d--010afdf9d15447018695ffba56cc2330 518353511fff4100ab0a6b6d0cdbac9f PHASE(phi_ent₁) 010afdf9d15447018695ffba56cc2330--518353511fff4100ab0a6b6d0cdbac9f 518353511fff4100ab0a6b6d0cdbac9f--61bcd5924af044af840c110f18e185d8 b7c9a7ebf5ff4b2cab55ad55d3dcf62d RX(phi₁₁) 518353511fff4100ab0a6b6d0cdbac9f--b7c9a7ebf5ff4b2cab55ad55d3dcf62d ae0c0c7c4a3f4f94bd5f3909d87e9a5d RY(phi₁₄) b7c9a7ebf5ff4b2cab55ad55d3dcf62d--ae0c0c7c4a3f4f94bd5f3909d87e9a5d 4423a8805f71402a8e0f6e1492e384fe RX(phi₁₇) ae0c0c7c4a3f4f94bd5f3909d87e9a5d--4423a8805f71402a8e0f6e1492e384fe b9bbd31ca28d4219848a6bd955005a4a 4423a8805f71402a8e0f6e1492e384fe--b9bbd31ca28d4219848a6bd955005a4a c1a66cb1a1a641d3ba0f932ffe05f1d7 PHASE(phi_ent₃) b9bbd31ca28d4219848a6bd955005a4a--c1a66cb1a1a641d3ba0f932ffe05f1d7 c1a66cb1a1a641d3ba0f932ffe05f1d7--777217e22e4940dab7bd052304f12354 c1a66cb1a1a641d3ba0f932ffe05f1d7--9477c897bc8e4610861afd4f9ad269aa

Having a truly hardware-efficient ansatz means that the entangling operation can be chosen according to each device's native interactions. Besides digital operations, in Qadence it is also possible to build digital-analog HEAs with the entanglement produced by the natural evolution of a set of interacting qubits, as natively implemented in neutral atom devices. As with other digital-analog functions, this can be controlled with the strategy argument which can be chosen from the Strategy enum type. Currently, only Strategy.DIGITAL and Strategy.SDAQC are available. By default, calling strategy = Strategy.SDAQC will use a global entangling Hamiltonian with Ising-like \(NN\) interactions and constant interaction strength,

from qadence import Strategy

ansatz = hea(
    n_qubits,
    depth=depth,
    strategy=Strategy.SDAQC
)
%3 cluster_7e38c06b5704433983ba2af127f98753 cluster_6a266c71fd284561905dab103ef41ede 29ce4fb177804ea4aea061529ff80abb 0 03a51299c0ab42a0a49ac52a85542da2 RX(theta₀) 29ce4fb177804ea4aea061529ff80abb--03a51299c0ab42a0a49ac52a85542da2 10e746166bab4fa28985f118f8494854 1 89f03928bbe047ddae5500c530026048 RY(theta₃) 03a51299c0ab42a0a49ac52a85542da2--89f03928bbe047ddae5500c530026048 1a65e97beff245129543fac743bba909 RX(theta₆) 89f03928bbe047ddae5500c530026048--1a65e97beff245129543fac743bba909 e7b46adc3e064e318b7d6b12613e0423 HamEvo 1a65e97beff245129543fac743bba909--e7b46adc3e064e318b7d6b12613e0423 5ad765cdf547425e9a5a832c6b62b3ff RX(theta₉) e7b46adc3e064e318b7d6b12613e0423--5ad765cdf547425e9a5a832c6b62b3ff a29401e012bd4a82bd267f7b3e3ff664 RY(theta₁₂) 5ad765cdf547425e9a5a832c6b62b3ff--a29401e012bd4a82bd267f7b3e3ff664 4e3406534c8f4aa89f31e2d216ac5a0c RX(theta₁₅) a29401e012bd4a82bd267f7b3e3ff664--4e3406534c8f4aa89f31e2d216ac5a0c bd1c37de9bd946cdbb664782e9520c22 HamEvo 4e3406534c8f4aa89f31e2d216ac5a0c--bd1c37de9bd946cdbb664782e9520c22 d3b304180a064b6f9077ebeb94fafa8e bd1c37de9bd946cdbb664782e9520c22--d3b304180a064b6f9077ebeb94fafa8e 8cab3d5c8f624bcb8530123c15c9ec9b c2411ead2d3846908cbc89c5ebd5cbf9 RX(theta₁) 10e746166bab4fa28985f118f8494854--c2411ead2d3846908cbc89c5ebd5cbf9 56f1c01cfbe14f6ba3bab9203977392e 2 9b6c7b3dfdff44399149f9a39d9f545e RY(theta₄) c2411ead2d3846908cbc89c5ebd5cbf9--9b6c7b3dfdff44399149f9a39d9f545e 7828d74951d44ec8ab7963c677de1871 RX(theta₇) 9b6c7b3dfdff44399149f9a39d9f545e--7828d74951d44ec8ab7963c677de1871 1a7f0b9918ea488dad68953453db6927 t = theta_t₀ 7828d74951d44ec8ab7963c677de1871--1a7f0b9918ea488dad68953453db6927 d6081427d2994089aa02b79c568c58d0 RX(theta₁₀) 1a7f0b9918ea488dad68953453db6927--d6081427d2994089aa02b79c568c58d0 d13028e776bf42c9a73d9e29d73b8e0f RY(theta₁₃) d6081427d2994089aa02b79c568c58d0--d13028e776bf42c9a73d9e29d73b8e0f f18d1c14c3b749e09da6004cd2f7edde RX(theta₁₆) d13028e776bf42c9a73d9e29d73b8e0f--f18d1c14c3b749e09da6004cd2f7edde 0a9e66c941f3463da097cc0e3efca4f7 t = theta_t₁ f18d1c14c3b749e09da6004cd2f7edde--0a9e66c941f3463da097cc0e3efca4f7 0a9e66c941f3463da097cc0e3efca4f7--8cab3d5c8f624bcb8530123c15c9ec9b 4ef60d6b288a4061832080f6226fa217 ad684a67765a4afda76ddba772f375c0 RX(theta₂) 56f1c01cfbe14f6ba3bab9203977392e--ad684a67765a4afda76ddba772f375c0 a8e2bfc786a646e4a0392b556be27cd3 RY(theta₅) ad684a67765a4afda76ddba772f375c0--a8e2bfc786a646e4a0392b556be27cd3 4499bcbdc77a48398026cdf939150652 RX(theta₈) a8e2bfc786a646e4a0392b556be27cd3--4499bcbdc77a48398026cdf939150652 8f93c77a76244fa8ba4154bfbe6cab4e 4499bcbdc77a48398026cdf939150652--8f93c77a76244fa8ba4154bfbe6cab4e 3f06f11dd90a41c695af1cbe2071cd80 RX(theta₁₁) 8f93c77a76244fa8ba4154bfbe6cab4e--3f06f11dd90a41c695af1cbe2071cd80 898927eb0bf946309053c5b52c77c44b RY(theta₁₄) 3f06f11dd90a41c695af1cbe2071cd80--898927eb0bf946309053c5b52c77c44b 90d543704d86487f8dedefbf5eb75796 RX(theta₁₇) 898927eb0bf946309053c5b52c77c44b--90d543704d86487f8dedefbf5eb75796 0f32ba4c97c747a7acc081da0806bfd3 90d543704d86487f8dedefbf5eb75796--0f32ba4c97c747a7acc081da0806bfd3 0f32ba4c97c747a7acc081da0806bfd3--4ef60d6b288a4061832080f6226fa217

Note that, by default, only the time-parameter is automatically parameterized when building a digital-analog HEA. However, as described in the Hamiltonians tutorial, arbitrary interaction Hamiltonians can be easily built with the hamiltonian_factory function, with both customized or fully parameterized interactions, and these can be directly passed as the entangler for a customizable digital-analog HEA.

from qadence import hamiltonian_factory, Interaction, N, Register, hea

# Build a parameterized neutral-atom Hamiltonian following a honeycomb_lattice:
register = Register.honeycomb_lattice(1, 1)

entangler = hamiltonian_factory(
    register,
    interaction=Interaction.NN,
    detuning=N,
    interaction_strength="e",
    detuning_strength="n"
)

# Build a fully parameterized Digital-Analog HEA:
n_qubits = register.n_qubits
depth = 2

ansatz = hea(
    n_qubits=register.n_qubits,
    depth=depth,
    operations=[RX, RY, RX],
    entangler=entangler,
    strategy=Strategy.SDAQC
)
%3 cluster_9c64cc148b34401ba33f4baa36b86bbe cluster_5011e46363b24816ae68afe699663625 96d13bfd58074633af07c4c412480323 0 86a7345681e64b2aa9a368d1602f182e RX(theta₀) 96d13bfd58074633af07c4c412480323--86a7345681e64b2aa9a368d1602f182e 5a23eef080c743219e7483c1d16c787e 1 d68b2616a93541429da88d36893ec297 RY(theta₆) 86a7345681e64b2aa9a368d1602f182e--d68b2616a93541429da88d36893ec297 7854314425a845969898696b4de5f6bf RX(theta₁₂) d68b2616a93541429da88d36893ec297--7854314425a845969898696b4de5f6bf 826e7d9db3f74d59b34fdea8c9e246ad 7854314425a845969898696b4de5f6bf--826e7d9db3f74d59b34fdea8c9e246ad bb5fa20209c94c0488b01b68b3323c4c RX(theta₁₈) 826e7d9db3f74d59b34fdea8c9e246ad--bb5fa20209c94c0488b01b68b3323c4c 4cc3efdac9854e33b5e072b0ce6d6241 RY(theta₂₄) bb5fa20209c94c0488b01b68b3323c4c--4cc3efdac9854e33b5e072b0ce6d6241 9f2ffb5fa2a743748415ec514e66c6f5 RX(theta₃₀) 4cc3efdac9854e33b5e072b0ce6d6241--9f2ffb5fa2a743748415ec514e66c6f5 b4fc4f213be84f1380c2bceff949507a 9f2ffb5fa2a743748415ec514e66c6f5--b4fc4f213be84f1380c2bceff949507a 8f22327a9b324253baab39526faa42ad b4fc4f213be84f1380c2bceff949507a--8f22327a9b324253baab39526faa42ad 2099c5e4fb004ff8a0b515fa9d79d973 1dee22ec0eaa47c198434c2d6bf3536e RX(theta₁) 5a23eef080c743219e7483c1d16c787e--1dee22ec0eaa47c198434c2d6bf3536e 5c2b278d03724bd69b2552c5a59b498b 2 b58db3ffaccc4f34b3579c07011c6093 RY(theta₇) 1dee22ec0eaa47c198434c2d6bf3536e--b58db3ffaccc4f34b3579c07011c6093 064ffb39e10b4423a72cc64ea5f47d51 RX(theta₁₃) b58db3ffaccc4f34b3579c07011c6093--064ffb39e10b4423a72cc64ea5f47d51 b345ac59a61d48a882c4a9983b9ab898 064ffb39e10b4423a72cc64ea5f47d51--b345ac59a61d48a882c4a9983b9ab898 31297ab1e829497e9d5338e21b02ae63 RX(theta₁₉) b345ac59a61d48a882c4a9983b9ab898--31297ab1e829497e9d5338e21b02ae63 2cf875847fa64248bf6532eee3ccb172 RY(theta₂₅) 31297ab1e829497e9d5338e21b02ae63--2cf875847fa64248bf6532eee3ccb172 ab0ca01a0b29411eb6b416b67faaaf1d RX(theta₃₁) 2cf875847fa64248bf6532eee3ccb172--ab0ca01a0b29411eb6b416b67faaaf1d b0b47c20b666412dbe0ae223fc2245ab ab0ca01a0b29411eb6b416b67faaaf1d--b0b47c20b666412dbe0ae223fc2245ab b0b47c20b666412dbe0ae223fc2245ab--2099c5e4fb004ff8a0b515fa9d79d973 80453911e44f464ab6ceabd536685e4f da0899e3c4864a73b75dab7a6ddb0c15 RX(theta₂) 5c2b278d03724bd69b2552c5a59b498b--da0899e3c4864a73b75dab7a6ddb0c15 212ef340f411492285f734425010e366 3 0a402e5c0c704ac18fe36fa4d0d5d192 RY(theta₈) da0899e3c4864a73b75dab7a6ddb0c15--0a402e5c0c704ac18fe36fa4d0d5d192 444b9bd160f049babaf8be443b2bca25 RX(theta₁₄) 0a402e5c0c704ac18fe36fa4d0d5d192--444b9bd160f049babaf8be443b2bca25 c62d7c9a09794872a72fce89b4c3d6d2 HamEvo 444b9bd160f049babaf8be443b2bca25--c62d7c9a09794872a72fce89b4c3d6d2 813abcaae820427dbbc04f5e2215e0c7 RX(theta₂₀) c62d7c9a09794872a72fce89b4c3d6d2--813abcaae820427dbbc04f5e2215e0c7 62db98820bc640998abc8941a21b636b RY(theta₂₆) 813abcaae820427dbbc04f5e2215e0c7--62db98820bc640998abc8941a21b636b 19684bebfa934794953152ea86957962 RX(theta₃₂) 62db98820bc640998abc8941a21b636b--19684bebfa934794953152ea86957962 b7b8d1d39fa84f7180517a8a529f66af HamEvo 19684bebfa934794953152ea86957962--b7b8d1d39fa84f7180517a8a529f66af b7b8d1d39fa84f7180517a8a529f66af--80453911e44f464ab6ceabd536685e4f 258a8c47e7c04324b7127d9e61819fa3 736579a2bd15478591a8dc65ddd85396 RX(theta₃) 212ef340f411492285f734425010e366--736579a2bd15478591a8dc65ddd85396 16af0460f8d1448f88f8fc8d00809a4a 4 4dd9465953884122a7e2e6b29a9aa830 RY(theta₉) 736579a2bd15478591a8dc65ddd85396--4dd9465953884122a7e2e6b29a9aa830 d56bdc2a615d4b46ad392b9fb10d5560 RX(theta₁₅) 4dd9465953884122a7e2e6b29a9aa830--d56bdc2a615d4b46ad392b9fb10d5560 75cef0e6aede4130ad24b0f807f0205d t = theta_t₀ d56bdc2a615d4b46ad392b9fb10d5560--75cef0e6aede4130ad24b0f807f0205d a1f027e3df2343eebff4f49328106873 RX(theta₂₁) 75cef0e6aede4130ad24b0f807f0205d--a1f027e3df2343eebff4f49328106873 d430fbc52e4e4a50b8690fc0d4117e22 RY(theta₂₇) a1f027e3df2343eebff4f49328106873--d430fbc52e4e4a50b8690fc0d4117e22 7007413a51064aac9dca86aefaf9d0e1 RX(theta₃₃) d430fbc52e4e4a50b8690fc0d4117e22--7007413a51064aac9dca86aefaf9d0e1 56aa4f926fec4aafac7abecf6fa6c0b3 t = theta_t₁ 7007413a51064aac9dca86aefaf9d0e1--56aa4f926fec4aafac7abecf6fa6c0b3 56aa4f926fec4aafac7abecf6fa6c0b3--258a8c47e7c04324b7127d9e61819fa3 728220e71e414e3f9b2586f3a2b0cef5 53c78ed68a014ed4acd2353fefb4173e RX(theta₄) 16af0460f8d1448f88f8fc8d00809a4a--53c78ed68a014ed4acd2353fefb4173e b6870169dc9049e3bc287772ffcc0ed7 5 6b8da369e68b4898a05eb1813ad9ced0 RY(theta₁₀) 53c78ed68a014ed4acd2353fefb4173e--6b8da369e68b4898a05eb1813ad9ced0 7a957e983b7344728d99a3b0e9bf7cc1 RX(theta₁₆) 6b8da369e68b4898a05eb1813ad9ced0--7a957e983b7344728d99a3b0e9bf7cc1 7c2065643f4d409099ba680df24300b8 7a957e983b7344728d99a3b0e9bf7cc1--7c2065643f4d409099ba680df24300b8 e90b6d3dbd554d4eb24e04485cda5676 RX(theta₂₂) 7c2065643f4d409099ba680df24300b8--e90b6d3dbd554d4eb24e04485cda5676 7d49e4eb9b89474995f7a2ab473bb8b4 RY(theta₂₈) e90b6d3dbd554d4eb24e04485cda5676--7d49e4eb9b89474995f7a2ab473bb8b4 e4937adc0d79441d914e5d3486248d7c RX(theta₃₄) 7d49e4eb9b89474995f7a2ab473bb8b4--e4937adc0d79441d914e5d3486248d7c bbc97241ead743b5ba1ea500ee9dca0c e4937adc0d79441d914e5d3486248d7c--bbc97241ead743b5ba1ea500ee9dca0c bbc97241ead743b5ba1ea500ee9dca0c--728220e71e414e3f9b2586f3a2b0cef5 67746fe133124bbd854a219e3bdf2e4b 8bf7850b9b36469083889cb257695767 RX(theta₅) b6870169dc9049e3bc287772ffcc0ed7--8bf7850b9b36469083889cb257695767 8fc6873656c744f3b282e312b0cdeff9 RY(theta₁₁) 8bf7850b9b36469083889cb257695767--8fc6873656c744f3b282e312b0cdeff9 3ffa56ca700c49d69b1ee1ded5477090 RX(theta₁₇) 8fc6873656c744f3b282e312b0cdeff9--3ffa56ca700c49d69b1ee1ded5477090 405c3958090b4a858f3ed1cb6429bbed 3ffa56ca700c49d69b1ee1ded5477090--405c3958090b4a858f3ed1cb6429bbed 17c8a090236a4eeeb2cb3e6a96038358 RX(theta₂₃) 405c3958090b4a858f3ed1cb6429bbed--17c8a090236a4eeeb2cb3e6a96038358 eb51b4bf16754195be6f4ea96af3ae85 RY(theta₂₉) 17c8a090236a4eeeb2cb3e6a96038358--eb51b4bf16754195be6f4ea96af3ae85 298f25d1874849e8af578d250db46c20 RX(theta₃₅) eb51b4bf16754195be6f4ea96af3ae85--298f25d1874849e8af578d250db46c20 917d3b81b23d4c51a7ba9ca00bea73bd 298f25d1874849e8af578d250db46c20--917d3b81b23d4c51a7ba9ca00bea73bd 917d3b81b23d4c51a7ba9ca00bea73bd--67746fe133124bbd854a219e3bdf2e4b