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_758a059a95334e60a3722d71180a912f Constant Chebyshev FM cluster_0dd04badf485428e8abf58a777ff2d6f Constant Fourier FM 59801b5da1b4440eabdaaae892cbd786 0 43ccc946a9654afeae8776a5a5697a92 RX(phi) 59801b5da1b4440eabdaaae892cbd786--43ccc946a9654afeae8776a5a5697a92 a60c260d30814cc7b065cabaf39aa983 1 4de8ad6999c24b4bbc0fe0b9dac095e9 RX(acos(phi)) 43ccc946a9654afeae8776a5a5697a92--4de8ad6999c24b4bbc0fe0b9dac095e9 df7fbc791c66496491d171771a79be7e 4de8ad6999c24b4bbc0fe0b9dac095e9--df7fbc791c66496491d171771a79be7e 70ce6394beaa4426867e6426c3cb9557 65efe8d05399495f8f579310cf4d33ef RX(phi) a60c260d30814cc7b065cabaf39aa983--65efe8d05399495f8f579310cf4d33ef a5f38329f4a04f26806ee0ab81583d35 2 605cd29446c14fed99a166cbc8b711d5 RX(acos(phi)) 65efe8d05399495f8f579310cf4d33ef--605cd29446c14fed99a166cbc8b711d5 605cd29446c14fed99a166cbc8b711d5--70ce6394beaa4426867e6426c3cb9557 dc8fffcac5e04fbfbb18682d3806d67c 5045f273e50d43f1b066892c995bf25a RX(phi) a5f38329f4a04f26806ee0ab81583d35--5045f273e50d43f1b066892c995bf25a f79a29c26f1a40ac8ab805a3a46f552e RX(acos(phi)) 5045f273e50d43f1b066892c995bf25a--f79a29c26f1a40ac8ab805a3a46f552e f79a29c26f1a40ac8ab805a3a46f552e--dc8fffcac5e04fbfbb18682d3806d67c

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_bdee9219eef543049fa44c4f4926bbce Constant custom_func FM cluster_2df29e8f1569444496797beecd12a3af Constant asin FM d641f727c04d4a0da5810d981c3780a1 0 bf92965289504be3b8d475cfe2bd9c40 RX(asin(phi)) d641f727c04d4a0da5810d981c3780a1--bf92965289504be3b8d475cfe2bd9c40 6d3de42ef5ad4cf891a0aa1ae40e5ff5 1 7e595fcf9a8a4e2eb47fd966b0f62a85 RX(phi**2 + asin(phi)) bf92965289504be3b8d475cfe2bd9c40--7e595fcf9a8a4e2eb47fd966b0f62a85 a61fed6e624f46458cc4a591db2017c0 7e595fcf9a8a4e2eb47fd966b0f62a85--a61fed6e624f46458cc4a591db2017c0 06183281f56d476ebdfe10968b220b70 12079807f42840f2aa08006eaa0147a8 RX(asin(phi)) 6d3de42ef5ad4cf891a0aa1ae40e5ff5--12079807f42840f2aa08006eaa0147a8 d5db7a1a450c4cbfbc4a0f5cd4fa70af 2 3d6450d8f2654c3a9cb372d1ce03e08f RX(phi**2 + asin(phi)) 12079807f42840f2aa08006eaa0147a8--3d6450d8f2654c3a9cb372d1ce03e08f 3d6450d8f2654c3a9cb372d1ce03e08f--06183281f56d476ebdfe10968b220b70 ac391545f8c7409baa0ddcbb6e0f7dff 0116cc271a0a4022a6701d0c859233cc RX(asin(phi)) d5db7a1a450c4cbfbc4a0f5cd4fa70af--0116cc271a0a4022a6701d0c859233cc dce1e0c107cd4a89aa541b39193458e2 RX(phi**2 + asin(phi)) 0116cc271a0a4022a6701d0c859233cc--dce1e0c107cd4a89aa541b39193458e2 dce1e0c107cd4a89aa541b39193458e2--ac391545f8c7409baa0ddcbb6e0f7dff

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_209b33c9a9bd4cb598f01978d837b58d Exponential Fourier FM cluster_98a6fd9d28c144c683d4dfca6f542d7b Constant Fourier FM cluster_7a7a08e3a4bb48b09eaeca132cec5d55 Tower Fourier FM fc07a3677b524866bd284e94229d3ec4 0 41581f1e7b8940e784598b597f1df4c2 RX(phi) fc07a3677b524866bd284e94229d3ec4--41581f1e7b8940e784598b597f1df4c2 9ffcae60505843b2ac98bd4ca1623c1f 1 28cff5e665b545dc8deb3760fb8d966d RX(1.0*phi) 41581f1e7b8940e784598b597f1df4c2--28cff5e665b545dc8deb3760fb8d966d c849deb96ade40eabb209788850639d8 RX(1.0*phi) 28cff5e665b545dc8deb3760fb8d966d--c849deb96ade40eabb209788850639d8 443cbf72f300431091c292c5231e3ebf c849deb96ade40eabb209788850639d8--443cbf72f300431091c292c5231e3ebf cadba89747f740b6b9bfac5443ca5ba2 aa2faa7cd15f4ea4b678780b1a4f0044 RX(phi) 9ffcae60505843b2ac98bd4ca1623c1f--aa2faa7cd15f4ea4b678780b1a4f0044 f94e237828784cfda6e70061a91d2f80 2 933c43883580400b8bbc9eec0c71ae58 RX(2.0*phi) aa2faa7cd15f4ea4b678780b1a4f0044--933c43883580400b8bbc9eec0c71ae58 8bd4e4f4f7b54afea1ec21f15ce8683c RX(2.0*phi) 933c43883580400b8bbc9eec0c71ae58--8bd4e4f4f7b54afea1ec21f15ce8683c 8bd4e4f4f7b54afea1ec21f15ce8683c--cadba89747f740b6b9bfac5443ca5ba2 abde8a202d9142e5828051047144ffde aac4f85f5db845feb88a63140d4cfab5 RX(phi) f94e237828784cfda6e70061a91d2f80--aac4f85f5db845feb88a63140d4cfab5 96ca3facd3184f9cbcaa74a33cce5829 3 85282f23c1294641b407322b27991225 RX(3.0*phi) aac4f85f5db845feb88a63140d4cfab5--85282f23c1294641b407322b27991225 0603decbcf8b413a84a9347736315aa7 RX(4.0*phi) 85282f23c1294641b407322b27991225--0603decbcf8b413a84a9347736315aa7 0603decbcf8b413a84a9347736315aa7--abde8a202d9142e5828051047144ffde e770f1a415704bbfa32f7c1a572b3c5a 5a1d4b23672a4f4fa7c47ebeab18b5c5 RX(phi) 96ca3facd3184f9cbcaa74a33cce5829--5a1d4b23672a4f4fa7c47ebeab18b5c5 1570f8fff87242518731c2a2d1e063de 4 7fb5e176777c49c88dbf7892ffd3b5f9 RX(4.0*phi) 5a1d4b23672a4f4fa7c47ebeab18b5c5--7fb5e176777c49c88dbf7892ffd3b5f9 959425c21a164c118b3c3ca2703a5168 RX(8.0*phi) 7fb5e176777c49c88dbf7892ffd3b5f9--959425c21a164c118b3c3ca2703a5168 959425c21a164c118b3c3ca2703a5168--e770f1a415704bbfa32f7c1a572b3c5a ae0125abedbd4c2cb55d2f1c896189c5 027c3a018cf54c568f4cadd3207eaf68 RX(phi) 1570f8fff87242518731c2a2d1e063de--027c3a018cf54c568f4cadd3207eaf68 d80c579550ea4ee6b462890a4c3a8569 RX(5.0*phi) 027c3a018cf54c568f4cadd3207eaf68--d80c579550ea4ee6b462890a4c3a8569 0412809e56174dd9b6840e58b8ea53a8 RX(16.0*phi) d80c579550ea4ee6b462890a4c3a8569--0412809e56174dd9b6840e58b8ea53a8 0412809e56174dd9b6840e58b8ea53a8--ae0125abedbd4c2cb55d2f1c896189c5

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 54f7c8059bd248649a3033ee5cd966d2 0 efe7c9baf1a74cf8b5876b9d2dfcdf35 RX(1.0*acos(phi)) 54f7c8059bd248649a3033ee5cd966d2--efe7c9baf1a74cf8b5876b9d2dfcdf35 5ed172d2325f40d2b97476592e27c151 1 0931de374ce04a678a62d48152ea2209 efe7c9baf1a74cf8b5876b9d2dfcdf35--0931de374ce04a678a62d48152ea2209 eb20aa1d709f4004aa092ea5e6196326 198e55bc0422464584568c97198ae976 RX(1.414*acos(phi)) 5ed172d2325f40d2b97476592e27c151--198e55bc0422464584568c97198ae976 8887603bc56648748e730217861bda58 2 198e55bc0422464584568c97198ae976--eb20aa1d709f4004aa092ea5e6196326 5fd96abaa4e840cba3a997579c11a197 3f52a11fd4044685a5aa7938d3ed9d3e RX(1.732*acos(phi)) 8887603bc56648748e730217861bda58--3f52a11fd4044685a5aa7938d3ed9d3e a9d4d5ba89374e6fb0f06568fbb6d024 3 3f52a11fd4044685a5aa7938d3ed9d3e--5fd96abaa4e840cba3a997579c11a197 0edf1130882b4543ad7b21cb61533b7a deac49ac43c04575b31b4b736243efdd RX(2.0*acos(phi)) a9d4d5ba89374e6fb0f06568fbb6d024--deac49ac43c04575b31b4b736243efdd 4a65e8fe8d0b48948500c98df1b89750 4 deac49ac43c04575b31b4b736243efdd--0edf1130882b4543ad7b21cb61533b7a 9e895a239962482d9f4a1681b76bf623 2257c0441f93422f9db918768709734d RX(2.236*acos(phi)) 4a65e8fe8d0b48948500c98df1b89750--2257c0441f93422f9db918768709734d 2257c0441f93422f9db918768709734d--9e895a239962482d9f4a1681b76bf623

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 abebfc6dc5f841239c696fb122b5d71a 0 11f6db15287448beb4438242a646971d RY(80.0*acos(0.667*x + 1.667)) abebfc6dc5f841239c696fb122b5d71a--11f6db15287448beb4438242a646971d 1cd51158668342fa8db76d6aa4e3c46c 1 d304f595dcbf4581b429af7635135df8 11f6db15287448beb4438242a646971d--d304f595dcbf4581b429af7635135df8 df9b44f4bd844c6cb9097523e6d76812 1e0f4a7e29444f5f97486d23db6164f1 RY(40.0*acos(0.667*x + 1.667)) 1cd51158668342fa8db76d6aa4e3c46c--1e0f4a7e29444f5f97486d23db6164f1 05e7312c0c38454b869118d7ec2e5230 2 1e0f4a7e29444f5f97486d23db6164f1--df9b44f4bd844c6cb9097523e6d76812 c87cce651d8c40389a393c249a8f6a60 4ed728abe86e4fa284469e736ace6469 RY(20.0*acos(0.667*x + 1.667)) 05e7312c0c38454b869118d7ec2e5230--4ed728abe86e4fa284469e736ace6469 2ba8c21b8e2645909a85179dd884ad27 3 4ed728abe86e4fa284469e736ace6469--c87cce651d8c40389a393c249a8f6a60 a2f04c3530f7410dbf85a9c9773f8bd0 9392c4c172d5411eb85ee41c1b478c1f RY(10.0*acos(0.667*x + 1.667)) 2ba8c21b8e2645909a85179dd884ad27--9392c4c172d5411eb85ee41c1b478c1f 86a1adfa06b84d82b468317fe62a6abe 4 9392c4c172d5411eb85ee41c1b478c1f--a2f04c3530f7410dbf85a9c9773f8bd0 8c1d88ce50074ab78cb650828b22ee81 2aee26613c9e418f96619720374538c4 RY(5.0*acos(0.667*x + 1.667)) 86a1adfa06b84d82b468317fe62a6abe--2aee26613c9e418f96619720374538c4 2aee26613c9e418f96619720374538c4--8c1d88ce50074ab78cb650828b22ee81

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 019da967e9f64378be7c15c891742ee1 0 05afa4b9223a49af8bcd768fa0cf8fd5 RX(theta₀) 019da967e9f64378be7c15c891742ee1--05afa4b9223a49af8bcd768fa0cf8fd5 f491a78d383646dc80be0d76f5341b1d 1 f265ac295fc142ee865eac3e81aba5c7 RY(theta₃) 05afa4b9223a49af8bcd768fa0cf8fd5--f265ac295fc142ee865eac3e81aba5c7 6a29ab9154754667a1b86d19ddc0d99a RX(theta₆) f265ac295fc142ee865eac3e81aba5c7--6a29ab9154754667a1b86d19ddc0d99a 2de30353e78144e1a5df14cc93ef4046 6a29ab9154754667a1b86d19ddc0d99a--2de30353e78144e1a5df14cc93ef4046 045a8e265ab3424484e21c84fd8fa8c1 2de30353e78144e1a5df14cc93ef4046--045a8e265ab3424484e21c84fd8fa8c1 07a16e561ace4e66a01a07ff0b345dba RX(theta₉) 045a8e265ab3424484e21c84fd8fa8c1--07a16e561ace4e66a01a07ff0b345dba 073df38d39bd4f4fa1e852ff949d3fb2 RY(theta₁₂) 07a16e561ace4e66a01a07ff0b345dba--073df38d39bd4f4fa1e852ff949d3fb2 922dac29d6754a5dba2c252a580917b7 RX(theta₁₅) 073df38d39bd4f4fa1e852ff949d3fb2--922dac29d6754a5dba2c252a580917b7 2ec20ce51cc44a15b03cc82016afc9e0 922dac29d6754a5dba2c252a580917b7--2ec20ce51cc44a15b03cc82016afc9e0 e035a9afedf143389b546c492be7bd1d 2ec20ce51cc44a15b03cc82016afc9e0--e035a9afedf143389b546c492be7bd1d 1602fb64a8e246e08c304a8edfbea4b3 e035a9afedf143389b546c492be7bd1d--1602fb64a8e246e08c304a8edfbea4b3 01666e0cfd1c4dbf89332ba64d409639 06a88a54dfd44458816863cc1a876342 RX(theta₁) f491a78d383646dc80be0d76f5341b1d--06a88a54dfd44458816863cc1a876342 3c3a09b1ebb04ac5b8345f82e5101044 2 2b8a0912465e4cb8bb9e6e0ec23c3774 RY(theta₄) 06a88a54dfd44458816863cc1a876342--2b8a0912465e4cb8bb9e6e0ec23c3774 8f0268b8577c44c09087668e4de69bd2 RX(theta₇) 2b8a0912465e4cb8bb9e6e0ec23c3774--8f0268b8577c44c09087668e4de69bd2 0f2f1a05b7b8415fb49b16df55e27e8b X 8f0268b8577c44c09087668e4de69bd2--0f2f1a05b7b8415fb49b16df55e27e8b 0f2f1a05b7b8415fb49b16df55e27e8b--2de30353e78144e1a5df14cc93ef4046 8710d40443634a4292078332746a3106 0f2f1a05b7b8415fb49b16df55e27e8b--8710d40443634a4292078332746a3106 4356302642f8424287386ebe6b42e0b0 RX(theta₁₀) 8710d40443634a4292078332746a3106--4356302642f8424287386ebe6b42e0b0 d6b206a061f944689897ad2d8bf12c01 RY(theta₁₃) 4356302642f8424287386ebe6b42e0b0--d6b206a061f944689897ad2d8bf12c01 d6851c991ecf4ed182217fffcf0d0512 RX(theta₁₆) d6b206a061f944689897ad2d8bf12c01--d6851c991ecf4ed182217fffcf0d0512 6d19696b3e64499dae2df2b9fd5308aa X d6851c991ecf4ed182217fffcf0d0512--6d19696b3e64499dae2df2b9fd5308aa 6d19696b3e64499dae2df2b9fd5308aa--2ec20ce51cc44a15b03cc82016afc9e0 43785c59ff894bcfb03fd0fd5ff7c3bf 6d19696b3e64499dae2df2b9fd5308aa--43785c59ff894bcfb03fd0fd5ff7c3bf 43785c59ff894bcfb03fd0fd5ff7c3bf--01666e0cfd1c4dbf89332ba64d409639 5b0c2d44135a4748ba5382c533e9cca7 4ee8245c08074adf9715652bfd5cd26f RX(theta₂) 3c3a09b1ebb04ac5b8345f82e5101044--4ee8245c08074adf9715652bfd5cd26f 2628d20052ba41d0aa8eed7031e46996 RY(theta₅) 4ee8245c08074adf9715652bfd5cd26f--2628d20052ba41d0aa8eed7031e46996 1ff29f899ede448799a5118f52bab242 RX(theta₈) 2628d20052ba41d0aa8eed7031e46996--1ff29f899ede448799a5118f52bab242 bb7c17f8e2884e41bac04b5a2d36b773 1ff29f899ede448799a5118f52bab242--bb7c17f8e2884e41bac04b5a2d36b773 d97c45d0652c41e488d2ae5c33fed127 X bb7c17f8e2884e41bac04b5a2d36b773--d97c45d0652c41e488d2ae5c33fed127 d97c45d0652c41e488d2ae5c33fed127--8710d40443634a4292078332746a3106 c7c7126d842d4736a8d4ae4900ec056a RX(theta₁₁) d97c45d0652c41e488d2ae5c33fed127--c7c7126d842d4736a8d4ae4900ec056a d13503adfe3e47d8b2c1f4b527c9bfa9 RY(theta₁₄) c7c7126d842d4736a8d4ae4900ec056a--d13503adfe3e47d8b2c1f4b527c9bfa9 6e4eed695168469b9d2afea33b431cb7 RX(theta₁₇) d13503adfe3e47d8b2c1f4b527c9bfa9--6e4eed695168469b9d2afea33b431cb7 6990a9583d7249ff98bc20e1a55ea407 6e4eed695168469b9d2afea33b431cb7--6990a9583d7249ff98bc20e1a55ea407 3cdf962afb944470ac4033313c1dbf64 X 6990a9583d7249ff98bc20e1a55ea407--3cdf962afb944470ac4033313c1dbf64 3cdf962afb944470ac4033313c1dbf64--43785c59ff894bcfb03fd0fd5ff7c3bf 3cdf962afb944470ac4033313c1dbf64--5b0c2d44135a4748ba5382c533e9cca7

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 a1134a267c8b472cba1cc9b663ce524b 0 7b97d432660c4a4780427cdbe368cf98 RX(phi₀) a1134a267c8b472cba1cc9b663ce524b--7b97d432660c4a4780427cdbe368cf98 7b19c461e0c242f6b2ff9c607010ca8c 1 fccbed018a9349ac96f9103d63ce3a86 RY(phi₃) 7b97d432660c4a4780427cdbe368cf98--fccbed018a9349ac96f9103d63ce3a86 6fc0ce94e057465399a8a3bf64a676b0 RX(phi₆) fccbed018a9349ac96f9103d63ce3a86--6fc0ce94e057465399a8a3bf64a676b0 8a2ba113d469467e9841193d85a9ed31 6fc0ce94e057465399a8a3bf64a676b0--8a2ba113d469467e9841193d85a9ed31 79beb19870184ec09e212cf452cb765a 8a2ba113d469467e9841193d85a9ed31--79beb19870184ec09e212cf452cb765a adc35a7329ca45018944765eb3868ff7 RX(phi₉) 79beb19870184ec09e212cf452cb765a--adc35a7329ca45018944765eb3868ff7 47f2eddf098d433b98e4dba9e6beb6e4 RY(phi₁₂) adc35a7329ca45018944765eb3868ff7--47f2eddf098d433b98e4dba9e6beb6e4 468bfc5a772448289b5217c86dc5a4d6 RX(phi₁₅) 47f2eddf098d433b98e4dba9e6beb6e4--468bfc5a772448289b5217c86dc5a4d6 bf08e8b3ceba4b8b9f37dccc2da3c026 468bfc5a772448289b5217c86dc5a4d6--bf08e8b3ceba4b8b9f37dccc2da3c026 8b84da891d6f4ca39881b255884a3012 bf08e8b3ceba4b8b9f37dccc2da3c026--8b84da891d6f4ca39881b255884a3012 3688df439b62430a82ef3e9df9b2a7e7 8b84da891d6f4ca39881b255884a3012--3688df439b62430a82ef3e9df9b2a7e7 090717d3a8b6480682a7e76797bd7993 ce267bc20af448d494f0d9eab627021c RX(phi₁) 7b19c461e0c242f6b2ff9c607010ca8c--ce267bc20af448d494f0d9eab627021c 0ed0b2027fcb4e128f99a81237cabefe 2 ee9e2c97e0484fffab9cd30d8a74a265 RY(phi₄) ce267bc20af448d494f0d9eab627021c--ee9e2c97e0484fffab9cd30d8a74a265 9936fe1c4eae4d9faec9c28e33fcbd08 RX(phi₇) ee9e2c97e0484fffab9cd30d8a74a265--9936fe1c4eae4d9faec9c28e33fcbd08 f0f6a61d302c403380918c832b40da61 PHASE(phi_ent₀) 9936fe1c4eae4d9faec9c28e33fcbd08--f0f6a61d302c403380918c832b40da61 f0f6a61d302c403380918c832b40da61--8a2ba113d469467e9841193d85a9ed31 de8b0ff0a6f94780b313f3afa116f2a9 f0f6a61d302c403380918c832b40da61--de8b0ff0a6f94780b313f3afa116f2a9 83421e5a17d140869c248a5c12ab8f49 RX(phi₁₀) de8b0ff0a6f94780b313f3afa116f2a9--83421e5a17d140869c248a5c12ab8f49 d35521d110c8460a94aff30cb5db6881 RY(phi₁₃) 83421e5a17d140869c248a5c12ab8f49--d35521d110c8460a94aff30cb5db6881 88278fe7500d4617825325b306d6294a RX(phi₁₆) d35521d110c8460a94aff30cb5db6881--88278fe7500d4617825325b306d6294a c6f5164498924b72b033799f0b3fb03f PHASE(phi_ent₂) 88278fe7500d4617825325b306d6294a--c6f5164498924b72b033799f0b3fb03f c6f5164498924b72b033799f0b3fb03f--bf08e8b3ceba4b8b9f37dccc2da3c026 0d4bac8a9ba94ede927cd5c28771a3cf c6f5164498924b72b033799f0b3fb03f--0d4bac8a9ba94ede927cd5c28771a3cf 0d4bac8a9ba94ede927cd5c28771a3cf--090717d3a8b6480682a7e76797bd7993 3633a2b8fa49410abc8770089f909f76 2aff43b81e2f4d8da69091362ac36fe0 RX(phi₂) 0ed0b2027fcb4e128f99a81237cabefe--2aff43b81e2f4d8da69091362ac36fe0 52f12cd20ac14673b737d8d51591e523 RY(phi₅) 2aff43b81e2f4d8da69091362ac36fe0--52f12cd20ac14673b737d8d51591e523 2d3b1a12c50e4f218dfa73fc0198d2d6 RX(phi₈) 52f12cd20ac14673b737d8d51591e523--2d3b1a12c50e4f218dfa73fc0198d2d6 a57d15576d79491298e3666f61b13731 2d3b1a12c50e4f218dfa73fc0198d2d6--a57d15576d79491298e3666f61b13731 2a99702476e84983976cd2f5798b8b4f PHASE(phi_ent₁) a57d15576d79491298e3666f61b13731--2a99702476e84983976cd2f5798b8b4f 2a99702476e84983976cd2f5798b8b4f--de8b0ff0a6f94780b313f3afa116f2a9 4ee7effa03434428834521ba205f7e26 RX(phi₁₁) 2a99702476e84983976cd2f5798b8b4f--4ee7effa03434428834521ba205f7e26 cc4e0d433b3d4297baafcde5cbbbaf75 RY(phi₁₄) 4ee7effa03434428834521ba205f7e26--cc4e0d433b3d4297baafcde5cbbbaf75 6ffd3df98f474472baf0264854a79ef1 RX(phi₁₇) cc4e0d433b3d4297baafcde5cbbbaf75--6ffd3df98f474472baf0264854a79ef1 93f64fed97014d2f8c9c8947f5cd908d 6ffd3df98f474472baf0264854a79ef1--93f64fed97014d2f8c9c8947f5cd908d 902c3ddd3fe5449bb0e50432a2efca5f PHASE(phi_ent₃) 93f64fed97014d2f8c9c8947f5cd908d--902c3ddd3fe5449bb0e50432a2efca5f 902c3ddd3fe5449bb0e50432a2efca5f--0d4bac8a9ba94ede927cd5c28771a3cf 902c3ddd3fe5449bb0e50432a2efca5f--3633a2b8fa49410abc8770089f909f76

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_c4f24e985372407487aabc930955e0a6 cluster_e534035a3b9b4854a67f338782b0dc8a 614334ffa7ec44078c5824f900105869 0 8e3ccbe30e2e4a67bfdb1a1e12daca00 RX(theta₀) 614334ffa7ec44078c5824f900105869--8e3ccbe30e2e4a67bfdb1a1e12daca00 6adcd59ca96c4285afa48b1ccae57d32 1 c1d996ac20df4b4aab7a4705f192fd58 RY(theta₃) 8e3ccbe30e2e4a67bfdb1a1e12daca00--c1d996ac20df4b4aab7a4705f192fd58 68ac2a00b2f743c1a85a1d4400da439a RX(theta₆) c1d996ac20df4b4aab7a4705f192fd58--68ac2a00b2f743c1a85a1d4400da439a c9502fd1082d40f6b04c0090c71eaad2 HamEvo 68ac2a00b2f743c1a85a1d4400da439a--c9502fd1082d40f6b04c0090c71eaad2 590014fda50d4308bad93448b9b7e6ca RX(theta₉) c9502fd1082d40f6b04c0090c71eaad2--590014fda50d4308bad93448b9b7e6ca 32a4f859578a4a6faa0d94b81c1279d9 RY(theta₁₂) 590014fda50d4308bad93448b9b7e6ca--32a4f859578a4a6faa0d94b81c1279d9 28b0972b9ed845df9c07a08a9966031a RX(theta₁₅) 32a4f859578a4a6faa0d94b81c1279d9--28b0972b9ed845df9c07a08a9966031a 1d0a006af8a4411585b31befaf47563a HamEvo 28b0972b9ed845df9c07a08a9966031a--1d0a006af8a4411585b31befaf47563a 510c012a22dd4ed58ee40747eef45367 1d0a006af8a4411585b31befaf47563a--510c012a22dd4ed58ee40747eef45367 d7be3d7660974a42882ef3c19f3bdba1 e7d96c1d1aa34a74a4e666ec9a8d1e75 RX(theta₁) 6adcd59ca96c4285afa48b1ccae57d32--e7d96c1d1aa34a74a4e666ec9a8d1e75 72248a7467714a79b36729389713e314 2 f8b3eee68d3f417fb4b3d07fa9ce0419 RY(theta₄) e7d96c1d1aa34a74a4e666ec9a8d1e75--f8b3eee68d3f417fb4b3d07fa9ce0419 231c04e89bb446db8f67becd51a3c45e RX(theta₇) f8b3eee68d3f417fb4b3d07fa9ce0419--231c04e89bb446db8f67becd51a3c45e 72490701118442c0ab17b80f57fef758 t = theta_t₀ 231c04e89bb446db8f67becd51a3c45e--72490701118442c0ab17b80f57fef758 c4a037c6ae0446d2acf3916039c59d1a RX(theta₁₀) 72490701118442c0ab17b80f57fef758--c4a037c6ae0446d2acf3916039c59d1a beea4477ab264840a08c6c917f6abe36 RY(theta₁₃) c4a037c6ae0446d2acf3916039c59d1a--beea4477ab264840a08c6c917f6abe36 668274852c9043e298f5fdbfb73de409 RX(theta₁₆) beea4477ab264840a08c6c917f6abe36--668274852c9043e298f5fdbfb73de409 e614bfe1179f491b921f9b58cfd866ee t = theta_t₁ 668274852c9043e298f5fdbfb73de409--e614bfe1179f491b921f9b58cfd866ee e614bfe1179f491b921f9b58cfd866ee--d7be3d7660974a42882ef3c19f3bdba1 d0a97d9498f7438a87297732092b6d12 b3859460a7444dd5bf975321e1613ce2 RX(theta₂) 72248a7467714a79b36729389713e314--b3859460a7444dd5bf975321e1613ce2 065f82010e1445a1814613a2b1cd7d52 RY(theta₅) b3859460a7444dd5bf975321e1613ce2--065f82010e1445a1814613a2b1cd7d52 8e16366656594bcc93ded30014ccb076 RX(theta₈) 065f82010e1445a1814613a2b1cd7d52--8e16366656594bcc93ded30014ccb076 d2831d27ee5844aaba7d0e2d140435ef 8e16366656594bcc93ded30014ccb076--d2831d27ee5844aaba7d0e2d140435ef 46cf5dc644b74f17b40885fcc6f72b89 RX(theta₁₁) d2831d27ee5844aaba7d0e2d140435ef--46cf5dc644b74f17b40885fcc6f72b89 fc93d4d75a8343a0a9f863827e02f683 RY(theta₁₄) 46cf5dc644b74f17b40885fcc6f72b89--fc93d4d75a8343a0a9f863827e02f683 306099cf8b4444099532f18113cbcbd7 RX(theta₁₇) fc93d4d75a8343a0a9f863827e02f683--306099cf8b4444099532f18113cbcbd7 725cd7853ad74bc6842df77e763a54d4 306099cf8b4444099532f18113cbcbd7--725cd7853ad74bc6842df77e763a54d4 725cd7853ad74bc6842df77e763a54d4--d0a97d9498f7438a87297732092b6d12

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_ac403d4f593548068c66b21ce045be86 cluster_9e2cd26f85be477f91c0e4b1cd9a2aee 1b97efb69b0c4bc6b59163a34a5b6803 0 eb021d941d9441fab869a65078e47574 RX(theta₀) 1b97efb69b0c4bc6b59163a34a5b6803--eb021d941d9441fab869a65078e47574 6d0765a820104ca083e1d55f1beea72c 1 72f222e771504ab1a2ac4aba9bdefa41 RY(theta₆) eb021d941d9441fab869a65078e47574--72f222e771504ab1a2ac4aba9bdefa41 6d44acaa77214edfad721e7c2349b062 RX(theta₁₂) 72f222e771504ab1a2ac4aba9bdefa41--6d44acaa77214edfad721e7c2349b062 37f4e2f73a3a4a449178914b9a740355 6d44acaa77214edfad721e7c2349b062--37f4e2f73a3a4a449178914b9a740355 b6ae5b126bd34d9aa49fcccb615e567c RX(theta₁₈) 37f4e2f73a3a4a449178914b9a740355--b6ae5b126bd34d9aa49fcccb615e567c 4095ed890c314c77bcd82313dc80fd3c RY(theta₂₄) b6ae5b126bd34d9aa49fcccb615e567c--4095ed890c314c77bcd82313dc80fd3c 85022dd479374ce28e668d1b79e70e1b RX(theta₃₀) 4095ed890c314c77bcd82313dc80fd3c--85022dd479374ce28e668d1b79e70e1b 6fc72a748feb44c7b9dac16c75a1bb0a 85022dd479374ce28e668d1b79e70e1b--6fc72a748feb44c7b9dac16c75a1bb0a 19b2e84865654521a11c47df22d9f280 6fc72a748feb44c7b9dac16c75a1bb0a--19b2e84865654521a11c47df22d9f280 af8dc6e651374fda90b52aedfe6098c1 6a67487420e4438c980e12c1f4a0f4f0 RX(theta₁) 6d0765a820104ca083e1d55f1beea72c--6a67487420e4438c980e12c1f4a0f4f0 e4e1fc916fe645738495bc9ad2e40aca 2 fc1a18f7c9b24944a74ff614026c57c6 RY(theta₇) 6a67487420e4438c980e12c1f4a0f4f0--fc1a18f7c9b24944a74ff614026c57c6 213682f710424e079666bf5a00c21078 RX(theta₁₃) fc1a18f7c9b24944a74ff614026c57c6--213682f710424e079666bf5a00c21078 22b7a1b6eeca480786d173eeff111559 213682f710424e079666bf5a00c21078--22b7a1b6eeca480786d173eeff111559 9b7d9188d4d9417693f60c889ac7bbf8 RX(theta₁₉) 22b7a1b6eeca480786d173eeff111559--9b7d9188d4d9417693f60c889ac7bbf8 c08adbd416954441ada6dd899adc9a6b RY(theta₂₅) 9b7d9188d4d9417693f60c889ac7bbf8--c08adbd416954441ada6dd899adc9a6b 79229a5405ed4600a95068fefa704e7b RX(theta₃₁) c08adbd416954441ada6dd899adc9a6b--79229a5405ed4600a95068fefa704e7b 5c34db55132d4749844d937cc6244c61 79229a5405ed4600a95068fefa704e7b--5c34db55132d4749844d937cc6244c61 5c34db55132d4749844d937cc6244c61--af8dc6e651374fda90b52aedfe6098c1 0fd8e1c6d8d3453b844dc939ac4ae2dd 90e79083361742aaa1f820a4ef950e78 RX(theta₂) e4e1fc916fe645738495bc9ad2e40aca--90e79083361742aaa1f820a4ef950e78 b2234ad3e7de47a68e8b4a29b0224642 3 29a67e15b6a14da6a542748d92990c2d RY(theta₈) 90e79083361742aaa1f820a4ef950e78--29a67e15b6a14da6a542748d92990c2d 47bc3875ac7245a7b4a177b5101a1b48 RX(theta₁₄) 29a67e15b6a14da6a542748d92990c2d--47bc3875ac7245a7b4a177b5101a1b48 e605c3452c8e4ab09971ce75c5615127 HamEvo 47bc3875ac7245a7b4a177b5101a1b48--e605c3452c8e4ab09971ce75c5615127 5907b2396afa4d41a1b54794aef8cf6e RX(theta₂₀) e605c3452c8e4ab09971ce75c5615127--5907b2396afa4d41a1b54794aef8cf6e 49e4418a9fd3460dbcba576854f9b7c8 RY(theta₂₆) 5907b2396afa4d41a1b54794aef8cf6e--49e4418a9fd3460dbcba576854f9b7c8 8757a8de26064853a7d01e44d3854376 RX(theta₃₂) 49e4418a9fd3460dbcba576854f9b7c8--8757a8de26064853a7d01e44d3854376 2229cb3d39ac47a0957fb56d7c6289d1 HamEvo 8757a8de26064853a7d01e44d3854376--2229cb3d39ac47a0957fb56d7c6289d1 2229cb3d39ac47a0957fb56d7c6289d1--0fd8e1c6d8d3453b844dc939ac4ae2dd 650b36a286d9426bb4c668251d86404c 9dc4e6ee8b1a4a68ad76e17a1e10b3d5 RX(theta₃) b2234ad3e7de47a68e8b4a29b0224642--9dc4e6ee8b1a4a68ad76e17a1e10b3d5 97232596aafb40dfb21b86db8d83fec4 4 69f2645a95f442b8908c674df19bcbb7 RY(theta₉) 9dc4e6ee8b1a4a68ad76e17a1e10b3d5--69f2645a95f442b8908c674df19bcbb7 7176fab096a34ef784a1a1c8c9c881f9 RX(theta₁₅) 69f2645a95f442b8908c674df19bcbb7--7176fab096a34ef784a1a1c8c9c881f9 4ba35d83278741488d2ec9bf0d5c90e5 t = theta_t₀ 7176fab096a34ef784a1a1c8c9c881f9--4ba35d83278741488d2ec9bf0d5c90e5 29a3b4c5ee9f48c4b6ccba25133446f5 RX(theta₂₁) 4ba35d83278741488d2ec9bf0d5c90e5--29a3b4c5ee9f48c4b6ccba25133446f5 09e2718e53644de38bdc028e5eed245b RY(theta₂₇) 29a3b4c5ee9f48c4b6ccba25133446f5--09e2718e53644de38bdc028e5eed245b b8bc28fe60b741ef90cecf7fad8e57b3 RX(theta₃₃) 09e2718e53644de38bdc028e5eed245b--b8bc28fe60b741ef90cecf7fad8e57b3 c03c6172c7a447baa4afb28655fe81c9 t = theta_t₁ b8bc28fe60b741ef90cecf7fad8e57b3--c03c6172c7a447baa4afb28655fe81c9 c03c6172c7a447baa4afb28655fe81c9--650b36a286d9426bb4c668251d86404c ad12b641cc7947eca728d4b68bff4d66 01b839853f8d47b58a69c2d6349673cd RX(theta₄) 97232596aafb40dfb21b86db8d83fec4--01b839853f8d47b58a69c2d6349673cd ff9f695c780c453d9b580b31b5d53319 5 85f703ce043c406cac932b748ca5f57c RY(theta₁₀) 01b839853f8d47b58a69c2d6349673cd--85f703ce043c406cac932b748ca5f57c 79e85f1035284dea84e9a758071d7013 RX(theta₁₆) 85f703ce043c406cac932b748ca5f57c--79e85f1035284dea84e9a758071d7013 38688f2d16cc41fbbd1832e2c38db87b 79e85f1035284dea84e9a758071d7013--38688f2d16cc41fbbd1832e2c38db87b 93b172843a2e4878892ce8689e8ec135 RX(theta₂₂) 38688f2d16cc41fbbd1832e2c38db87b--93b172843a2e4878892ce8689e8ec135 76936e4356dc40b9835863dd90ce8b77 RY(theta₂₈) 93b172843a2e4878892ce8689e8ec135--76936e4356dc40b9835863dd90ce8b77 b5ae20952f3f41c29679a12ef993c677 RX(theta₃₄) 76936e4356dc40b9835863dd90ce8b77--b5ae20952f3f41c29679a12ef993c677 3beeb6160b674decaaa9e98606db9326 b5ae20952f3f41c29679a12ef993c677--3beeb6160b674decaaa9e98606db9326 3beeb6160b674decaaa9e98606db9326--ad12b641cc7947eca728d4b68bff4d66 66b41b8916d94795bee3f9fb1528fff6 d969ad1f918a4693bd8598fc473317ba RX(theta₅) ff9f695c780c453d9b580b31b5d53319--d969ad1f918a4693bd8598fc473317ba 73f05ab42c604be88c1f56dd347defb7 RY(theta₁₁) d969ad1f918a4693bd8598fc473317ba--73f05ab42c604be88c1f56dd347defb7 9623054ec3ac4e13923abef75f5ea744 RX(theta₁₇) 73f05ab42c604be88c1f56dd347defb7--9623054ec3ac4e13923abef75f5ea744 f6b72d1310a74d9a804bcbacd7c5d6c4 9623054ec3ac4e13923abef75f5ea744--f6b72d1310a74d9a804bcbacd7c5d6c4 e40ca65fe9a44441907c7a6e60af7ef9 RX(theta₂₃) f6b72d1310a74d9a804bcbacd7c5d6c4--e40ca65fe9a44441907c7a6e60af7ef9 4edc46530a47479a9b5290693341e781 RY(theta₂₉) e40ca65fe9a44441907c7a6e60af7ef9--4edc46530a47479a9b5290693341e781 b284abdf2ca9469fb148dd4423c398dc RX(theta₃₅) 4edc46530a47479a9b5290693341e781--b284abdf2ca9469fb148dd4423c398dc 775706d1042a44f7a4fda33244edce4f b284abdf2ca9469fb148dd4423c398dc--775706d1042a44f7a4fda33244edce4f 775706d1042a44f7a4fda33244edce4f--66b41b8916d94795bee3f9fb1528fff6