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_9bdd034321ea4b5e86f8a3b3e35a6c6d Constant Chebyshev FM cluster_bffbbd6af270445292f5dd9d3cd7d7e3 Constant Fourier FM dedb52ba55384c6db4a2d35a1bdaad51 0 73077a5e9ca44e40a5f41abe5a16361d RX(phi) dedb52ba55384c6db4a2d35a1bdaad51--73077a5e9ca44e40a5f41abe5a16361d 04ef59b3e10e48aca3928df20bd64851 1 5a93532f667e4259916b5f1c8ce2288f RX(acos(phi)) 73077a5e9ca44e40a5f41abe5a16361d--5a93532f667e4259916b5f1c8ce2288f 8e0ce426bb15428da2d6be3fc179e2ad 5a93532f667e4259916b5f1c8ce2288f--8e0ce426bb15428da2d6be3fc179e2ad 722c2b13f1cd4dea93a5c6405edef966 5d3a793fc7014461ad471ac444f40694 RX(phi) 04ef59b3e10e48aca3928df20bd64851--5d3a793fc7014461ad471ac444f40694 0f8127fa9f614474abe856538a93f32d 2 2f307897a5ee4008bd14869ae029984a RX(acos(phi)) 5d3a793fc7014461ad471ac444f40694--2f307897a5ee4008bd14869ae029984a 2f307897a5ee4008bd14869ae029984a--722c2b13f1cd4dea93a5c6405edef966 c85933db9d16476095094ae5f09c1f84 ca3e42f915ee43f49f9822d19b6bd3d9 RX(phi) 0f8127fa9f614474abe856538a93f32d--ca3e42f915ee43f49f9822d19b6bd3d9 b35a7532d72242ba9d2efa5c60f1ac6c RX(acos(phi)) ca3e42f915ee43f49f9822d19b6bd3d9--b35a7532d72242ba9d2efa5c60f1ac6c b35a7532d72242ba9d2efa5c60f1ac6c--c85933db9d16476095094ae5f09c1f84

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_37b76e43bd4140e785e0373bae250221 Constant custom_func FM cluster_05ee7b2d5c584e8a81ba96d42c1e0472 Constant asin FM 4457d86454f04336af4bf33afb1c50d0 0 d1511ba33dd842f5b756cd5cabfc1227 RX(asin(phi)) 4457d86454f04336af4bf33afb1c50d0--d1511ba33dd842f5b756cd5cabfc1227 1b7e60b575884b3cb4823e12afd47325 1 528fe1f39f0b4afd8e9f177f20213501 RX(phi**2 + asin(phi)) d1511ba33dd842f5b756cd5cabfc1227--528fe1f39f0b4afd8e9f177f20213501 bfbf1126da554049bffea74423e5e760 528fe1f39f0b4afd8e9f177f20213501--bfbf1126da554049bffea74423e5e760 fd995f9a5c994ea1b6f284aaff92a188 deb6fce7996d49a59f2a166949cc02a8 RX(asin(phi)) 1b7e60b575884b3cb4823e12afd47325--deb6fce7996d49a59f2a166949cc02a8 2de5c121d7be4ea594f5b454e878ff88 2 c0bdd0f528784a55b7f66da0f375836a RX(phi**2 + asin(phi)) deb6fce7996d49a59f2a166949cc02a8--c0bdd0f528784a55b7f66da0f375836a c0bdd0f528784a55b7f66da0f375836a--fd995f9a5c994ea1b6f284aaff92a188 f31dc78e18b04307b9bce05fe934646d 0894ccf71b524c20bfe7731903a89e18 RX(asin(phi)) 2de5c121d7be4ea594f5b454e878ff88--0894ccf71b524c20bfe7731903a89e18 7670486b106d46b786cc1eb61536884a RX(phi**2 + asin(phi)) 0894ccf71b524c20bfe7731903a89e18--7670486b106d46b786cc1eb61536884a 7670486b106d46b786cc1eb61536884a--f31dc78e18b04307b9bce05fe934646d

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_cc61d2b72e464240bdb748983a2270b7 Exponential Fourier FM cluster_f068b57837b44f168bbee5dc631eb769 Constant Fourier FM cluster_04ac7187ceac41c1b50076b9dbb8e996 Tower Fourier FM 4473b30c125a464eb34ceeacafcf77ee 0 216e349c994d477aa8c081562d77bf10 RX(phi) 4473b30c125a464eb34ceeacafcf77ee--216e349c994d477aa8c081562d77bf10 f5c45a3f604a4910b3f88fb8542f7cbd 1 1d646e947573453abd839547b1c20f2e RX(1.0*phi) 216e349c994d477aa8c081562d77bf10--1d646e947573453abd839547b1c20f2e 712753094d3049faa550afaa2325eaea RX(1.0*phi) 1d646e947573453abd839547b1c20f2e--712753094d3049faa550afaa2325eaea 504598c1181d41f0b7fc49f26d2270ff 712753094d3049faa550afaa2325eaea--504598c1181d41f0b7fc49f26d2270ff 4d1406d1073745a6b0d8f2884a3397f4 41b3a27df0ad41e6a015b8efcd7d93fb RX(phi) f5c45a3f604a4910b3f88fb8542f7cbd--41b3a27df0ad41e6a015b8efcd7d93fb 6a7d5da3a4dc4e1b8cddd51c58b76efe 2 48fe28b648ca4f8f8b2a6773e0b8dedd RX(2.0*phi) 41b3a27df0ad41e6a015b8efcd7d93fb--48fe28b648ca4f8f8b2a6773e0b8dedd eb45715accf34151bfa002b34f80d4e8 RX(2.0*phi) 48fe28b648ca4f8f8b2a6773e0b8dedd--eb45715accf34151bfa002b34f80d4e8 eb45715accf34151bfa002b34f80d4e8--4d1406d1073745a6b0d8f2884a3397f4 708e39a999054ed88c5b22aee537bc3a e32ef531cfad428d8f396b7e63656e79 RX(phi) 6a7d5da3a4dc4e1b8cddd51c58b76efe--e32ef531cfad428d8f396b7e63656e79 6894a40179c24f8ab408509b537d916a 3 3259863fe91d4feeba0a4e36456b3b81 RX(3.0*phi) e32ef531cfad428d8f396b7e63656e79--3259863fe91d4feeba0a4e36456b3b81 7130383384584b37b34618cf6b357f9d RX(4.0*phi) 3259863fe91d4feeba0a4e36456b3b81--7130383384584b37b34618cf6b357f9d 7130383384584b37b34618cf6b357f9d--708e39a999054ed88c5b22aee537bc3a f80b088094444e4b842ccd39e8661873 93908fe5d56141d394c46f0fbd753fd4 RX(phi) 6894a40179c24f8ab408509b537d916a--93908fe5d56141d394c46f0fbd753fd4 ec92a3adc3ed48968e2440ad7f296294 4 cdfe80740c2143a4a3e9489007b6bb26 RX(4.0*phi) 93908fe5d56141d394c46f0fbd753fd4--cdfe80740c2143a4a3e9489007b6bb26 e58e5ff7daf94a9499ab53bfadd49a50 RX(8.0*phi) cdfe80740c2143a4a3e9489007b6bb26--e58e5ff7daf94a9499ab53bfadd49a50 e58e5ff7daf94a9499ab53bfadd49a50--f80b088094444e4b842ccd39e8661873 1c801655dc944f76889cdb0b677ddafc eebbccad852949dfb32425b02cae1de2 RX(phi) ec92a3adc3ed48968e2440ad7f296294--eebbccad852949dfb32425b02cae1de2 af2b0ae0a2664de2bb839f600b368d42 RX(5.0*phi) eebbccad852949dfb32425b02cae1de2--af2b0ae0a2664de2bb839f600b368d42 4be114e7f07044009bccbd3a330602b2 RX(16.0*phi) af2b0ae0a2664de2bb839f600b368d42--4be114e7f07044009bccbd3a330602b2 4be114e7f07044009bccbd3a330602b2--1c801655dc944f76889cdb0b677ddafc

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 24f4ce6b27dc45fba58a8915b0096c14 0 9388eb4dfa484bf68bc369ebf4003beb RX(1.0*acos(phi)) 24f4ce6b27dc45fba58a8915b0096c14--9388eb4dfa484bf68bc369ebf4003beb 5fc4a68256be498799999ae93bfdaba8 1 51f559ece0c74e588e199bcd41bfea3e 9388eb4dfa484bf68bc369ebf4003beb--51f559ece0c74e588e199bcd41bfea3e e768c62fb52b4068addf6492b2744806 f64f188597994220a25ead80f55a576a RX(1.414*acos(phi)) 5fc4a68256be498799999ae93bfdaba8--f64f188597994220a25ead80f55a576a 7e49be8e98de473cb79b0094ee52a4c2 2 f64f188597994220a25ead80f55a576a--e768c62fb52b4068addf6492b2744806 d83136d848e744a6b8e3b26a047cdb9b dedbc8db28bf4339a64b3dbb99fe1de8 RX(1.732*acos(phi)) 7e49be8e98de473cb79b0094ee52a4c2--dedbc8db28bf4339a64b3dbb99fe1de8 4ba9ee5480aa4d7ea9c6cd4941a23dbf 3 dedbc8db28bf4339a64b3dbb99fe1de8--d83136d848e744a6b8e3b26a047cdb9b 567f924d344446f4a7b38b5e70d68b02 b3d30d9aaf494a6d8295e69f6cde3492 RX(2.0*acos(phi)) 4ba9ee5480aa4d7ea9c6cd4941a23dbf--b3d30d9aaf494a6d8295e69f6cde3492 395391d799964f3fab296aa298ccdb12 4 b3d30d9aaf494a6d8295e69f6cde3492--567f924d344446f4a7b38b5e70d68b02 0806f2f5899c4d1a910444fe12eec46c 168d9e2e262a48669706119148204833 RX(2.236*acos(phi)) 395391d799964f3fab296aa298ccdb12--168d9e2e262a48669706119148204833 168d9e2e262a48669706119148204833--0806f2f5899c4d1a910444fe12eec46c

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 f59e92d5cb0c4566b9a2e004971ae8d5 0 580c6cc17fc440f48a5511dd71ff8a88 RY(80.0*acos(0.667*x + 1.667)) f59e92d5cb0c4566b9a2e004971ae8d5--580c6cc17fc440f48a5511dd71ff8a88 f33ba6ad47b9431cba2b53a573a1eb24 1 4b2ca6275a6b472f9927635830c5c375 580c6cc17fc440f48a5511dd71ff8a88--4b2ca6275a6b472f9927635830c5c375 87636a2b39684ea9b24b51f8d3c7123b 4089deda20674c2b9619e0775e4b9007 RY(40.0*acos(0.667*x + 1.667)) f33ba6ad47b9431cba2b53a573a1eb24--4089deda20674c2b9619e0775e4b9007 58027cf9506c4cbcae0b29b39e514f6b 2 4089deda20674c2b9619e0775e4b9007--87636a2b39684ea9b24b51f8d3c7123b e3bf57ba79214db199035f358cce4be1 83e53199dc974b19af9db16c700412af RY(20.0*acos(0.667*x + 1.667)) 58027cf9506c4cbcae0b29b39e514f6b--83e53199dc974b19af9db16c700412af f374aa32ec2d4833a1f4a97e5b99d8a6 3 83e53199dc974b19af9db16c700412af--e3bf57ba79214db199035f358cce4be1 d28d03e56d7f4cf3aad8a86fb5d02cc8 178a87d9c56f4f7b95406ce4f1a8bed4 RY(10.0*acos(0.667*x + 1.667)) f374aa32ec2d4833a1f4a97e5b99d8a6--178a87d9c56f4f7b95406ce4f1a8bed4 8a23d5aa94204be2bb816a7e5a049fd7 4 178a87d9c56f4f7b95406ce4f1a8bed4--d28d03e56d7f4cf3aad8a86fb5d02cc8 c791bb3106ee44dfb5e5969a72cecde0 f42bd42f72f54906ae3b25a08dd7140c RY(5.0*acos(0.667*x + 1.667)) 8a23d5aa94204be2bb816a7e5a049fd7--f42bd42f72f54906ae3b25a08dd7140c f42bd42f72f54906ae3b25a08dd7140c--c791bb3106ee44dfb5e5969a72cecde0

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 d2259a55539048c6a6a2276f8e8ff46d 0 fd68a7e067904a3fabd9cad4ab990839 RX(theta₀) d2259a55539048c6a6a2276f8e8ff46d--fd68a7e067904a3fabd9cad4ab990839 a52ba28c7c00472f92a9dd11e5339ada 1 3b1e8c8ad7c0473186c5cccdd05235cd RY(theta₃) fd68a7e067904a3fabd9cad4ab990839--3b1e8c8ad7c0473186c5cccdd05235cd cf8c82eb0aba4800b4c5a96daa4bee16 RX(theta₆) 3b1e8c8ad7c0473186c5cccdd05235cd--cf8c82eb0aba4800b4c5a96daa4bee16 2e50841badd9459f8ee5450d4d8405b0 cf8c82eb0aba4800b4c5a96daa4bee16--2e50841badd9459f8ee5450d4d8405b0 3f640339f5eb40118e071e0753306ba5 2e50841badd9459f8ee5450d4d8405b0--3f640339f5eb40118e071e0753306ba5 070319e8d44b4176b1890b68e8d0bac1 RX(theta₉) 3f640339f5eb40118e071e0753306ba5--070319e8d44b4176b1890b68e8d0bac1 7574ce13943f4350bb5fb24ec635e883 RY(theta₁₂) 070319e8d44b4176b1890b68e8d0bac1--7574ce13943f4350bb5fb24ec635e883 03ab0f47e67e4647a743fb0527f2f061 RX(theta₁₅) 7574ce13943f4350bb5fb24ec635e883--03ab0f47e67e4647a743fb0527f2f061 dbf078c162df4ea687ad278805af7567 03ab0f47e67e4647a743fb0527f2f061--dbf078c162df4ea687ad278805af7567 7e7241c130d04f9fb32d7183dcab1734 dbf078c162df4ea687ad278805af7567--7e7241c130d04f9fb32d7183dcab1734 d23af25c780848f6a445ecba728d56e1 7e7241c130d04f9fb32d7183dcab1734--d23af25c780848f6a445ecba728d56e1 88f405e20a264bcea64f29e235814e7e 5bda83cf84334f6490f11948ddf784d6 RX(theta₁) a52ba28c7c00472f92a9dd11e5339ada--5bda83cf84334f6490f11948ddf784d6 4765fcd8c3bd444ebcc74430aab81631 2 62328fee5df74d9aacdf7cad7c1d7102 RY(theta₄) 5bda83cf84334f6490f11948ddf784d6--62328fee5df74d9aacdf7cad7c1d7102 89b0eabfc2ea42a1a5801b96bbbe0e29 RX(theta₇) 62328fee5df74d9aacdf7cad7c1d7102--89b0eabfc2ea42a1a5801b96bbbe0e29 929b43df1989476c98b0bd0af7ae2b7a X 89b0eabfc2ea42a1a5801b96bbbe0e29--929b43df1989476c98b0bd0af7ae2b7a 929b43df1989476c98b0bd0af7ae2b7a--2e50841badd9459f8ee5450d4d8405b0 59eadf3ea15748f0b24cde44dc9a196f 929b43df1989476c98b0bd0af7ae2b7a--59eadf3ea15748f0b24cde44dc9a196f 3ae58632a1884c39bb93e3d9948887e4 RX(theta₁₀) 59eadf3ea15748f0b24cde44dc9a196f--3ae58632a1884c39bb93e3d9948887e4 75b2e81d6d0646a6985b05a73cad4625 RY(theta₁₃) 3ae58632a1884c39bb93e3d9948887e4--75b2e81d6d0646a6985b05a73cad4625 5d1ea5785c9944189c2794219b1277f7 RX(theta₁₆) 75b2e81d6d0646a6985b05a73cad4625--5d1ea5785c9944189c2794219b1277f7 14d3553f1282488781b24c62334fc8c7 X 5d1ea5785c9944189c2794219b1277f7--14d3553f1282488781b24c62334fc8c7 14d3553f1282488781b24c62334fc8c7--dbf078c162df4ea687ad278805af7567 0007afce5f6546baaff3fd1321f3186a 14d3553f1282488781b24c62334fc8c7--0007afce5f6546baaff3fd1321f3186a 0007afce5f6546baaff3fd1321f3186a--88f405e20a264bcea64f29e235814e7e 4192dab7c42d487fa1c77cf284318d75 84c1f8c7158f4af9a5e87161dc8b7269 RX(theta₂) 4765fcd8c3bd444ebcc74430aab81631--84c1f8c7158f4af9a5e87161dc8b7269 eda6055ec5cc4d5689b1fac26cbb9722 RY(theta₅) 84c1f8c7158f4af9a5e87161dc8b7269--eda6055ec5cc4d5689b1fac26cbb9722 a00847073a054cf9b0ca16cb5b6f2825 RX(theta₈) eda6055ec5cc4d5689b1fac26cbb9722--a00847073a054cf9b0ca16cb5b6f2825 db5794eda399486c8452f85fd8122f6f a00847073a054cf9b0ca16cb5b6f2825--db5794eda399486c8452f85fd8122f6f 26d6f609c24640f1b068b107ee24da8f X db5794eda399486c8452f85fd8122f6f--26d6f609c24640f1b068b107ee24da8f 26d6f609c24640f1b068b107ee24da8f--59eadf3ea15748f0b24cde44dc9a196f a40d8080eb414603bfce2dfefc72d7ff RX(theta₁₁) 26d6f609c24640f1b068b107ee24da8f--a40d8080eb414603bfce2dfefc72d7ff f959251a2dac4de080f0679390bcfeda RY(theta₁₄) a40d8080eb414603bfce2dfefc72d7ff--f959251a2dac4de080f0679390bcfeda 47bb2fe55f1e43d188e466f5ba417105 RX(theta₁₇) f959251a2dac4de080f0679390bcfeda--47bb2fe55f1e43d188e466f5ba417105 e106e8884b954c358d2a89e4ac075332 47bb2fe55f1e43d188e466f5ba417105--e106e8884b954c358d2a89e4ac075332 1925b14d4fb74e3d9211669cd419e011 X e106e8884b954c358d2a89e4ac075332--1925b14d4fb74e3d9211669cd419e011 1925b14d4fb74e3d9211669cd419e011--0007afce5f6546baaff3fd1321f3186a 1925b14d4fb74e3d9211669cd419e011--4192dab7c42d487fa1c77cf284318d75

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 61bebd38e5d94ad49172e0b547917b00 0 eb5d79deabca44288417a9601fc7e77d RX(phi₀) 61bebd38e5d94ad49172e0b547917b00--eb5d79deabca44288417a9601fc7e77d aad8bd092d6f496aa1c3d1c5b25fa659 1 c2b8f51e85fe4aadbf58983db73e8cda RY(phi₃) eb5d79deabca44288417a9601fc7e77d--c2b8f51e85fe4aadbf58983db73e8cda 70442ef111d24d439e386edba16408c4 RX(phi₆) c2b8f51e85fe4aadbf58983db73e8cda--70442ef111d24d439e386edba16408c4 9287a22c0a1949ad9074dd6c1980cea4 70442ef111d24d439e386edba16408c4--9287a22c0a1949ad9074dd6c1980cea4 84773c06045b427f97ddd364ba8646d2 9287a22c0a1949ad9074dd6c1980cea4--84773c06045b427f97ddd364ba8646d2 2d92482973164b4291d90fadde7f404f RX(phi₉) 84773c06045b427f97ddd364ba8646d2--2d92482973164b4291d90fadde7f404f fcb77d20877949638bbcaaa600f38437 RY(phi₁₂) 2d92482973164b4291d90fadde7f404f--fcb77d20877949638bbcaaa600f38437 de4f2ff0f4084dd2955487141e39d678 RX(phi₁₅) fcb77d20877949638bbcaaa600f38437--de4f2ff0f4084dd2955487141e39d678 847e91f0ee5e45e08ca22ab1861057e7 de4f2ff0f4084dd2955487141e39d678--847e91f0ee5e45e08ca22ab1861057e7 fee5bf0a5ec44066812b289e8969cc78 847e91f0ee5e45e08ca22ab1861057e7--fee5bf0a5ec44066812b289e8969cc78 10ae12d729e6455da060e82a5ac72032 fee5bf0a5ec44066812b289e8969cc78--10ae12d729e6455da060e82a5ac72032 ced4d9af081e491dbe43490bb6ac9cb2 fb9436a4da7e475f8b40ad64fbc4daf3 RX(phi₁) aad8bd092d6f496aa1c3d1c5b25fa659--fb9436a4da7e475f8b40ad64fbc4daf3 2ad1af5f9de042dba509b9e19054c68e 2 3ca2248c0f3e4684b14f856595e167cc RY(phi₄) fb9436a4da7e475f8b40ad64fbc4daf3--3ca2248c0f3e4684b14f856595e167cc 3cb5b046d45d470ea2b811859033d405 RX(phi₇) 3ca2248c0f3e4684b14f856595e167cc--3cb5b046d45d470ea2b811859033d405 eae61a38b17047fd9823ccdff5b36fe3 PHASE(phi_ent₀) 3cb5b046d45d470ea2b811859033d405--eae61a38b17047fd9823ccdff5b36fe3 eae61a38b17047fd9823ccdff5b36fe3--9287a22c0a1949ad9074dd6c1980cea4 7047d755140949d99a48a6d80f2b5bb5 eae61a38b17047fd9823ccdff5b36fe3--7047d755140949d99a48a6d80f2b5bb5 ed2af1677e0f4dacbf59122a7fe0806f RX(phi₁₀) 7047d755140949d99a48a6d80f2b5bb5--ed2af1677e0f4dacbf59122a7fe0806f 39d1f6122c00403db723b9c03d571098 RY(phi₁₃) ed2af1677e0f4dacbf59122a7fe0806f--39d1f6122c00403db723b9c03d571098 2c64adaba3ac4e18a6cd8788113d0d58 RX(phi₁₆) 39d1f6122c00403db723b9c03d571098--2c64adaba3ac4e18a6cd8788113d0d58 5bb3ea58520f4b989dc164e554aa3cfb PHASE(phi_ent₂) 2c64adaba3ac4e18a6cd8788113d0d58--5bb3ea58520f4b989dc164e554aa3cfb 5bb3ea58520f4b989dc164e554aa3cfb--847e91f0ee5e45e08ca22ab1861057e7 533278c33dd54a06ada463cfb74232e3 5bb3ea58520f4b989dc164e554aa3cfb--533278c33dd54a06ada463cfb74232e3 533278c33dd54a06ada463cfb74232e3--ced4d9af081e491dbe43490bb6ac9cb2 c260b5b95c9547a4a50fff5c359cf49b 82e0facfdedf493491abef373d814a60 RX(phi₂) 2ad1af5f9de042dba509b9e19054c68e--82e0facfdedf493491abef373d814a60 ef35ee22d89c49b6ac0262d0ee0f80e6 RY(phi₅) 82e0facfdedf493491abef373d814a60--ef35ee22d89c49b6ac0262d0ee0f80e6 03df4b570e744826a6312aed94505925 RX(phi₈) ef35ee22d89c49b6ac0262d0ee0f80e6--03df4b570e744826a6312aed94505925 2514c17de967427da69a48193cd70c5c 03df4b570e744826a6312aed94505925--2514c17de967427da69a48193cd70c5c 83def89e63e1438f97b3ce8fa61f609e PHASE(phi_ent₁) 2514c17de967427da69a48193cd70c5c--83def89e63e1438f97b3ce8fa61f609e 83def89e63e1438f97b3ce8fa61f609e--7047d755140949d99a48a6d80f2b5bb5 668fe63b9d12408587cbc23c2cb19bfe RX(phi₁₁) 83def89e63e1438f97b3ce8fa61f609e--668fe63b9d12408587cbc23c2cb19bfe 82a72267debe4fd1be4889089f71fbf4 RY(phi₁₄) 668fe63b9d12408587cbc23c2cb19bfe--82a72267debe4fd1be4889089f71fbf4 e93f776311d64f14b3d7d65535e7dafe RX(phi₁₇) 82a72267debe4fd1be4889089f71fbf4--e93f776311d64f14b3d7d65535e7dafe 21cffc268f7f4cfbaacc8c09a10b5f0f e93f776311d64f14b3d7d65535e7dafe--21cffc268f7f4cfbaacc8c09a10b5f0f 76309e6b70cd45ec8aacd43a2bbf771b PHASE(phi_ent₃) 21cffc268f7f4cfbaacc8c09a10b5f0f--76309e6b70cd45ec8aacd43a2bbf771b 76309e6b70cd45ec8aacd43a2bbf771b--533278c33dd54a06ada463cfb74232e3 76309e6b70cd45ec8aacd43a2bbf771b--c260b5b95c9547a4a50fff5c359cf49b

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_09123db1b81449139ca640591f602d50 cluster_4aa71dc301bd433da9b55301e00969aa 99b6a3ca556c4530b684d89da3fb8a6b 0 64539e01f2144eeea162cdff8a347191 RX(theta₀) 99b6a3ca556c4530b684d89da3fb8a6b--64539e01f2144eeea162cdff8a347191 b6e7cd9e4bd44176bb7405530d3da1bb 1 a76072a5f07049829561ea21b4573c6e RY(theta₃) 64539e01f2144eeea162cdff8a347191--a76072a5f07049829561ea21b4573c6e b80cdcace146456b95dbf0e53b764620 RX(theta₆) a76072a5f07049829561ea21b4573c6e--b80cdcace146456b95dbf0e53b764620 d242c6b4aba44b759206596786cc7108 HamEvo b80cdcace146456b95dbf0e53b764620--d242c6b4aba44b759206596786cc7108 67953a599e5d45cd8bba5548818935eb RX(theta₉) d242c6b4aba44b759206596786cc7108--67953a599e5d45cd8bba5548818935eb 1e8a740f4fbe43fbb0b83fed32c96d57 RY(theta₁₂) 67953a599e5d45cd8bba5548818935eb--1e8a740f4fbe43fbb0b83fed32c96d57 8beed8876cb347f8a9887c1697eada79 RX(theta₁₅) 1e8a740f4fbe43fbb0b83fed32c96d57--8beed8876cb347f8a9887c1697eada79 b8317003112b4b64aa25bf1812f1f324 HamEvo 8beed8876cb347f8a9887c1697eada79--b8317003112b4b64aa25bf1812f1f324 652dfed76b2545e5bb8c23e57d27afd3 b8317003112b4b64aa25bf1812f1f324--652dfed76b2545e5bb8c23e57d27afd3 8e3334c97d1248468d11d181ba706d52 301e2d7e4acb42f4ade7cc51a51c8159 RX(theta₁) b6e7cd9e4bd44176bb7405530d3da1bb--301e2d7e4acb42f4ade7cc51a51c8159 24a591be413c47eb94e793d7ee33685c 2 b6de5287f6b543058bd129b67d76c0ff RY(theta₄) 301e2d7e4acb42f4ade7cc51a51c8159--b6de5287f6b543058bd129b67d76c0ff ddc7caf8a6104245aefc42759878e584 RX(theta₇) b6de5287f6b543058bd129b67d76c0ff--ddc7caf8a6104245aefc42759878e584 375625ec54b44a628d3992714639af0d t = theta_t₀ ddc7caf8a6104245aefc42759878e584--375625ec54b44a628d3992714639af0d cf3583cf2e4240c8b974f2bf822969e9 RX(theta₁₀) 375625ec54b44a628d3992714639af0d--cf3583cf2e4240c8b974f2bf822969e9 c0175209f918449ab1694f7b423f8843 RY(theta₁₃) cf3583cf2e4240c8b974f2bf822969e9--c0175209f918449ab1694f7b423f8843 9189db1a2f13477084294bacbacd4417 RX(theta₁₆) c0175209f918449ab1694f7b423f8843--9189db1a2f13477084294bacbacd4417 3ae31869fc114127961d837da459c8f1 t = theta_t₁ 9189db1a2f13477084294bacbacd4417--3ae31869fc114127961d837da459c8f1 3ae31869fc114127961d837da459c8f1--8e3334c97d1248468d11d181ba706d52 2ad5793def3c4a459a2d7bc0503cebcf dffd40972b114290b48e062febfd9bd1 RX(theta₂) 24a591be413c47eb94e793d7ee33685c--dffd40972b114290b48e062febfd9bd1 9fa3d7cccd474466a6f77749213b1f98 RY(theta₅) dffd40972b114290b48e062febfd9bd1--9fa3d7cccd474466a6f77749213b1f98 e2598082f88345758f998dd314e5938b RX(theta₈) 9fa3d7cccd474466a6f77749213b1f98--e2598082f88345758f998dd314e5938b 3ac848840abc46e8947fda7f80777f53 e2598082f88345758f998dd314e5938b--3ac848840abc46e8947fda7f80777f53 c7d452f839c14acda16ea79af28fa18b RX(theta₁₁) 3ac848840abc46e8947fda7f80777f53--c7d452f839c14acda16ea79af28fa18b 79d9976e64204990a8a535d4d798eb87 RY(theta₁₄) c7d452f839c14acda16ea79af28fa18b--79d9976e64204990a8a535d4d798eb87 32531c27974f4c058eacf182f618c136 RX(theta₁₇) 79d9976e64204990a8a535d4d798eb87--32531c27974f4c058eacf182f618c136 d717d8e14e6f4deb85fb0be4cf4ad65b 32531c27974f4c058eacf182f618c136--d717d8e14e6f4deb85fb0be4cf4ad65b d717d8e14e6f4deb85fb0be4cf4ad65b--2ad5793def3c4a459a2d7bc0503cebcf

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_479105c721c049d4896926f0ffa5e590 cluster_af96d05c946c4362a78aa26c1c05b0fa ba77cc39701c4292be86eec4063078f8 0 3a9cac7628fc44c1afbb8a68f3889353 RX(theta₀) ba77cc39701c4292be86eec4063078f8--3a9cac7628fc44c1afbb8a68f3889353 e54c29aabfd6412b93daa191e4d2d166 1 d8c430b5f95644e284e8d18359f980b3 RY(theta₆) 3a9cac7628fc44c1afbb8a68f3889353--d8c430b5f95644e284e8d18359f980b3 4b76cc56fef94f62adda66c04b19d081 RX(theta₁₂) d8c430b5f95644e284e8d18359f980b3--4b76cc56fef94f62adda66c04b19d081 e70c9d0847e940e19329917ba6b57569 4b76cc56fef94f62adda66c04b19d081--e70c9d0847e940e19329917ba6b57569 590f42b026aa4e6a806208e13bb57143 RX(theta₁₈) e70c9d0847e940e19329917ba6b57569--590f42b026aa4e6a806208e13bb57143 ab83b3debfe84edca64e24747a25087a RY(theta₂₄) 590f42b026aa4e6a806208e13bb57143--ab83b3debfe84edca64e24747a25087a da928dca407d4b40bbb2564eff4dfc7d RX(theta₃₀) ab83b3debfe84edca64e24747a25087a--da928dca407d4b40bbb2564eff4dfc7d cce56dc7f52847e8b0d77b2bd711d410 da928dca407d4b40bbb2564eff4dfc7d--cce56dc7f52847e8b0d77b2bd711d410 97d9be8f335148068fa3cfaa931cea29 cce56dc7f52847e8b0d77b2bd711d410--97d9be8f335148068fa3cfaa931cea29 5a27d72a78924a4f80bfef474c9401a2 187e5e035632415dbe1c8dc5bdb55cf1 RX(theta₁) e54c29aabfd6412b93daa191e4d2d166--187e5e035632415dbe1c8dc5bdb55cf1 9267f8b9db2b43e7863acebbbf32de78 2 63bc06c68a6b428291a2016422826489 RY(theta₇) 187e5e035632415dbe1c8dc5bdb55cf1--63bc06c68a6b428291a2016422826489 abd8e25367dc4f73905b007127fd1963 RX(theta₁₃) 63bc06c68a6b428291a2016422826489--abd8e25367dc4f73905b007127fd1963 d63d23a3ca89463a90d328d21b3b88d2 abd8e25367dc4f73905b007127fd1963--d63d23a3ca89463a90d328d21b3b88d2 c020f0b8cebf45d09a8a9640c4f0b378 RX(theta₁₉) d63d23a3ca89463a90d328d21b3b88d2--c020f0b8cebf45d09a8a9640c4f0b378 7305ce5841ec473fab5b6808684c49a7 RY(theta₂₅) c020f0b8cebf45d09a8a9640c4f0b378--7305ce5841ec473fab5b6808684c49a7 58a5f1782e434d99ac3caa9384765a90 RX(theta₃₁) 7305ce5841ec473fab5b6808684c49a7--58a5f1782e434d99ac3caa9384765a90 46806b94779e434e89063855ff4fa6af 58a5f1782e434d99ac3caa9384765a90--46806b94779e434e89063855ff4fa6af 46806b94779e434e89063855ff4fa6af--5a27d72a78924a4f80bfef474c9401a2 8eaf99cd4668459bb8cb89c9aecbaaf1 9105b4405dd44c85aa85f9422c3a9734 RX(theta₂) 9267f8b9db2b43e7863acebbbf32de78--9105b4405dd44c85aa85f9422c3a9734 13ec193725654481941bdd50803318e1 3 7552ed23eb3249afbe4096dd03010b80 RY(theta₈) 9105b4405dd44c85aa85f9422c3a9734--7552ed23eb3249afbe4096dd03010b80 d675f72bd7014cf7922abba7a21ad6c4 RX(theta₁₄) 7552ed23eb3249afbe4096dd03010b80--d675f72bd7014cf7922abba7a21ad6c4 162762cc871f40bc89a97018619d4145 HamEvo d675f72bd7014cf7922abba7a21ad6c4--162762cc871f40bc89a97018619d4145 d1e479939d0d4975a13ea049870fbd34 RX(theta₂₀) 162762cc871f40bc89a97018619d4145--d1e479939d0d4975a13ea049870fbd34 9c927ec69602420c9b0bf1d4c1f889d1 RY(theta₂₆) d1e479939d0d4975a13ea049870fbd34--9c927ec69602420c9b0bf1d4c1f889d1 cdabca294d524a60ba068788c27dcb5b RX(theta₃₂) 9c927ec69602420c9b0bf1d4c1f889d1--cdabca294d524a60ba068788c27dcb5b ec59d98453b644389b9a73750148edc5 HamEvo cdabca294d524a60ba068788c27dcb5b--ec59d98453b644389b9a73750148edc5 ec59d98453b644389b9a73750148edc5--8eaf99cd4668459bb8cb89c9aecbaaf1 3c25a4e0b49043beb1256eabf7025ded 27f98ca04ddf426b83f13bdf61efb798 RX(theta₃) 13ec193725654481941bdd50803318e1--27f98ca04ddf426b83f13bdf61efb798 3b070694fc364f93b04320149af94488 4 4d44af7ede7e433495a1d7ef6b996f13 RY(theta₉) 27f98ca04ddf426b83f13bdf61efb798--4d44af7ede7e433495a1d7ef6b996f13 255a5b8065a14817824fa563e6f7594f RX(theta₁₅) 4d44af7ede7e433495a1d7ef6b996f13--255a5b8065a14817824fa563e6f7594f 55a3b2858b9245cba3d12c5079b9dde7 t = theta_t₀ 255a5b8065a14817824fa563e6f7594f--55a3b2858b9245cba3d12c5079b9dde7 6d4defc97a1146ae83e3ce87ec0c7b16 RX(theta₂₁) 55a3b2858b9245cba3d12c5079b9dde7--6d4defc97a1146ae83e3ce87ec0c7b16 d68e46a4f2bf40c5baaa780c8e992a82 RY(theta₂₇) 6d4defc97a1146ae83e3ce87ec0c7b16--d68e46a4f2bf40c5baaa780c8e992a82 3a1117a04b4d474e9a5ec7cfb5aaf687 RX(theta₃₃) d68e46a4f2bf40c5baaa780c8e992a82--3a1117a04b4d474e9a5ec7cfb5aaf687 e959bffa1c824ca8b4c5ce915cacf256 t = theta_t₁ 3a1117a04b4d474e9a5ec7cfb5aaf687--e959bffa1c824ca8b4c5ce915cacf256 e959bffa1c824ca8b4c5ce915cacf256--3c25a4e0b49043beb1256eabf7025ded 011fa407cc3b407bba6969f78b1025a9 7e1fd123b612427e9e9757a70e636ab6 RX(theta₄) 3b070694fc364f93b04320149af94488--7e1fd123b612427e9e9757a70e636ab6 30baf6c51d0b45729742ff484478638f 5 af18c1e63ef544efab840b10ec404481 RY(theta₁₀) 7e1fd123b612427e9e9757a70e636ab6--af18c1e63ef544efab840b10ec404481 34f0ab8764bf48688b1b0824af5ee712 RX(theta₁₆) af18c1e63ef544efab840b10ec404481--34f0ab8764bf48688b1b0824af5ee712 c22bbc432d6c45f19649cbf24da5c810 34f0ab8764bf48688b1b0824af5ee712--c22bbc432d6c45f19649cbf24da5c810 9b78f42f52e44988bed3af185b9eab65 RX(theta₂₂) c22bbc432d6c45f19649cbf24da5c810--9b78f42f52e44988bed3af185b9eab65 11e2b3275aa7431bb87a4c7e482684f9 RY(theta₂₈) 9b78f42f52e44988bed3af185b9eab65--11e2b3275aa7431bb87a4c7e482684f9 0b6d2591adad41e181b80dbbc35d7efd RX(theta₃₄) 11e2b3275aa7431bb87a4c7e482684f9--0b6d2591adad41e181b80dbbc35d7efd 45d6b3f981374d17a7e0aa162d39d300 0b6d2591adad41e181b80dbbc35d7efd--45d6b3f981374d17a7e0aa162d39d300 45d6b3f981374d17a7e0aa162d39d300--011fa407cc3b407bba6969f78b1025a9 a4f5a15c14e54906b0f8745178b50a77 5d6513dd18994aae9c027e18e56b83ab RX(theta₅) 30baf6c51d0b45729742ff484478638f--5d6513dd18994aae9c027e18e56b83ab 4f2efc36587748abb71687db563a75ec RY(theta₁₁) 5d6513dd18994aae9c027e18e56b83ab--4f2efc36587748abb71687db563a75ec b141d230f25347a3b01f376916844673 RX(theta₁₇) 4f2efc36587748abb71687db563a75ec--b141d230f25347a3b01f376916844673 b0163419a98142c7b3aba1502da0c9fc b141d230f25347a3b01f376916844673--b0163419a98142c7b3aba1502da0c9fc a830567a2b134c468c7603aed9977f48 RX(theta₂₃) b0163419a98142c7b3aba1502da0c9fc--a830567a2b134c468c7603aed9977f48 dd9b6c6670714f228cd42e08ec0c0b38 RY(theta₂₉) a830567a2b134c468c7603aed9977f48--dd9b6c6670714f228cd42e08ec0c0b38 17da49f6f1dd46bdbe70be5bff07125a RX(theta₃₅) dd9b6c6670714f228cd42e08ec0c0b38--17da49f6f1dd46bdbe70be5bff07125a f8bdbbce5f724dbab335d2f0764f7394 17da49f6f1dd46bdbe70be5bff07125a--f8bdbbce5f724dbab335d2f0764f7394 f8bdbbce5f724dbab335d2f0764f7394--a4f5a15c14e54906b0f8745178b50a77