Skip to content

qadence.draw example plots

Mostly for quick, manual checking of correct plotting output.

from qadence import X, Y, kron
from qadence.draw import display

b = kron(X(0), Y(1))
%3 ea3a6fc0965747489971340ca700abbb 0 db7a05854d814498b9780d20919ef1a7 X ea3a6fc0965747489971340ca700abbb--db7a05854d814498b9780d20919ef1a7 5683bb9e20c74be0915df738c0779c02 1 c31ab21b738f4b0688330d98d16f9f79 db7a05854d814498b9780d20919ef1a7--c31ab21b738f4b0688330d98d16f9f79 913c41db6acd4e5a95150a204abc3a24 7baf467ea48c4bf58ced99185f3e57cb Y 5683bb9e20c74be0915df738c0779c02--7baf467ea48c4bf58ced99185f3e57cb 7baf467ea48c4bf58ced99185f3e57cb--913c41db6acd4e5a95150a204abc3a24
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 ae39fff1855d4dfd9cbd494a57b18f42 0 57ade647fbf040d9b3a7443bdb7f87f9 X ae39fff1855d4dfd9cbd494a57b18f42--57ade647fbf040d9b3a7443bdb7f87f9 452c3168cc6041ee819060e9e9ab140c Y 57ade647fbf040d9b3a7443bdb7f87f9--452c3168cc6041ee819060e9e9ab140c df49b998c7ca4605b7cb5f2ce605a1bb 452c3168cc6041ee819060e9e9ab140c--df49b998c7ca4605b7cb5f2ce605a1bb
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 35c76a38b09b404ab7204f92943fd81f 0 5efc8fe0ac754d7599fd4ea625746365 X 35c76a38b09b404ab7204f92943fd81f--5efc8fe0ac754d7599fd4ea625746365 bc881c28eec34a4cb7b8d9a3cd210bfd 1 8fc821a64c8c443181e87297c0af9d70 5efc8fe0ac754d7599fd4ea625746365--8fc821a64c8c443181e87297c0af9d70 71e9e0df97c842499b06392cfb344e59 8fc821a64c8c443181e87297c0af9d70--71e9e0df97c842499b06392cfb344e59 8b09f14e217149bc8cb0832d5fc065ed 6879edadfdbb4d3c9ece4a858444eed9 bc881c28eec34a4cb7b8d9a3cd210bfd--6879edadfdbb4d3c9ece4a858444eed9 f83f512f7e9647979466978b69d4ba15 Y 6879edadfdbb4d3c9ece4a858444eed9--f83f512f7e9647979466978b69d4ba15 f83f512f7e9647979466978b69d4ba15--8b09f14e217149bc8cb0832d5fc065ed
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_ec35cc375dcf42269bb787ba7abd934a cbe4686c4ec84720b9cb0e8ed440fff9 0 2d586e12f9224bc6a04e143b1536b172 cbe4686c4ec84720b9cb0e8ed440fff9--2d586e12f9224bc6a04e143b1536b172 a974dd82799b40728d53933c1332b1d3 1 3f4bd25476804e56a8ba97d10f343fe7 2d586e12f9224bc6a04e143b1536b172--3f4bd25476804e56a8ba97d10f343fe7 0f22847e945d45f487ffc0f5bbfc8e10 541e6424765a4e24bde14a1982ea4613 AddBlock a974dd82799b40728d53933c1332b1d3--541e6424765a4e24bde14a1982ea4613 705f155ad8264c1aa76e88e5b16ceeaf 2 541e6424765a4e24bde14a1982ea4613--0f22847e945d45f487ffc0f5bbfc8e10 7af3238a476b4d28a8fbdae6572039a6 a4b18fc48fc941eb923ece6c237ad953 705f155ad8264c1aa76e88e5b16ceeaf--a4b18fc48fc941eb923ece6c237ad953 a4b18fc48fc941eb923ece6c237ad953--7af3238a476b4d28a8fbdae6572039a6
from qadence import CNOT, RX, HamEvo, X, Y, Z, chain, kron

rx = kron(RX(3,0.5), RX(2, "x"))
rx.tag = "rx"
gen = chain(Z(i) for i in range(4))

# `chain` puts things in sequence
block = chain(
    kron(X(0), Y(1), rx),
    CNOT(2,3),
    HamEvo(gen, 10)
)
%3 cluster_04e93f7d607248af8982ecf149f3a7d4 cluster_63dd6987ac46423ba526207a78b77e44 rx 134732a60c914c1db0a62b680ad2155d 0 872ea326c6f24e46954e881a60de6d88 X 134732a60c914c1db0a62b680ad2155d--872ea326c6f24e46954e881a60de6d88 3f491f14ced342d69709aa615bcfce5d 1 143fabbd9e454f77b5ac95b155dd28df 872ea326c6f24e46954e881a60de6d88--143fabbd9e454f77b5ac95b155dd28df 0f5733e31b6f440898a0fb2bbaa92a50 143fabbd9e454f77b5ac95b155dd28df--0f5733e31b6f440898a0fb2bbaa92a50 da76319a5d5e4d8584937a96ae521321 0f5733e31b6f440898a0fb2bbaa92a50--da76319a5d5e4d8584937a96ae521321 5cd4999d1d344627b21a50914b2d395a 87b8aed5e9dd4fff9a8105c779cf7821 Y 3f491f14ced342d69709aa615bcfce5d--87b8aed5e9dd4fff9a8105c779cf7821 c8b019a7af5f4dfe87ac03368151ab2c 2 4a74a34b210346d2817a542ad63a905f 87b8aed5e9dd4fff9a8105c779cf7821--4a74a34b210346d2817a542ad63a905f 2f1d5928c4584aefa3381adc40373e20 HamEvo 4a74a34b210346d2817a542ad63a905f--2f1d5928c4584aefa3381adc40373e20 2f1d5928c4584aefa3381adc40373e20--5cd4999d1d344627b21a50914b2d395a d3b3181c55274d398356d7c65f198ef4 985d03af96e540f2b06c46370069aa15 RX(x) c8b019a7af5f4dfe87ac03368151ab2c--985d03af96e540f2b06c46370069aa15 4a684f8cf1694c9ea2588dcae87275a9 3 a06ac8032071489691fb9290d7ef3e5c 985d03af96e540f2b06c46370069aa15--a06ac8032071489691fb9290d7ef3e5c 9ebe407e177f46f6a3eb887ccfebda73 t = 10 a06ac8032071489691fb9290d7ef3e5c--9ebe407e177f46f6a3eb887ccfebda73 9ebe407e177f46f6a3eb887ccfebda73--d3b3181c55274d398356d7c65f198ef4 facc2d14bdaf46889108385fa0aa702b 2870dd6b73de4ab2945a5a48a30ab359 RX(0.5) 4a684f8cf1694c9ea2588dcae87275a9--2870dd6b73de4ab2945a5a48a30ab359 18245ccee0e149a5aaa261ceff74ffd9 X 2870dd6b73de4ab2945a5a48a30ab359--18245ccee0e149a5aaa261ceff74ffd9 18245ccee0e149a5aaa261ceff74ffd9--a06ac8032071489691fb9290d7ef3e5c fc0c58660ef14ce9b760685b2c7d457a 18245ccee0e149a5aaa261ceff74ffd9--fc0c58660ef14ce9b760685b2c7d457a fc0c58660ef14ce9b760685b2c7d457a--facc2d14bdaf46889108385fa0aa702b
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_b4f8381b420b471b8b28dd680d174ec4 HEA cluster_1b00ddfbc0c54cafbd9a6619eb65fd4d Tower Fourier FM d32f26c285af4598afe5a06ec2424e57 0 80290867492f4caf87818109cffd1b45 RX(1.0*phi) d32f26c285af4598afe5a06ec2424e57--80290867492f4caf87818109cffd1b45 a9c10a3bace04b6a8a36f284c9f1b152 1 73bcc204cfc24938a06940dda6ce5fb1 RX(theta₀) 80290867492f4caf87818109cffd1b45--73bcc204cfc24938a06940dda6ce5fb1 448a2073db1840de8008eac87997712c RY(theta₄) 73bcc204cfc24938a06940dda6ce5fb1--448a2073db1840de8008eac87997712c a9ab29feb938416fa20cb2936d59df99 RX(theta₈) 448a2073db1840de8008eac87997712c--a9ab29feb938416fa20cb2936d59df99 f9f86dc98c7d4b78b639eb8248fe6b5b a9ab29feb938416fa20cb2936d59df99--f9f86dc98c7d4b78b639eb8248fe6b5b 1bfcac33965849fdb12e84614bb2565a f9f86dc98c7d4b78b639eb8248fe6b5b--1bfcac33965849fdb12e84614bb2565a c0ced519d0ec4b32aed5f49a5c550bb9 RX(theta₁₂) 1bfcac33965849fdb12e84614bb2565a--c0ced519d0ec4b32aed5f49a5c550bb9 4328add5de1743e1a771b115c5823d1b RY(theta₁₆) c0ced519d0ec4b32aed5f49a5c550bb9--4328add5de1743e1a771b115c5823d1b f7ac9fd4b6194d048978c8a952fb39bc RX(theta₂₀) 4328add5de1743e1a771b115c5823d1b--f7ac9fd4b6194d048978c8a952fb39bc 4397dc1bb80b4a01bd0798a7585f6e68 f7ac9fd4b6194d048978c8a952fb39bc--4397dc1bb80b4a01bd0798a7585f6e68 3a1c8b607fdd4f979759634212ae7ede 4397dc1bb80b4a01bd0798a7585f6e68--3a1c8b607fdd4f979759634212ae7ede c91b97134195411c8b9b3cf4595206d9 3a1c8b607fdd4f979759634212ae7ede--c91b97134195411c8b9b3cf4595206d9 9dff0401cecb4fbd9c48acef9eaa1fa7 e6d00184d0754bf4b90fb48e4b04e001 RX(2.0*phi) a9c10a3bace04b6a8a36f284c9f1b152--e6d00184d0754bf4b90fb48e4b04e001 15bd946dc4ec46289b5a7ca7affa9b60 2 12d1669e60f54cacacd1211be7cc9bb5 RX(theta₁) e6d00184d0754bf4b90fb48e4b04e001--12d1669e60f54cacacd1211be7cc9bb5 b376ed79fbce418698194afe6c507ff7 RY(theta₅) 12d1669e60f54cacacd1211be7cc9bb5--b376ed79fbce418698194afe6c507ff7 f698e09f9b0148419e70991fafbfa8e3 RX(theta₉) b376ed79fbce418698194afe6c507ff7--f698e09f9b0148419e70991fafbfa8e3 5a0c72afac834e088665148a5635b2ac X f698e09f9b0148419e70991fafbfa8e3--5a0c72afac834e088665148a5635b2ac 5a0c72afac834e088665148a5635b2ac--f9f86dc98c7d4b78b639eb8248fe6b5b 5f3cd2a8623746debd77f9311855cf38 5a0c72afac834e088665148a5635b2ac--5f3cd2a8623746debd77f9311855cf38 21252d01cb464a618c005817132ed676 RX(theta₁₃) 5f3cd2a8623746debd77f9311855cf38--21252d01cb464a618c005817132ed676 ded6779736714202a96630ef320c72bf RY(theta₁₇) 21252d01cb464a618c005817132ed676--ded6779736714202a96630ef320c72bf ab3ac6ba347b486ebf0e4ba733ad96e6 RX(theta₂₁) ded6779736714202a96630ef320c72bf--ab3ac6ba347b486ebf0e4ba733ad96e6 aeb29d144f8c476e9dad1dff535aeac7 X ab3ac6ba347b486ebf0e4ba733ad96e6--aeb29d144f8c476e9dad1dff535aeac7 aeb29d144f8c476e9dad1dff535aeac7--4397dc1bb80b4a01bd0798a7585f6e68 5deb62e7d8d04a99991f793400c73d9c aeb29d144f8c476e9dad1dff535aeac7--5deb62e7d8d04a99991f793400c73d9c 5deb62e7d8d04a99991f793400c73d9c--9dff0401cecb4fbd9c48acef9eaa1fa7 6dd74ac0cd2047c4880e2d6ccd9be73b 0bc43ab96f1c4d2884bbb9591bd4be2d RX(3.0*phi) 15bd946dc4ec46289b5a7ca7affa9b60--0bc43ab96f1c4d2884bbb9591bd4be2d b7adfcc7734144de8dfd3febd660f19c 3 6d71dfb24e6b4c54962164a6e62cc7a6 RX(theta₂) 0bc43ab96f1c4d2884bbb9591bd4be2d--6d71dfb24e6b4c54962164a6e62cc7a6 ba2ab0bd965244c8b5b7e0ca2fa9176a RY(theta₆) 6d71dfb24e6b4c54962164a6e62cc7a6--ba2ab0bd965244c8b5b7e0ca2fa9176a 1fb6babeb55d4660905f47ca93b8cdb5 RX(theta₁₀) ba2ab0bd965244c8b5b7e0ca2fa9176a--1fb6babeb55d4660905f47ca93b8cdb5 4a679f0372734c8e99a56987edc2f003 1fb6babeb55d4660905f47ca93b8cdb5--4a679f0372734c8e99a56987edc2f003 3dde3dda5c8048409722c4791145ac9c X 4a679f0372734c8e99a56987edc2f003--3dde3dda5c8048409722c4791145ac9c 3dde3dda5c8048409722c4791145ac9c--5f3cd2a8623746debd77f9311855cf38 566faa597e2f42679732457a2bc5e6b8 RX(theta₁₄) 3dde3dda5c8048409722c4791145ac9c--566faa597e2f42679732457a2bc5e6b8 42ce35b4a5ca4d3a9944f708ef3ef811 RY(theta₁₈) 566faa597e2f42679732457a2bc5e6b8--42ce35b4a5ca4d3a9944f708ef3ef811 5d54115bedda4aed9ed096597f8edd64 RX(theta₂₂) 42ce35b4a5ca4d3a9944f708ef3ef811--5d54115bedda4aed9ed096597f8edd64 ed280a78dca34999b08d2d907c67bb08 5d54115bedda4aed9ed096597f8edd64--ed280a78dca34999b08d2d907c67bb08 65a90df30f024b91b44e8ed0d92a0235 X ed280a78dca34999b08d2d907c67bb08--65a90df30f024b91b44e8ed0d92a0235 65a90df30f024b91b44e8ed0d92a0235--5deb62e7d8d04a99991f793400c73d9c 65a90df30f024b91b44e8ed0d92a0235--6dd74ac0cd2047c4880e2d6ccd9be73b fa361d61960a4c36afc55d0d44b356ca f7d7d242b9644a3495ff888333594bd5 RX(4.0*phi) b7adfcc7734144de8dfd3febd660f19c--f7d7d242b9644a3495ff888333594bd5 6e351e9c29984d81a853b820a3a239b6 RX(theta₃) f7d7d242b9644a3495ff888333594bd5--6e351e9c29984d81a853b820a3a239b6 d7f0ea2ba2624010873f8b4d14ef1814 RY(theta₇) 6e351e9c29984d81a853b820a3a239b6--d7f0ea2ba2624010873f8b4d14ef1814 87091cc10d2744689545e60826219483 RX(theta₁₁) d7f0ea2ba2624010873f8b4d14ef1814--87091cc10d2744689545e60826219483 fe1e157317c4472db09cc622ca71e709 X 87091cc10d2744689545e60826219483--fe1e157317c4472db09cc622ca71e709 fe1e157317c4472db09cc622ca71e709--4a679f0372734c8e99a56987edc2f003 d1ad482e544c42c3b843dcd570b39f23 fe1e157317c4472db09cc622ca71e709--d1ad482e544c42c3b843dcd570b39f23 a095d0660d00493eb607395fdab622a7 RX(theta₁₅) d1ad482e544c42c3b843dcd570b39f23--a095d0660d00493eb607395fdab622a7 23a0a07083474efc8ca1d6207da0a07d RY(theta₁₉) a095d0660d00493eb607395fdab622a7--23a0a07083474efc8ca1d6207da0a07d 2e0b9a092c9a45a4b5f81115141b5447 RX(theta₂₃) 23a0a07083474efc8ca1d6207da0a07d--2e0b9a092c9a45a4b5f81115141b5447 cd587883368f4292bf96b2b49cedb9e4 X 2e0b9a092c9a45a4b5f81115141b5447--cd587883368f4292bf96b2b49cedb9e4 cd587883368f4292bf96b2b49cedb9e4--ed280a78dca34999b08d2d907c67bb08 0cb47cd59b8c46ca95f94756792be519 cd587883368f4292bf96b2b49cedb9e4--0cb47cd59b8c46ca95f94756792be519 0cb47cd59b8c46ca95f94756792be519--fa361d61960a4c36afc55d0d44b356ca
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_4fbd1ed68c174fcf832b4812e1055b11 Obs. cluster_f0b090275dab49d78b7fe26df98ba65c cluster_6048a57f87f84134974297c1ffd7e580 HEA b6134b79f799460eab2b7ea0334e7d0f 0 448f88f4add842c0a92590a3617c4e94 RX(theta₀) b6134b79f799460eab2b7ea0334e7d0f--448f88f4add842c0a92590a3617c4e94 b689e5417bdb4fab8f7e4fd59f7129c8 1 eff097ffc22e43b8bc972d597f9df750 RY(theta₃) 448f88f4add842c0a92590a3617c4e94--eff097ffc22e43b8bc972d597f9df750 4d227938a8684f878872733a060ac383 RX(theta₆) eff097ffc22e43b8bc972d597f9df750--4d227938a8684f878872733a060ac383 746ea89f60e04e9d9bdbe560653aa17a 4d227938a8684f878872733a060ac383--746ea89f60e04e9d9bdbe560653aa17a 837e1e7351654e94ab01d21bd48c75cc 746ea89f60e04e9d9bdbe560653aa17a--837e1e7351654e94ab01d21bd48c75cc 8936ab4c1d0c4b48978ba8a1cc70d54d RX(theta₉) 837e1e7351654e94ab01d21bd48c75cc--8936ab4c1d0c4b48978ba8a1cc70d54d 93c2eb3e4e5644dcbf66ce75e03e1b4a RY(theta₁₂) 8936ab4c1d0c4b48978ba8a1cc70d54d--93c2eb3e4e5644dcbf66ce75e03e1b4a 3a40d5458f1147748e367f5ef332a5b6 RX(theta₁₅) 93c2eb3e4e5644dcbf66ce75e03e1b4a--3a40d5458f1147748e367f5ef332a5b6 52dbd6eecd914063940fc29183ad5d96 3a40d5458f1147748e367f5ef332a5b6--52dbd6eecd914063940fc29183ad5d96 ee7cc302e6e641f4b7a0ab2b27dc26cf 52dbd6eecd914063940fc29183ad5d96--ee7cc302e6e641f4b7a0ab2b27dc26cf 8ab10f09a2ab40789651e441f4f39cfa ee7cc302e6e641f4b7a0ab2b27dc26cf--8ab10f09a2ab40789651e441f4f39cfa dc61c440a58942fe839b75780c599576 8ab10f09a2ab40789651e441f4f39cfa--dc61c440a58942fe839b75780c599576 24e295fa290b4efb956bd466c9e551ed 51eb68e70c7a4543bf39ad28fddf54ec RX(theta₁) b689e5417bdb4fab8f7e4fd59f7129c8--51eb68e70c7a4543bf39ad28fddf54ec 87e6483f9f5e4e548cbc2dfbcbb530c5 2 88aebf5ee8bd4df7a1f1e2b5fe9cdaa7 RY(theta₄) 51eb68e70c7a4543bf39ad28fddf54ec--88aebf5ee8bd4df7a1f1e2b5fe9cdaa7 4365cda80c1b4ed7bf8d2b1bdf4a9ecb RX(theta₇) 88aebf5ee8bd4df7a1f1e2b5fe9cdaa7--4365cda80c1b4ed7bf8d2b1bdf4a9ecb 0d22c193e310455184dee7ab43cefe97 X 4365cda80c1b4ed7bf8d2b1bdf4a9ecb--0d22c193e310455184dee7ab43cefe97 0d22c193e310455184dee7ab43cefe97--746ea89f60e04e9d9bdbe560653aa17a a0ccf87b8dce46a7a13194dc2a6f5f0a 0d22c193e310455184dee7ab43cefe97--a0ccf87b8dce46a7a13194dc2a6f5f0a c255c1a8706c4e019f88bcec4bb23037 RX(theta₁₀) a0ccf87b8dce46a7a13194dc2a6f5f0a--c255c1a8706c4e019f88bcec4bb23037 98b08abd81534f8f8d64d942bac73046 RY(theta₁₃) c255c1a8706c4e019f88bcec4bb23037--98b08abd81534f8f8d64d942bac73046 22d2bc4340784fedaf25904b91c8fc05 RX(theta₁₆) 98b08abd81534f8f8d64d942bac73046--22d2bc4340784fedaf25904b91c8fc05 15ebd7545f1c4a0899f1963500d0225a X 22d2bc4340784fedaf25904b91c8fc05--15ebd7545f1c4a0899f1963500d0225a 15ebd7545f1c4a0899f1963500d0225a--52dbd6eecd914063940fc29183ad5d96 edbee4f01b4b4ccf9928a2cee0e4c70c 15ebd7545f1c4a0899f1963500d0225a--edbee4f01b4b4ccf9928a2cee0e4c70c 6ff9ab24cae2479d94b0986337b5f661 AddBlock edbee4f01b4b4ccf9928a2cee0e4c70c--6ff9ab24cae2479d94b0986337b5f661 6ff9ab24cae2479d94b0986337b5f661--24e295fa290b4efb956bd466c9e551ed 6742838605ba44f98e45b7ec547102f1 23b7861878d742b68dc7e8a7154df128 RX(theta₂) 87e6483f9f5e4e548cbc2dfbcbb530c5--23b7861878d742b68dc7e8a7154df128 f64abe8fe94848eb97f963219a6b0d82 RY(theta₅) 23b7861878d742b68dc7e8a7154df128--f64abe8fe94848eb97f963219a6b0d82 8f7d98d5ca1441dd90f70950b4a21c11 RX(theta₈) f64abe8fe94848eb97f963219a6b0d82--8f7d98d5ca1441dd90f70950b4a21c11 5173262d4b2145b8a9ef247745a011bc 8f7d98d5ca1441dd90f70950b4a21c11--5173262d4b2145b8a9ef247745a011bc 9854b72903524895bf6e6b6146c4f6a8 X 5173262d4b2145b8a9ef247745a011bc--9854b72903524895bf6e6b6146c4f6a8 9854b72903524895bf6e6b6146c4f6a8--a0ccf87b8dce46a7a13194dc2a6f5f0a 0900d320f7104312aa7d5278d98eab8f RX(theta₁₁) 9854b72903524895bf6e6b6146c4f6a8--0900d320f7104312aa7d5278d98eab8f 0f04a85bcfb54757bb24501c34e51723 RY(theta₁₄) 0900d320f7104312aa7d5278d98eab8f--0f04a85bcfb54757bb24501c34e51723 c89da84eef60463cb760b5295d9c7df5 RX(theta₁₇) 0f04a85bcfb54757bb24501c34e51723--c89da84eef60463cb760b5295d9c7df5 c12396fc2e20470aadd7d0b3feced463 c89da84eef60463cb760b5295d9c7df5--c12396fc2e20470aadd7d0b3feced463 7e4d229742e34d2186e0199af6147675 X c12396fc2e20470aadd7d0b3feced463--7e4d229742e34d2186e0199af6147675 7e4d229742e34d2186e0199af6147675--edbee4f01b4b4ccf9928a2cee0e4c70c 0579517ba25141d98a405cb152b305fc 7e4d229742e34d2186e0199af6147675--0579517ba25141d98a405cb152b305fc 0579517ba25141d98a405cb152b305fc--6742838605ba44f98e45b7ec547102f1
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 fa30a9550f7542c8933ab6c989ebdcce 0 1539e49d52f44801942c94d1dde32c02 fa30a9550f7542c8933ab6c989ebdcce--1539e49d52f44801942c94d1dde32c02 c0185a6e7b4844cfbf17142283ccb3b0 1 ff6a2fd9cd234bc7a379ffae11f5cb37 21affcd21b7b4d29abc5fd04056cefd2 1539e49d52f44801942c94d1dde32c02--21affcd21b7b4d29abc5fd04056cefd2 6059256caa5240f7b700903544bd9feb ff6a2fd9cd234bc7a379ffae11f5cb37--6059256caa5240f7b700903544bd9feb 6ff135b9235e43b9b7e5115bbcb6998b 2618114e80c74ca494aa6700b6efa1b3 6059256caa5240f7b700903544bd9feb--2618114e80c74ca494aa6700b6efa1b3 fda47add550247f680bfd55086f99963 6ff135b9235e43b9b7e5115bbcb6998b--fda47add550247f680bfd55086f99963 bc4ebd293c36482bbb495d76368fadd0 e07b8c34c0744c87b6624f7e589f58ba c0185a6e7b4844cfbf17142283ccb3b0--e07b8c34c0744c87b6624f7e589f58ba b6b7ce55ff5e401db06f08e3e6cacd15 2 e07b8c34c0744c87b6624f7e589f58ba--ff6a2fd9cd234bc7a379ffae11f5cb37 2b399b548eed4c259a8dd907bf2ba445 21affcd21b7b4d29abc5fd04056cefd2--2b399b548eed4c259a8dd907bf2ba445 00b91461101f4ce488e7bbfd66098de0 2b399b548eed4c259a8dd907bf2ba445--00b91461101f4ce488e7bbfd66098de0 00b91461101f4ce488e7bbfd66098de0--bc4ebd293c36482bbb495d76368fadd0 987295ade70445268b12337c5b2caea3 b58b644fc14f447cb71ba37c7b646e1c b6b7ce55ff5e401db06f08e3e6cacd15--b58b644fc14f447cb71ba37c7b646e1c 63934f0ed1804500a63041c494fdfdec 3 26eb604a2854413eb73c7fdcc8d9c837 b58b644fc14f447cb71ba37c7b646e1c--26eb604a2854413eb73c7fdcc8d9c837 c368ea135d8849a0b3cbaf512163e37b 26eb604a2854413eb73c7fdcc8d9c837--c368ea135d8849a0b3cbaf512163e37b 120d74383355434a929d73ad68bba56a c368ea135d8849a0b3cbaf512163e37b--120d74383355434a929d73ad68bba56a 120d74383355434a929d73ad68bba56a--987295ade70445268b12337c5b2caea3 f50fec0f037345d8a9c32d012b96002d 6a5f6016da6c4bde99b8edb5e4954797 63934f0ed1804500a63041c494fdfdec--6a5f6016da6c4bde99b8edb5e4954797 eefe3512f35c43d08ac75a1c3cf47235 6a5f6016da6c4bde99b8edb5e4954797--eefe3512f35c43d08ac75a1c3cf47235 b27940b82c5c404fa04943716ffbd21e eefe3512f35c43d08ac75a1c3cf47235--b27940b82c5c404fa04943716ffbd21e b27940b82c5c404fa04943716ffbd21e--6ff135b9235e43b9b7e5115bbcb6998b 2618114e80c74ca494aa6700b6efa1b3--f50fec0f037345d8a9c32d012b96002d
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 83040ccde2be4f31870a7cfdaac9bc9c 0 2736c6b575f04ec3a48ede1744540b54 83040ccde2be4f31870a7cfdaac9bc9c--2736c6b575f04ec3a48ede1744540b54 9db970487e5e4d528022e10cd7053b0f 1 328202458c804bb59f58e244ef29ccb9 2736c6b575f04ec3a48ede1744540b54--328202458c804bb59f58e244ef29ccb9 ace96c0424f54910b08901a852125e81 328202458c804bb59f58e244ef29ccb9--ace96c0424f54910b08901a852125e81 161787a80dd844258cb401057868c4a5 ace96c0424f54910b08901a852125e81--161787a80dd844258cb401057868c4a5 fe5f5e791bd145908821443a8db5ed8a 39aa94b1ecd9434fa427034245e188b3 PHASE(0.5) 9db970487e5e4d528022e10cd7053b0f--39aa94b1ecd9434fa427034245e188b3 6d384ea2418e44a09b3610ab9e275e12 2 39aa94b1ecd9434fa427034245e188b3--2736c6b575f04ec3a48ede1744540b54 a876973252b64ea298edef36fff9fc9c 39aa94b1ecd9434fa427034245e188b3--a876973252b64ea298edef36fff9fc9c 969f341bfb13404caf849a8e2410b0a7 a876973252b64ea298edef36fff9fc9c--969f341bfb13404caf849a8e2410b0a7 969f341bfb13404caf849a8e2410b0a7--fe5f5e791bd145908821443a8db5ed8a 6290b7efc231487b8fdc02c5e9829231 02bf8718ba37465b9a2e1ccc224de327 6d384ea2418e44a09b3610ab9e275e12--02bf8718ba37465b9a2e1ccc224de327 c008d45dfd0f44ae97e827d86f2cd47b 3 bfb2e972afed4e9082d814ba097df7e8 PHASE(0.5) 02bf8718ba37465b9a2e1ccc224de327--bfb2e972afed4e9082d814ba097df7e8 bfb2e972afed4e9082d814ba097df7e8--328202458c804bb59f58e244ef29ccb9 bd111215190c4c509bf1537d9819315b bfb2e972afed4e9082d814ba097df7e8--bd111215190c4c509bf1537d9819315b bd111215190c4c509bf1537d9819315b--6290b7efc231487b8fdc02c5e9829231 464d127c928b4ecbbab91d366488cf1c 42403c8af8eb4ad4b0e0533835b84057 c008d45dfd0f44ae97e827d86f2cd47b--42403c8af8eb4ad4b0e0533835b84057 d05ef54029864f2ba20361262b23738d 42403c8af8eb4ad4b0e0533835b84057--d05ef54029864f2ba20361262b23738d c326ae7d7c714ce9a5036392dec25539 PHASE(0.5) d05ef54029864f2ba20361262b23738d--c326ae7d7c714ce9a5036392dec25539 c326ae7d7c714ce9a5036392dec25539--ace96c0424f54910b08901a852125e81 c326ae7d7c714ce9a5036392dec25539--464d127c928b4ecbbab91d366488cf1c

Developer documentation

This section contains examples in pure graphviz that can be used to understand roughly what is done in the actual drawing backend.

import graphviz

font_name = "Sans-Serif"
font_size = "8"

graph_attr = {
    "rankdir": "LR",  # LR = left to right, TB = top to bottom
    "nodesep": "0.1",  # In inches, tells distance between nodes without edges
    "compound": "true",  # Needed to draw properly edges in hamevo when content is hidden
    "splines": "false",  # Needed to draw control gates vertical lines one over the other
}  # These are the default values for graphs

node_attr = {
    "shape": "box",  # 'box' for normal nodes, 'point' for control gates or 'plaintext' for starting nodes (the qubit label).
    "style": "rounded",  # Unfortunately we can't specify the radius of the rounded, at least for this version
    "fontname": font_name,
    "fontsize": font_size,
    "width": "0.1",  # In inches, it doesn't get tinier than the label font.
    "height": "0.1"  # In inches, it doesn't get tinier than the label font.
}  # These are the defaults values that can be overridden at node declaration.

default_cluster_attr = {
    "fontname": font_name,
    "fontsize": font_size,
    "labelloc": "b",  # location of cluster label. b as bottom, t as top
    "style": "rounded"
} # These are the defaults values that can be overridden at sub graph declaration

hamevo_cluster_attr = {
    "label": "HamEvo(t=10)"
}
hamevo_cluster_attr.update(default_cluster_attr)

h = graphviz.Graph(graph_attr=graph_attr, node_attr=node_attr)
h.node("Hello World!")
h

# Define graph
h = graphviz.Graph(node_attr=node_attr, graph_attr=graph_attr)

# Add start and end nodes
for i in range(4):
    h.node(f's{i}', shape="plaintext", label=f'{i}', group=f"{i}")
    h.node(f'e{i}', style='invis', group=f"{i}")

# Add nodes
h.node('X', group="0")
h.node('Y', group="1")

# Add hamevo and its nodes
hamevo = graphviz.Graph(name='cluster_hamevo', graph_attr=hamevo_cluster_attr)
for i in range(4):
    hamevo.node(f'z{i}', shape="box", style="invis", label=f'{i}', group=f"{i}")
h.subgraph(hamevo)

# Add rx gates cluster and its nodes
cluster_attr = {"label": "RX gates"}
cluster_attr.update(default_cluster_attr)
cluster = graphviz.Graph(name="cluster_0", graph_attr=cluster_attr)
cluster.node('RX(x)', group="2")
cluster.node('RX(0.5)', group="3")
h.subgraph(cluster)

h.node('cnot0', label='', shape='point', width='0.1', group='0')
h.node('cnot1', label='X', group='1')
h.node('cnot2', label='', shape='point', width='0.1', group='2')
h.node('cnot3', label='', shape='point', width='0.1', group='3')

# Add edges
h.edge('s0', 'X')
h.edge('X', 'cnot0')
h.edge('cnot0', 'z0', lhead='cluster_hamevo')
h.edge('z0', 'e0', ltail='cluster_hamevo')
h.edge('s1', 'Y')
h.edge('Y', 'cnot1')
h.edge('cnot1', 'z1', lhead='cluster_hamevo')
h.edge('z1', 'e1', ltail='cluster_hamevo')
h.edge('s2', 'RX(x)')
h.edge('RX(x)', 'cnot2')
h.edge('cnot2', 'z2', lhead='cluster_hamevo')
h.edge('z2', 'e2', ltail='cluster_hamevo')
h.edge('s3', 'RX(0.5)')
h.edge('RX(0.5)', 'cnot3')
h.edge('cnot3', 'z3', lhead='cluster_hamevo')
h.edge('z3', 'e3', ltail='cluster_hamevo')
h.edge('cnot1', 'cnot0', constraint='false')  # constraint: false is needed to draw vertical edges
h.edge('cnot1', 'cnot2', constraint='false')  # constraint: false is needed to draw vertical edges
h.edge('cnot1', 'cnot3', constraint='false')  # constraint: false is needed to draw vertical edges
h

Example of cluster of clusters

# Define graph
h = graphviz.Graph(node_attr=node_attr, graph_attr=graph_attr)

# Define start and end nodes
for i in range(4):
    h.node(f's{i}', shape="plaintext", label=f'{i}', group=f"{i}")
    h.node(f'e{i}', style='invis', group=f"{i}")

# Define outer cluster
cluster_attr = {"label": "Outer cluster"}
cluster_attr.update(default_cluster_attr)
outer_cluster = graphviz.Graph(name="cluster_outer", graph_attr=cluster_attr)

# Define inner cluster 1 and its nodes
cluster_attr = {"label": "Inner cluster 1"}
cluster_attr.update(default_cluster_attr)
inner1_cluster = graphviz.Graph(name="cluster_inner1", graph_attr=cluster_attr)
inner1_cluster.node("a0", group="0")
inner1_cluster.node("a1", group="1")
outer_cluster.subgraph(inner1_cluster)

# Define inner cluster 2 and its nodes
cluster_attr = {"label": "Inner cluster 2"}
cluster_attr.update(default_cluster_attr)
inner2_cluster = graphviz.Graph(name="cluster_inner2", graph_attr=cluster_attr)
inner2_cluster.node("a2", group="2")
inner2_cluster.node("a3", group="3")
outer_cluster.subgraph(inner2_cluster)

# This has to be done here, after inner clusters definitions
h.subgraph(outer_cluster)

# Define more nodes
for i in range(4):
    h.node(f"b{i}", group=f"{i}")

for i in range(4):
    h.edge(f's{i}', f'a{i}')
    h.edge(f'a{i}', f'b{i}')
    h.edge(f'b{i}', f'e{i}')

h