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_aec5c12b3799470abd16ce0b1c3dd534 Constant Chebyshev FM cluster_8de9e7d910ef4474bab5d5c62834f11b Constant Fourier FM b9b3bc67bf324a969c0bfb9115d14e59 0 f1a687be553245769a7a706bc91acfaf RX(phi) b9b3bc67bf324a969c0bfb9115d14e59--f1a687be553245769a7a706bc91acfaf 71e243c4299c4633a4850928804dc0d2 1 eb2a47b4acc84b97bd753933d8e0aa46 RX(acos(phi)) f1a687be553245769a7a706bc91acfaf--eb2a47b4acc84b97bd753933d8e0aa46 90f74b6062c248e88a3b6ea4e4817389 eb2a47b4acc84b97bd753933d8e0aa46--90f74b6062c248e88a3b6ea4e4817389 b16675d3cf4340ef8051fdafbda78809 98f5f6e904554d37842a1747a80a004c RX(phi) 71e243c4299c4633a4850928804dc0d2--98f5f6e904554d37842a1747a80a004c 584b6153a58d4788bee2fd288029d32d 2 b64234a70a844286bb3fc7f9978d828c RX(acos(phi)) 98f5f6e904554d37842a1747a80a004c--b64234a70a844286bb3fc7f9978d828c b64234a70a844286bb3fc7f9978d828c--b16675d3cf4340ef8051fdafbda78809 1731bdec6f914096aa8964f0e0b29a8b 8a6fef03f12649c0bc37b16df59a9cb0 RX(phi) 584b6153a58d4788bee2fd288029d32d--8a6fef03f12649c0bc37b16df59a9cb0 90bf0b1294394679aa520692e72f9616 RX(acos(phi)) 8a6fef03f12649c0bc37b16df59a9cb0--90bf0b1294394679aa520692e72f9616 90bf0b1294394679aa520692e72f9616--1731bdec6f914096aa8964f0e0b29a8b

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_15c02a53d02648f7a391e43598f3b2d8 Constant custom_func FM cluster_9eef0852ad4f4ef29be41c460d0534f2 Constant asin FM 4edf81e552e3474789c5cc0b751ab167 0 e02844bf783e44f3b8d17f0aa23ad9f0 RX(asin(phi)) 4edf81e552e3474789c5cc0b751ab167--e02844bf783e44f3b8d17f0aa23ad9f0 1ead6ded447b423eaa160c47aa47d4d0 1 ba7eea60f81c48c995e0189a2f76c242 RX(phi**2 + asin(phi)) e02844bf783e44f3b8d17f0aa23ad9f0--ba7eea60f81c48c995e0189a2f76c242 44905099ea7e49959820084923e3bf16 ba7eea60f81c48c995e0189a2f76c242--44905099ea7e49959820084923e3bf16 ce267ce4483d4c41bc602edea0276661 4fb1dd6d540642079403f4ba1074a0a9 RX(asin(phi)) 1ead6ded447b423eaa160c47aa47d4d0--4fb1dd6d540642079403f4ba1074a0a9 01156d97bca04974b1678d8314bba390 2 453bca5351614cc08d333937ee707485 RX(phi**2 + asin(phi)) 4fb1dd6d540642079403f4ba1074a0a9--453bca5351614cc08d333937ee707485 453bca5351614cc08d333937ee707485--ce267ce4483d4c41bc602edea0276661 73eafa907b394c569ef1edab11a1b9f0 e06e74e1a2614034bc6d8bee508c82a9 RX(asin(phi)) 01156d97bca04974b1678d8314bba390--e06e74e1a2614034bc6d8bee508c82a9 ba9ce08aa221413cbf55c9d9984e3c87 RX(phi**2 + asin(phi)) e06e74e1a2614034bc6d8bee508c82a9--ba9ce08aa221413cbf55c9d9984e3c87 ba9ce08aa221413cbf55c9d9984e3c87--73eafa907b394c569ef1edab11a1b9f0

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_e29099181a6f46d886c23cda4f6edc05 Exponential Fourier FM cluster_21ada88a093c4a0f8e3bc62f0a2a410f Constant Fourier FM cluster_cf720a8429474e2293314b3344798127 Tower Fourier FM 6975a865d65649648b3683d03d674c36 0 a0e0c2d33ef2410ab696480c6586b00e RX(phi) 6975a865d65649648b3683d03d674c36--a0e0c2d33ef2410ab696480c6586b00e 3f56081350df42858f33a27ed13df635 1 5537387ea20b4b428651ca7c82ac795c RX(1.0*phi) a0e0c2d33ef2410ab696480c6586b00e--5537387ea20b4b428651ca7c82ac795c ce314d0a9d55414887fc8776935b69fc RX(1.0*phi) 5537387ea20b4b428651ca7c82ac795c--ce314d0a9d55414887fc8776935b69fc 95185f7d6f4f4ef889410c4809b807ee ce314d0a9d55414887fc8776935b69fc--95185f7d6f4f4ef889410c4809b807ee 1b7530a816644bef825140bccab974a1 008e1964c6b74dce82c8ee2d39f282e6 RX(phi) 3f56081350df42858f33a27ed13df635--008e1964c6b74dce82c8ee2d39f282e6 37abdac71e7d4be4971d7ec99ccea013 2 d42ec10af87e4d8d9b15d1f1bf4e96d3 RX(2.0*phi) 008e1964c6b74dce82c8ee2d39f282e6--d42ec10af87e4d8d9b15d1f1bf4e96d3 6c0cd10011a8408cb4b894efbc4c26db RX(2.0*phi) d42ec10af87e4d8d9b15d1f1bf4e96d3--6c0cd10011a8408cb4b894efbc4c26db 6c0cd10011a8408cb4b894efbc4c26db--1b7530a816644bef825140bccab974a1 ebdab465215c48228352e9133b7b87b4 32cfe668faff45a7b181b37d8296eaea RX(phi) 37abdac71e7d4be4971d7ec99ccea013--32cfe668faff45a7b181b37d8296eaea 291029ead8f743e1a87fee8a8fc3322a 3 7cd0dfccf2204dd09a4186f2ae3e0158 RX(3.0*phi) 32cfe668faff45a7b181b37d8296eaea--7cd0dfccf2204dd09a4186f2ae3e0158 1e4014a754604f38844398f77dd7ffde RX(4.0*phi) 7cd0dfccf2204dd09a4186f2ae3e0158--1e4014a754604f38844398f77dd7ffde 1e4014a754604f38844398f77dd7ffde--ebdab465215c48228352e9133b7b87b4 673f58966da94452901b4aa7931c86bc 35b1aedd586f4b85bff3f13293b801aa RX(phi) 291029ead8f743e1a87fee8a8fc3322a--35b1aedd586f4b85bff3f13293b801aa a0c799bf82584b979c884ed6497b0e90 4 3a91709092ac4ab1a407b01fd7646efa RX(4.0*phi) 35b1aedd586f4b85bff3f13293b801aa--3a91709092ac4ab1a407b01fd7646efa 78b9063f5977456d8aa35298b80d6757 RX(8.0*phi) 3a91709092ac4ab1a407b01fd7646efa--78b9063f5977456d8aa35298b80d6757 78b9063f5977456d8aa35298b80d6757--673f58966da94452901b4aa7931c86bc 95a46aa97a874004acc726d911348c86 656e9e784d3a40dc860483a022eed30e RX(phi) a0c799bf82584b979c884ed6497b0e90--656e9e784d3a40dc860483a022eed30e 11647f89de884124be361c782705dea4 RX(5.0*phi) 656e9e784d3a40dc860483a022eed30e--11647f89de884124be361c782705dea4 f464cb3515b344dfb46cb00c2215ac77 RX(16.0*phi) 11647f89de884124be361c782705dea4--f464cb3515b344dfb46cb00c2215ac77 f464cb3515b344dfb46cb00c2215ac77--95a46aa97a874004acc726d911348c86

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 a3783f9424444331a2c24131f9edf4c7 0 653c530fb8cd4f3d80fe0755ca0a6ddd RX(1.0*acos(phi)) a3783f9424444331a2c24131f9edf4c7--653c530fb8cd4f3d80fe0755ca0a6ddd 2f6d75a89daf4fb1aaeef0ddf4a53d79 1 49b5a61801bf46bcabeea4868742c2c8 653c530fb8cd4f3d80fe0755ca0a6ddd--49b5a61801bf46bcabeea4868742c2c8 3537ed643b86411aa3ffb6ddfb52d3f0 657345fd96fd4e4fbbe04e75fa629d08 RX(1.414*acos(phi)) 2f6d75a89daf4fb1aaeef0ddf4a53d79--657345fd96fd4e4fbbe04e75fa629d08 4e2e67feb1e74171a953adc10649ca0e 2 657345fd96fd4e4fbbe04e75fa629d08--3537ed643b86411aa3ffb6ddfb52d3f0 a8d5a529e8f44550b36b1935daeebb19 556f0d2c2fa343ff87d0bfaf9e5b3a2a RX(1.732*acos(phi)) 4e2e67feb1e74171a953adc10649ca0e--556f0d2c2fa343ff87d0bfaf9e5b3a2a cfaf67f3eb6647d2bf4bd98049216920 3 556f0d2c2fa343ff87d0bfaf9e5b3a2a--a8d5a529e8f44550b36b1935daeebb19 24140e16613f43c5bdf17d407ee47d42 26f24a68a38149c69e29b510b768adcf RX(2.0*acos(phi)) cfaf67f3eb6647d2bf4bd98049216920--26f24a68a38149c69e29b510b768adcf 72792c06ae5f4b5086254715afb1f4e0 4 26f24a68a38149c69e29b510b768adcf--24140e16613f43c5bdf17d407ee47d42 02a120d5d4764b03b7fd09b69065a0d5 43c6031572c6420ba2a1f69446b27e3b RX(2.236*acos(phi)) 72792c06ae5f4b5086254715afb1f4e0--43c6031572c6420ba2a1f69446b27e3b 43c6031572c6420ba2a1f69446b27e3b--02a120d5d4764b03b7fd09b69065a0d5

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 717e11c3d3234312894ed7a38f48ad2d 0 4f686a0b49e346c49c04636c8b44c6a6 RY(80.0*acos(0.667*x + 1.667)) 717e11c3d3234312894ed7a38f48ad2d--4f686a0b49e346c49c04636c8b44c6a6 b9d67656e89c4bada2e2fc6774aeaa25 1 9da75a535d19432387c90a9f2601f741 4f686a0b49e346c49c04636c8b44c6a6--9da75a535d19432387c90a9f2601f741 9989724e823a4b6f9f1a8d4c6da7a042 f8f88ca0a66a4962acae2fa53b4aa833 RY(40.0*acos(0.667*x + 1.667)) b9d67656e89c4bada2e2fc6774aeaa25--f8f88ca0a66a4962acae2fa53b4aa833 ee88407e95f74eaf94a89d6f3490ceed 2 f8f88ca0a66a4962acae2fa53b4aa833--9989724e823a4b6f9f1a8d4c6da7a042 04850a653a2249668faac8cd4f47c2be ea8884ee8a464048807c86b2326d21d2 RY(20.0*acos(0.667*x + 1.667)) ee88407e95f74eaf94a89d6f3490ceed--ea8884ee8a464048807c86b2326d21d2 4b822cf1381d47539e073f77e95fb129 3 ea8884ee8a464048807c86b2326d21d2--04850a653a2249668faac8cd4f47c2be c30bd9c4a6684530b8dd65d3fe4fce6f af447607c49e4ca2bae94fe4984932bf RY(10.0*acos(0.667*x + 1.667)) 4b822cf1381d47539e073f77e95fb129--af447607c49e4ca2bae94fe4984932bf 51d9f05a4d554781967e8c41c132641e 4 af447607c49e4ca2bae94fe4984932bf--c30bd9c4a6684530b8dd65d3fe4fce6f 0529cfedb3364420b916e6539d0af6ad 6cef6645b34a4758a2614dc7cb294819 RY(5.0*acos(0.667*x + 1.667)) 51d9f05a4d554781967e8c41c132641e--6cef6645b34a4758a2614dc7cb294819 6cef6645b34a4758a2614dc7cb294819--0529cfedb3364420b916e6539d0af6ad

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 f38a32c351444ea2bf35611ed447dd8a 0 f4e000a253ec4fa5a916c073620e01e6 RX(theta₀) f38a32c351444ea2bf35611ed447dd8a--f4e000a253ec4fa5a916c073620e01e6 c57bf005a8474b489ef676f0ab9deabb 1 fce6b77f710c4780b565c8f8fab91d1d RY(theta₃) f4e000a253ec4fa5a916c073620e01e6--fce6b77f710c4780b565c8f8fab91d1d 2581bdb4e301498aabe624cce01d462e RX(theta₆) fce6b77f710c4780b565c8f8fab91d1d--2581bdb4e301498aabe624cce01d462e d5be16e826ee424e82818767de59e34a 2581bdb4e301498aabe624cce01d462e--d5be16e826ee424e82818767de59e34a fd3cf653cc294d96b2d0430d162d734e d5be16e826ee424e82818767de59e34a--fd3cf653cc294d96b2d0430d162d734e 21fd01c9a1844295a229259206dc6259 RX(theta₉) fd3cf653cc294d96b2d0430d162d734e--21fd01c9a1844295a229259206dc6259 6cf8943e7f77409b8ef0c86fdb5fc60a RY(theta₁₂) 21fd01c9a1844295a229259206dc6259--6cf8943e7f77409b8ef0c86fdb5fc60a 0d57b0e01b70447f855b1f76a24966dd RX(theta₁₅) 6cf8943e7f77409b8ef0c86fdb5fc60a--0d57b0e01b70447f855b1f76a24966dd ee37e4fa4bc24589ba4424585a773bac 0d57b0e01b70447f855b1f76a24966dd--ee37e4fa4bc24589ba4424585a773bac b320be2870ed41b0a92fc36950066189 ee37e4fa4bc24589ba4424585a773bac--b320be2870ed41b0a92fc36950066189 67c272e05b4f4657bd7e98edf43c259d b320be2870ed41b0a92fc36950066189--67c272e05b4f4657bd7e98edf43c259d 5e2a1bb5479843f5917f1a382876b95b fa71c91f7f254c628c00ea4634bd898b RX(theta₁) c57bf005a8474b489ef676f0ab9deabb--fa71c91f7f254c628c00ea4634bd898b c6d6fdea289e4f918e8352db234b1227 2 9c6aa0d304fd486e83bec4b87b7bc22c RY(theta₄) fa71c91f7f254c628c00ea4634bd898b--9c6aa0d304fd486e83bec4b87b7bc22c 23ad1d1a0f024eef8e840333220bc82f RX(theta₇) 9c6aa0d304fd486e83bec4b87b7bc22c--23ad1d1a0f024eef8e840333220bc82f a6d37c9e695f4d9d8bb7da2b056ad6df X 23ad1d1a0f024eef8e840333220bc82f--a6d37c9e695f4d9d8bb7da2b056ad6df a6d37c9e695f4d9d8bb7da2b056ad6df--d5be16e826ee424e82818767de59e34a ae934c7fa69e484f8e6b25008642e375 a6d37c9e695f4d9d8bb7da2b056ad6df--ae934c7fa69e484f8e6b25008642e375 537962aa93e24a5ea3bb0a1267656099 RX(theta₁₀) ae934c7fa69e484f8e6b25008642e375--537962aa93e24a5ea3bb0a1267656099 8a4dc4dc125f4a7fa31bb36c8eab91ea RY(theta₁₃) 537962aa93e24a5ea3bb0a1267656099--8a4dc4dc125f4a7fa31bb36c8eab91ea f1a14f1aa16b42b0b6f42fdee08b8679 RX(theta₁₆) 8a4dc4dc125f4a7fa31bb36c8eab91ea--f1a14f1aa16b42b0b6f42fdee08b8679 bd7d63099040419e9525b228d013e30a X f1a14f1aa16b42b0b6f42fdee08b8679--bd7d63099040419e9525b228d013e30a bd7d63099040419e9525b228d013e30a--ee37e4fa4bc24589ba4424585a773bac 039481558afb44d99543eb7fe58aa6c0 bd7d63099040419e9525b228d013e30a--039481558afb44d99543eb7fe58aa6c0 039481558afb44d99543eb7fe58aa6c0--5e2a1bb5479843f5917f1a382876b95b c8d925fef10d4e47a51d1a56fb615366 620c5bb340dd45b1baaf8aded847a6da RX(theta₂) c6d6fdea289e4f918e8352db234b1227--620c5bb340dd45b1baaf8aded847a6da b20fe1d80db34cc68956466a88a96fac RY(theta₅) 620c5bb340dd45b1baaf8aded847a6da--b20fe1d80db34cc68956466a88a96fac b0b9930dd1254fc4af70b6eefa5d0082 RX(theta₈) b20fe1d80db34cc68956466a88a96fac--b0b9930dd1254fc4af70b6eefa5d0082 df0d9b36d9b84268a58e58d69708f96a b0b9930dd1254fc4af70b6eefa5d0082--df0d9b36d9b84268a58e58d69708f96a 3915810bb54b49efa834e7934f8ec409 X df0d9b36d9b84268a58e58d69708f96a--3915810bb54b49efa834e7934f8ec409 3915810bb54b49efa834e7934f8ec409--ae934c7fa69e484f8e6b25008642e375 dbc4cd5e54aa408e8181c22adf05d311 RX(theta₁₁) 3915810bb54b49efa834e7934f8ec409--dbc4cd5e54aa408e8181c22adf05d311 ba122da4dc084e63b86fa27971bc495e RY(theta₁₄) dbc4cd5e54aa408e8181c22adf05d311--ba122da4dc084e63b86fa27971bc495e 1496ab7f3c8b46f5bc5f319683573f7b RX(theta₁₇) ba122da4dc084e63b86fa27971bc495e--1496ab7f3c8b46f5bc5f319683573f7b 94857ec612ce488b9cc95c7c16bdf1d7 1496ab7f3c8b46f5bc5f319683573f7b--94857ec612ce488b9cc95c7c16bdf1d7 cfff9adb60fe442d88cb81f419b6f45e X 94857ec612ce488b9cc95c7c16bdf1d7--cfff9adb60fe442d88cb81f419b6f45e cfff9adb60fe442d88cb81f419b6f45e--039481558afb44d99543eb7fe58aa6c0 cfff9adb60fe442d88cb81f419b6f45e--c8d925fef10d4e47a51d1a56fb615366

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 09c2495bf0eb484eb2d8de185446dbf1 0 3c903317dffd46dba3697e92622948f8 RX(phi₀) 09c2495bf0eb484eb2d8de185446dbf1--3c903317dffd46dba3697e92622948f8 784c0fb8d6fe4817aac8be789aadf666 1 4c3fffbb2e6e46db8bcf89da8875c5a7 RY(phi₃) 3c903317dffd46dba3697e92622948f8--4c3fffbb2e6e46db8bcf89da8875c5a7 785c01acaa5846069b237539e06570ae RX(phi₆) 4c3fffbb2e6e46db8bcf89da8875c5a7--785c01acaa5846069b237539e06570ae 44f918ee88034ad0bff8922a191beb6e 785c01acaa5846069b237539e06570ae--44f918ee88034ad0bff8922a191beb6e 198d44b6fc194c64bdf5135002d9406e 44f918ee88034ad0bff8922a191beb6e--198d44b6fc194c64bdf5135002d9406e 7dabff5313a041049c018b7b99d975dc RX(phi₉) 198d44b6fc194c64bdf5135002d9406e--7dabff5313a041049c018b7b99d975dc 71810893e9cc420baf8925f3da98c6af RY(phi₁₂) 7dabff5313a041049c018b7b99d975dc--71810893e9cc420baf8925f3da98c6af 2c8da7d9dcff4d81b70f28ac1aed58b2 RX(phi₁₅) 71810893e9cc420baf8925f3da98c6af--2c8da7d9dcff4d81b70f28ac1aed58b2 aedb1f0aa6814db4bc26dba21ae054b8 2c8da7d9dcff4d81b70f28ac1aed58b2--aedb1f0aa6814db4bc26dba21ae054b8 62d87373b68f4ae09377087d7dbcee81 aedb1f0aa6814db4bc26dba21ae054b8--62d87373b68f4ae09377087d7dbcee81 ed74d87a5dc648ba88876be653fe1d0c 62d87373b68f4ae09377087d7dbcee81--ed74d87a5dc648ba88876be653fe1d0c 6c4a9516964b492aab1da14613ae15c9 3f7d4fa209cc40efb27f09ffd72990d3 RX(phi₁) 784c0fb8d6fe4817aac8be789aadf666--3f7d4fa209cc40efb27f09ffd72990d3 adb0ccef0f5641f4a50d65598c9ed622 2 1a1cffb0115e46be9012dd1e34451003 RY(phi₄) 3f7d4fa209cc40efb27f09ffd72990d3--1a1cffb0115e46be9012dd1e34451003 daadca9761a746a6816313d80494a14e RX(phi₇) 1a1cffb0115e46be9012dd1e34451003--daadca9761a746a6816313d80494a14e 85ccdf4e591f415e8af4ee0225072668 PHASE(phi_ent₀) daadca9761a746a6816313d80494a14e--85ccdf4e591f415e8af4ee0225072668 85ccdf4e591f415e8af4ee0225072668--44f918ee88034ad0bff8922a191beb6e 486cb660afb24203b7a887ad4f4c988a 85ccdf4e591f415e8af4ee0225072668--486cb660afb24203b7a887ad4f4c988a 2d1317028f974e4a898be54e5a063fc6 RX(phi₁₀) 486cb660afb24203b7a887ad4f4c988a--2d1317028f974e4a898be54e5a063fc6 43d2dfca0d004d098a7ea6506ea17fc4 RY(phi₁₃) 2d1317028f974e4a898be54e5a063fc6--43d2dfca0d004d098a7ea6506ea17fc4 63da273fa5fa47a7a8adaeaba02bbbe1 RX(phi₁₆) 43d2dfca0d004d098a7ea6506ea17fc4--63da273fa5fa47a7a8adaeaba02bbbe1 e07ef94cae73400ba18ab47d488debe3 PHASE(phi_ent₂) 63da273fa5fa47a7a8adaeaba02bbbe1--e07ef94cae73400ba18ab47d488debe3 e07ef94cae73400ba18ab47d488debe3--aedb1f0aa6814db4bc26dba21ae054b8 83e474019f20435ca0cd428556f39583 e07ef94cae73400ba18ab47d488debe3--83e474019f20435ca0cd428556f39583 83e474019f20435ca0cd428556f39583--6c4a9516964b492aab1da14613ae15c9 589aff6a87aa47cabcf3b265faa369ab 425f2a1b31064537aecc2c75883980a0 RX(phi₂) adb0ccef0f5641f4a50d65598c9ed622--425f2a1b31064537aecc2c75883980a0 bb8255ddcde840a587df56b8a865b0f3 RY(phi₅) 425f2a1b31064537aecc2c75883980a0--bb8255ddcde840a587df56b8a865b0f3 62669053ebbe4c1c88ca4f1bae145554 RX(phi₈) bb8255ddcde840a587df56b8a865b0f3--62669053ebbe4c1c88ca4f1bae145554 ac9c00266c0d4d17b51f23aeb6b7c675 62669053ebbe4c1c88ca4f1bae145554--ac9c00266c0d4d17b51f23aeb6b7c675 b21de24d0ed74c0c856c65ad6df1e65d PHASE(phi_ent₁) ac9c00266c0d4d17b51f23aeb6b7c675--b21de24d0ed74c0c856c65ad6df1e65d b21de24d0ed74c0c856c65ad6df1e65d--486cb660afb24203b7a887ad4f4c988a 19945e7f2d5d491b942f324680141988 RX(phi₁₁) b21de24d0ed74c0c856c65ad6df1e65d--19945e7f2d5d491b942f324680141988 294bb1e6eb08429a959b31973bc85a04 RY(phi₁₄) 19945e7f2d5d491b942f324680141988--294bb1e6eb08429a959b31973bc85a04 c1198d5baa6d4506be0425de2aded73d RX(phi₁₇) 294bb1e6eb08429a959b31973bc85a04--c1198d5baa6d4506be0425de2aded73d 4d667fbb9dd3419bbc289757e7f993aa c1198d5baa6d4506be0425de2aded73d--4d667fbb9dd3419bbc289757e7f993aa 2fe329bc3bb24e9784369a25f16b3a81 PHASE(phi_ent₃) 4d667fbb9dd3419bbc289757e7f993aa--2fe329bc3bb24e9784369a25f16b3a81 2fe329bc3bb24e9784369a25f16b3a81--83e474019f20435ca0cd428556f39583 2fe329bc3bb24e9784369a25f16b3a81--589aff6a87aa47cabcf3b265faa369ab

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_f9e663ea98bc4919b35d42502461dd53 cluster_43baff3d5fbf4d708cb83c8c89301aa6 1406789865b549edbedc34b73ec1de46 0 bdf0e4b3bae34bbc805e5a7e0375db21 RX(theta₀) 1406789865b549edbedc34b73ec1de46--bdf0e4b3bae34bbc805e5a7e0375db21 befde7d0ae064090aaf96e6055a8c7ed 1 0eb12edb6e2f4df2a3fa1686e5ba6b1e RY(theta₃) bdf0e4b3bae34bbc805e5a7e0375db21--0eb12edb6e2f4df2a3fa1686e5ba6b1e d609c624c6e342b8be8c46190de1df3b RX(theta₆) 0eb12edb6e2f4df2a3fa1686e5ba6b1e--d609c624c6e342b8be8c46190de1df3b ab76da85b7944444a2b449b22477686c HamEvo d609c624c6e342b8be8c46190de1df3b--ab76da85b7944444a2b449b22477686c f75b82ee91f540b89d137d1c03f4d9ba RX(theta₉) ab76da85b7944444a2b449b22477686c--f75b82ee91f540b89d137d1c03f4d9ba 5bdad9d2575b4c1eac3d280964bf218b RY(theta₁₂) f75b82ee91f540b89d137d1c03f4d9ba--5bdad9d2575b4c1eac3d280964bf218b 1e9f164d062b42e29b0cba1ce6c3ce99 RX(theta₁₅) 5bdad9d2575b4c1eac3d280964bf218b--1e9f164d062b42e29b0cba1ce6c3ce99 4d60f477d84d41a48926d5e85226e33c HamEvo 1e9f164d062b42e29b0cba1ce6c3ce99--4d60f477d84d41a48926d5e85226e33c b4d60ee8aba04c48bc2370e574a81153 4d60f477d84d41a48926d5e85226e33c--b4d60ee8aba04c48bc2370e574a81153 5635d33e31694795905c84b8df233fc9 a82bf97f4e8d40018b10ddb505ac9356 RX(theta₁) befde7d0ae064090aaf96e6055a8c7ed--a82bf97f4e8d40018b10ddb505ac9356 fd885be1ef5545b2b3e6bd2c3c03587c 2 c8ef8cdbec614b968241669c847b7d47 RY(theta₄) a82bf97f4e8d40018b10ddb505ac9356--c8ef8cdbec614b968241669c847b7d47 d9966dfe265b402ba4c3e1f4026ddf2c RX(theta₇) c8ef8cdbec614b968241669c847b7d47--d9966dfe265b402ba4c3e1f4026ddf2c 4593f64a04c0474b98db677098864f97 t = theta_t₀ d9966dfe265b402ba4c3e1f4026ddf2c--4593f64a04c0474b98db677098864f97 b04b648e666d4f38a5846ed015ad8c64 RX(theta₁₀) 4593f64a04c0474b98db677098864f97--b04b648e666d4f38a5846ed015ad8c64 280039e70b6e4dcdb439e444fd4470eb RY(theta₁₃) b04b648e666d4f38a5846ed015ad8c64--280039e70b6e4dcdb439e444fd4470eb 9ef908e8aaa14eaa83186e427f18d73c RX(theta₁₆) 280039e70b6e4dcdb439e444fd4470eb--9ef908e8aaa14eaa83186e427f18d73c 7a95c929a45a435a90954c58b199c162 t = theta_t₁ 9ef908e8aaa14eaa83186e427f18d73c--7a95c929a45a435a90954c58b199c162 7a95c929a45a435a90954c58b199c162--5635d33e31694795905c84b8df233fc9 45b7804123c84295bf381cec62050fe2 ab02d232877c42b2be4ac4b95cc4eadb RX(theta₂) fd885be1ef5545b2b3e6bd2c3c03587c--ab02d232877c42b2be4ac4b95cc4eadb f8cdf7e8e1b641bf8e3666240280383c RY(theta₅) ab02d232877c42b2be4ac4b95cc4eadb--f8cdf7e8e1b641bf8e3666240280383c b6531b0a723c4766bb136be8aa50cfdf RX(theta₈) f8cdf7e8e1b641bf8e3666240280383c--b6531b0a723c4766bb136be8aa50cfdf 8f49f8ff53aa484d891067a272b162e2 b6531b0a723c4766bb136be8aa50cfdf--8f49f8ff53aa484d891067a272b162e2 fd57047361b94fdaa2c31e16c21495d3 RX(theta₁₁) 8f49f8ff53aa484d891067a272b162e2--fd57047361b94fdaa2c31e16c21495d3 d46498c828484abc9270bca071617aab RY(theta₁₄) fd57047361b94fdaa2c31e16c21495d3--d46498c828484abc9270bca071617aab d50e212df4744a33bafe2d19aecac689 RX(theta₁₇) d46498c828484abc9270bca071617aab--d50e212df4744a33bafe2d19aecac689 0f9ea5cb03f349b0b2b52f041909d1b9 d50e212df4744a33bafe2d19aecac689--0f9ea5cb03f349b0b2b52f041909d1b9 0f9ea5cb03f349b0b2b52f041909d1b9--45b7804123c84295bf381cec62050fe2

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_763cb86d5f6e4efcaf5c6fba8e1fe445 cluster_742d5c3b46e449d4a5ff7f4c01c4d85b fb04283798d14876b0faa0b1bf50763a 0 9f9a86906f254b2eb8f1a9ca0df5368f RX(theta₀) fb04283798d14876b0faa0b1bf50763a--9f9a86906f254b2eb8f1a9ca0df5368f a6e415f1f1324ee78547b819ec44f51c 1 8abbda71bbf74cfaa3be1dcab378e2c0 RY(theta₆) 9f9a86906f254b2eb8f1a9ca0df5368f--8abbda71bbf74cfaa3be1dcab378e2c0 a37a63c0035e45919432102daecd8bcd RX(theta₁₂) 8abbda71bbf74cfaa3be1dcab378e2c0--a37a63c0035e45919432102daecd8bcd adbc223800d74c8e88c207f5f2cbbb2f a37a63c0035e45919432102daecd8bcd--adbc223800d74c8e88c207f5f2cbbb2f 83a937a773a2450aa87e97223dea14d7 RX(theta₁₈) adbc223800d74c8e88c207f5f2cbbb2f--83a937a773a2450aa87e97223dea14d7 1c240306844c46e0aa3ff69e0641ffb2 RY(theta₂₄) 83a937a773a2450aa87e97223dea14d7--1c240306844c46e0aa3ff69e0641ffb2 7bacefe468eb45c6b62ea8bca93b0ffb RX(theta₃₀) 1c240306844c46e0aa3ff69e0641ffb2--7bacefe468eb45c6b62ea8bca93b0ffb 53262323435e4b32b0bfce9f61b9cb0e 7bacefe468eb45c6b62ea8bca93b0ffb--53262323435e4b32b0bfce9f61b9cb0e ab2e3b1fd653486ca3edd4e1ed4a5a05 53262323435e4b32b0bfce9f61b9cb0e--ab2e3b1fd653486ca3edd4e1ed4a5a05 a4c8234cf90443c9a98dfa50f82293f8 daf81e08a4b9424598ddd5e38ed90d90 RX(theta₁) a6e415f1f1324ee78547b819ec44f51c--daf81e08a4b9424598ddd5e38ed90d90 a0ec78eb65324b228bb9ae29d22d3c5e 2 83307a2402de45bb85cd6495529039bb RY(theta₇) daf81e08a4b9424598ddd5e38ed90d90--83307a2402de45bb85cd6495529039bb d2d4a8ebd9d24567911bf4d345b2a90e RX(theta₁₃) 83307a2402de45bb85cd6495529039bb--d2d4a8ebd9d24567911bf4d345b2a90e cec11cdc15fc4418b8a40e875b883642 d2d4a8ebd9d24567911bf4d345b2a90e--cec11cdc15fc4418b8a40e875b883642 fe3ae893f1ec478a9fd2c9e209edfeb5 RX(theta₁₉) cec11cdc15fc4418b8a40e875b883642--fe3ae893f1ec478a9fd2c9e209edfeb5 293dabe58c9c40dba6846219bad2eff6 RY(theta₂₅) fe3ae893f1ec478a9fd2c9e209edfeb5--293dabe58c9c40dba6846219bad2eff6 c743419b6cee45a5be6082a2254f2e9a RX(theta₃₁) 293dabe58c9c40dba6846219bad2eff6--c743419b6cee45a5be6082a2254f2e9a 6306fc4a4ab24e56acebfccbe588348d c743419b6cee45a5be6082a2254f2e9a--6306fc4a4ab24e56acebfccbe588348d 6306fc4a4ab24e56acebfccbe588348d--a4c8234cf90443c9a98dfa50f82293f8 2acbd51ca28c4f3ab4c5adba5aff2bdc 0763e07733c24b729e24b3b6f0632b84 RX(theta₂) a0ec78eb65324b228bb9ae29d22d3c5e--0763e07733c24b729e24b3b6f0632b84 a0c11dd3151a4bc3b95a3217fd313075 3 0399514bc43840e490a5c1edd64fa88a RY(theta₈) 0763e07733c24b729e24b3b6f0632b84--0399514bc43840e490a5c1edd64fa88a 8a041e47382b4ef4802acc8041b49c9b RX(theta₁₄) 0399514bc43840e490a5c1edd64fa88a--8a041e47382b4ef4802acc8041b49c9b 2ee24809fde04fc5ae9cfda38e8db980 HamEvo 8a041e47382b4ef4802acc8041b49c9b--2ee24809fde04fc5ae9cfda38e8db980 5f1f54cd005f4029a71d9785fb76befe RX(theta₂₀) 2ee24809fde04fc5ae9cfda38e8db980--5f1f54cd005f4029a71d9785fb76befe 55c28158a34a46178eb9c3c39109d4b5 RY(theta₂₆) 5f1f54cd005f4029a71d9785fb76befe--55c28158a34a46178eb9c3c39109d4b5 89bc708823ba4a5fafeb84180bd28c79 RX(theta₃₂) 55c28158a34a46178eb9c3c39109d4b5--89bc708823ba4a5fafeb84180bd28c79 bcab43e86f394836ae6000fb6cd83eef HamEvo 89bc708823ba4a5fafeb84180bd28c79--bcab43e86f394836ae6000fb6cd83eef bcab43e86f394836ae6000fb6cd83eef--2acbd51ca28c4f3ab4c5adba5aff2bdc daab52117ef244cbb2d0875e9629e71d 79bba395f966425db3a2db5f91067b4f RX(theta₃) a0c11dd3151a4bc3b95a3217fd313075--79bba395f966425db3a2db5f91067b4f 06cda9c91137464fbca905dbdd291594 4 89e55785750444a79fb7ead4214fde37 RY(theta₉) 79bba395f966425db3a2db5f91067b4f--89e55785750444a79fb7ead4214fde37 ba0cbdc13a4c429fb592f3d7002c0150 RX(theta₁₅) 89e55785750444a79fb7ead4214fde37--ba0cbdc13a4c429fb592f3d7002c0150 31330a4504064e33b0c77ce09e8c1d3d t = theta_t₀ ba0cbdc13a4c429fb592f3d7002c0150--31330a4504064e33b0c77ce09e8c1d3d 4cf262f88b8b4306ad6aac3d5ddb5285 RX(theta₂₁) 31330a4504064e33b0c77ce09e8c1d3d--4cf262f88b8b4306ad6aac3d5ddb5285 ce6281bdd1d54010b1b5ba8d18193fbe RY(theta₂₇) 4cf262f88b8b4306ad6aac3d5ddb5285--ce6281bdd1d54010b1b5ba8d18193fbe 35189b3a6ef246f5b216879f5b99bbc7 RX(theta₃₃) ce6281bdd1d54010b1b5ba8d18193fbe--35189b3a6ef246f5b216879f5b99bbc7 d375075e9df44936822f8f51e815b2bd t = theta_t₁ 35189b3a6ef246f5b216879f5b99bbc7--d375075e9df44936822f8f51e815b2bd d375075e9df44936822f8f51e815b2bd--daab52117ef244cbb2d0875e9629e71d 7c60ef1813ea41f9bff33559d404ac57 18615b1c20764341be0327aa81fa6b6d RX(theta₄) 06cda9c91137464fbca905dbdd291594--18615b1c20764341be0327aa81fa6b6d d206b9d0ee154de18ea69e9442db13d1 5 446bb09425ea4b5a87bab369312c0f0c RY(theta₁₀) 18615b1c20764341be0327aa81fa6b6d--446bb09425ea4b5a87bab369312c0f0c 5989f71a75914b54b1c098d922ef38f9 RX(theta₁₆) 446bb09425ea4b5a87bab369312c0f0c--5989f71a75914b54b1c098d922ef38f9 bbf1376c0877403cae1c1399c3991be5 5989f71a75914b54b1c098d922ef38f9--bbf1376c0877403cae1c1399c3991be5 4724630182164d279cdbbd8f36f895d9 RX(theta₂₂) bbf1376c0877403cae1c1399c3991be5--4724630182164d279cdbbd8f36f895d9 f4f9536832c74196b7add07dff26d130 RY(theta₂₈) 4724630182164d279cdbbd8f36f895d9--f4f9536832c74196b7add07dff26d130 dd2a74c56f6a4df980526569a2465527 RX(theta₃₄) f4f9536832c74196b7add07dff26d130--dd2a74c56f6a4df980526569a2465527 d737ed190b824c6eb02204fd5d614652 dd2a74c56f6a4df980526569a2465527--d737ed190b824c6eb02204fd5d614652 d737ed190b824c6eb02204fd5d614652--7c60ef1813ea41f9bff33559d404ac57 f6c4d9f1db314fcc88748b01956a6b58 30d1cace05d34396b4d75b969e4033ff RX(theta₅) d206b9d0ee154de18ea69e9442db13d1--30d1cace05d34396b4d75b969e4033ff c09f6a10b4ec4ca986e43f8a73cf4c2d RY(theta₁₁) 30d1cace05d34396b4d75b969e4033ff--c09f6a10b4ec4ca986e43f8a73cf4c2d 1ffe69e1ce3c450ca2e9b39694cf9b0e RX(theta₁₇) c09f6a10b4ec4ca986e43f8a73cf4c2d--1ffe69e1ce3c450ca2e9b39694cf9b0e f2655f648263467ca77e2cce625fa390 1ffe69e1ce3c450ca2e9b39694cf9b0e--f2655f648263467ca77e2cce625fa390 e2bade4cc3454c7bb0547b8301b4e06c RX(theta₂₃) f2655f648263467ca77e2cce625fa390--e2bade4cc3454c7bb0547b8301b4e06c 3f31abd21d72490186b0948d44212058 RY(theta₂₉) e2bade4cc3454c7bb0547b8301b4e06c--3f31abd21d72490186b0948d44212058 731ad78a1e8b49d98568a775a5244d99 RX(theta₃₅) 3f31abd21d72490186b0948d44212058--731ad78a1e8b49d98568a775a5244d99 d62c0b1f6d0545019887a2944bbda2ea 731ad78a1e8b49d98568a775a5244d99--d62c0b1f6d0545019887a2944bbda2ea d62c0b1f6d0545019887a2944bbda2ea--f6c4d9f1db314fcc88748b01956a6b58