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 e0bbf1a6af6147c7ad2c5bdf896a8e00 0 9685d1367a3a4d60b806cdcf7598c920 X e0bbf1a6af6147c7ad2c5bdf896a8e00--9685d1367a3a4d60b806cdcf7598c920 a395a4412bf943af9dcf562277dd0039 1 6746bea68ffc4895b85784675ae01db7 9685d1367a3a4d60b806cdcf7598c920--6746bea68ffc4895b85784675ae01db7 802e43da3f7240fd81228dc94da46632 56d7cdcdd48e4584afe4c9c1ee3fe228 Y a395a4412bf943af9dcf562277dd0039--56d7cdcdd48e4584afe4c9c1ee3fe228 56d7cdcdd48e4584afe4c9c1ee3fe228--802e43da3f7240fd81228dc94da46632
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 904edbbd1575457f8b502ccbf3658d91 0 30c9086ecce44eb79285e0e55b3d25ec X 904edbbd1575457f8b502ccbf3658d91--30c9086ecce44eb79285e0e55b3d25ec 65d1bd66729d4a698bc64ea4aceffbc5 Y 30c9086ecce44eb79285e0e55b3d25ec--65d1bd66729d4a698bc64ea4aceffbc5 1a872b09580d48adad84140031e9dffa 65d1bd66729d4a698bc64ea4aceffbc5--1a872b09580d48adad84140031e9dffa
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 491d64098ee84f09983091ff36aea263 0 d726c32bcce447fcba3d83b80adb172e X 491d64098ee84f09983091ff36aea263--d726c32bcce447fcba3d83b80adb172e dbeeb947060944fd895c0a2bd6fe9273 1 8f40326947fb4371b4aac7906ab648cc d726c32bcce447fcba3d83b80adb172e--8f40326947fb4371b4aac7906ab648cc af1cca21d7a24b2aa30d7ca091ceacc7 8f40326947fb4371b4aac7906ab648cc--af1cca21d7a24b2aa30d7ca091ceacc7 c8e706a9d713410790b7a469158b5f0c 8620cd62a9e64d4faca11a0b8e5c2895 dbeeb947060944fd895c0a2bd6fe9273--8620cd62a9e64d4faca11a0b8e5c2895 0f87f5237b1441088bf8403070e736bc Y 8620cd62a9e64d4faca11a0b8e5c2895--0f87f5237b1441088bf8403070e736bc 0f87f5237b1441088bf8403070e736bc--c8e706a9d713410790b7a469158b5f0c
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_b0b8b7a9ee0f41c6a59f272b9896a624 5ed09ab22e44499a94f7d313cf8dac31 0 4f11d480111744dda5b60547bea4c10c 5ed09ab22e44499a94f7d313cf8dac31--4f11d480111744dda5b60547bea4c10c c2b8ad73dfe34a9dbf4bc0c9c68be869 1 316fb5bea4b24f28abaf759191d3f740 4f11d480111744dda5b60547bea4c10c--316fb5bea4b24f28abaf759191d3f740 cefe4435452f466eaec62772713a2868 0e20cc67f69944da846d86056d663b07 AddBlock c2b8ad73dfe34a9dbf4bc0c9c68be869--0e20cc67f69944da846d86056d663b07 20cdadd45c2a46af9678e0d05a20862b 2 0e20cc67f69944da846d86056d663b07--cefe4435452f466eaec62772713a2868 ad66b24594ca43a588cabd21263d10fb b0e0cae0cd6b42b7af242d4e64fbdb8b 20cdadd45c2a46af9678e0d05a20862b--b0e0cae0cd6b42b7af242d4e64fbdb8b b0e0cae0cd6b42b7af242d4e64fbdb8b--ad66b24594ca43a588cabd21263d10fb
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_dfc1458da08b496ab93d7bebc91a3dd0 cluster_75e892cdaede47aca38dce3858080838 rx 1c9f561a2c82451796dd5891ce6c321b 0 3f152414a944466aa91b97900d376992 X 1c9f561a2c82451796dd5891ce6c321b--3f152414a944466aa91b97900d376992 24106a58d6404ac583e8cb9caf585287 1 1c8a9b43b5ca4debaa5e6e501d459c65 3f152414a944466aa91b97900d376992--1c8a9b43b5ca4debaa5e6e501d459c65 44c403e951f5480bbdf7b1b7596213e1 1c8a9b43b5ca4debaa5e6e501d459c65--44c403e951f5480bbdf7b1b7596213e1 9e0620c466ba421dbe9e10584c4a9030 44c403e951f5480bbdf7b1b7596213e1--9e0620c466ba421dbe9e10584c4a9030 f73d191b8fb34fdf8b2f9cf737f76d8f ee82469bd4b444ce9f1bb50a962e73d5 Y 24106a58d6404ac583e8cb9caf585287--ee82469bd4b444ce9f1bb50a962e73d5 5a1b650838c14c6a8a54af9d0e73115c 2 a0d184e87c1a43a0a22c79c739e9bf81 ee82469bd4b444ce9f1bb50a962e73d5--a0d184e87c1a43a0a22c79c739e9bf81 9f178355d1c049698e2dfb3e71aa7cbe HamEvo a0d184e87c1a43a0a22c79c739e9bf81--9f178355d1c049698e2dfb3e71aa7cbe 9f178355d1c049698e2dfb3e71aa7cbe--f73d191b8fb34fdf8b2f9cf737f76d8f f88401fc07e249cd92f935e8e99c9f8e 7d25201340ec47108972fb45a5360cb9 RX(x) 5a1b650838c14c6a8a54af9d0e73115c--7d25201340ec47108972fb45a5360cb9 4b887c04cd124720be2cc14f6ea305b8 3 04fee0e6ab344c3691898886dcd59f24 7d25201340ec47108972fb45a5360cb9--04fee0e6ab344c3691898886dcd59f24 44004c8c55604ad0a8425102b8a1d2aa t = 10 04fee0e6ab344c3691898886dcd59f24--44004c8c55604ad0a8425102b8a1d2aa 44004c8c55604ad0a8425102b8a1d2aa--f88401fc07e249cd92f935e8e99c9f8e 85a2d4b5eb214ab99a5759893c8ee7f0 bb64aba56b77441fab1c6022167ef21d RX(0.5) 4b887c04cd124720be2cc14f6ea305b8--bb64aba56b77441fab1c6022167ef21d ab6e65cdff5d4af69c2f192080956343 X bb64aba56b77441fab1c6022167ef21d--ab6e65cdff5d4af69c2f192080956343 ab6e65cdff5d4af69c2f192080956343--04fee0e6ab344c3691898886dcd59f24 9a964789414843e8ba0e03451ff747bf ab6e65cdff5d4af69c2f192080956343--9a964789414843e8ba0e03451ff747bf 9a964789414843e8ba0e03451ff747bf--85a2d4b5eb214ab99a5759893c8ee7f0
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_ba3bf3463f8c434496a48a857cefdffe HEA cluster_78dab11d8bab42a2beec0f33e1b2ce78 Tower Fourier FM 744834363a5a4a63af2a3d66a41305e9 0 6c61874f528b4495a6797748f193078a RX(1.0*phi) 744834363a5a4a63af2a3d66a41305e9--6c61874f528b4495a6797748f193078a fde4355e477c486e91004bae1d424f0b 1 d33627c571ac4414b67d94d85f928999 RX(theta₀) 6c61874f528b4495a6797748f193078a--d33627c571ac4414b67d94d85f928999 18030eecc8704544903b92a95c2e139a RY(theta₄) d33627c571ac4414b67d94d85f928999--18030eecc8704544903b92a95c2e139a b62f3515d8154c6da7ba23e65a37f1b0 RX(theta₈) 18030eecc8704544903b92a95c2e139a--b62f3515d8154c6da7ba23e65a37f1b0 58f0d544460f4b86aee80ed88d0c7fc5 b62f3515d8154c6da7ba23e65a37f1b0--58f0d544460f4b86aee80ed88d0c7fc5 8e2f70e07a6244e49b6b1b026683f671 58f0d544460f4b86aee80ed88d0c7fc5--8e2f70e07a6244e49b6b1b026683f671 68c3c283333d489285742f879cc9c037 RX(theta₁₂) 8e2f70e07a6244e49b6b1b026683f671--68c3c283333d489285742f879cc9c037 5ec4acf57f394e4491e746c7e7b53549 RY(theta₁₆) 68c3c283333d489285742f879cc9c037--5ec4acf57f394e4491e746c7e7b53549 0da99aa47a65487a86c2c63955d3829b RX(theta₂₀) 5ec4acf57f394e4491e746c7e7b53549--0da99aa47a65487a86c2c63955d3829b 75c563b664df4a07b8d74e4fefeb6b3a 0da99aa47a65487a86c2c63955d3829b--75c563b664df4a07b8d74e4fefeb6b3a fc72115caeda41549214ea38087ff659 75c563b664df4a07b8d74e4fefeb6b3a--fc72115caeda41549214ea38087ff659 c99e61919c0b4372ab0c91b0129ef35d fc72115caeda41549214ea38087ff659--c99e61919c0b4372ab0c91b0129ef35d 674cde4139fc4b4f9127e7d0e429f4b1 68ca796775af40d68205d274b624201e RX(2.0*phi) fde4355e477c486e91004bae1d424f0b--68ca796775af40d68205d274b624201e 2c3e98c25ffb47cf9ff9f11543f0d7fa 2 a31de0a6fb57415aba4efb5ab573126b RX(theta₁) 68ca796775af40d68205d274b624201e--a31de0a6fb57415aba4efb5ab573126b 77020735fe3741ed9e063c0142fb7d1e RY(theta₅) a31de0a6fb57415aba4efb5ab573126b--77020735fe3741ed9e063c0142fb7d1e 28a40fe4ab30481cb6a344efccef2dea RX(theta₉) 77020735fe3741ed9e063c0142fb7d1e--28a40fe4ab30481cb6a344efccef2dea 55338fa91cf34f2b8e533cb648f15d51 X 28a40fe4ab30481cb6a344efccef2dea--55338fa91cf34f2b8e533cb648f15d51 55338fa91cf34f2b8e533cb648f15d51--58f0d544460f4b86aee80ed88d0c7fc5 db73a6fd682d4e5cbb51b3512fb42115 55338fa91cf34f2b8e533cb648f15d51--db73a6fd682d4e5cbb51b3512fb42115 9079b8e95b6a49fcaa0629695745a93f RX(theta₁₃) db73a6fd682d4e5cbb51b3512fb42115--9079b8e95b6a49fcaa0629695745a93f a1be918526aa436f80ef7ed41372a677 RY(theta₁₇) 9079b8e95b6a49fcaa0629695745a93f--a1be918526aa436f80ef7ed41372a677 154c7a3cdeba4c15a950783d9f0f4b08 RX(theta₂₁) a1be918526aa436f80ef7ed41372a677--154c7a3cdeba4c15a950783d9f0f4b08 eb048bb8c9994910ae36eddf56adfa40 X 154c7a3cdeba4c15a950783d9f0f4b08--eb048bb8c9994910ae36eddf56adfa40 eb048bb8c9994910ae36eddf56adfa40--75c563b664df4a07b8d74e4fefeb6b3a f011c3c5f08a4deeac5b2874f9ed2555 eb048bb8c9994910ae36eddf56adfa40--f011c3c5f08a4deeac5b2874f9ed2555 f011c3c5f08a4deeac5b2874f9ed2555--674cde4139fc4b4f9127e7d0e429f4b1 04642a7142a945f08c18c10c461ed469 d03dbdabaa2e44778bb4c093af6c045c RX(3.0*phi) 2c3e98c25ffb47cf9ff9f11543f0d7fa--d03dbdabaa2e44778bb4c093af6c045c 8c6be0ce532a4be19d2cb4de38665c36 3 f27a1ca7de2c422ea49a354b414b1abc RX(theta₂) d03dbdabaa2e44778bb4c093af6c045c--f27a1ca7de2c422ea49a354b414b1abc 64c5088f4a6e43ca82a037113da4b3d6 RY(theta₆) f27a1ca7de2c422ea49a354b414b1abc--64c5088f4a6e43ca82a037113da4b3d6 137b8e5f4d6e45ee87d2cc58bf42fc8b RX(theta₁₀) 64c5088f4a6e43ca82a037113da4b3d6--137b8e5f4d6e45ee87d2cc58bf42fc8b 84526eb064534d5b96bffb81499a2ad2 137b8e5f4d6e45ee87d2cc58bf42fc8b--84526eb064534d5b96bffb81499a2ad2 ee0806237a40404eb49be325ae7134ee X 84526eb064534d5b96bffb81499a2ad2--ee0806237a40404eb49be325ae7134ee ee0806237a40404eb49be325ae7134ee--db73a6fd682d4e5cbb51b3512fb42115 83274d96ef7440008d99a8fa76e43f44 RX(theta₁₄) ee0806237a40404eb49be325ae7134ee--83274d96ef7440008d99a8fa76e43f44 cfbdf40a787f4aedaab70c3edd4232de RY(theta₁₈) 83274d96ef7440008d99a8fa76e43f44--cfbdf40a787f4aedaab70c3edd4232de 37df38ddb0ac4ca3bb03875a60bcbb88 RX(theta₂₂) cfbdf40a787f4aedaab70c3edd4232de--37df38ddb0ac4ca3bb03875a60bcbb88 6b9e32408adc4bee8df8a91d8e09340a 37df38ddb0ac4ca3bb03875a60bcbb88--6b9e32408adc4bee8df8a91d8e09340a 156cc4935f7844d0a0a6b934ef78a8df X 6b9e32408adc4bee8df8a91d8e09340a--156cc4935f7844d0a0a6b934ef78a8df 156cc4935f7844d0a0a6b934ef78a8df--f011c3c5f08a4deeac5b2874f9ed2555 156cc4935f7844d0a0a6b934ef78a8df--04642a7142a945f08c18c10c461ed469 24eb0b516ee94b11a54f600b72ef8799 49d9ef9158b940c3894f84c2614be3fb RX(4.0*phi) 8c6be0ce532a4be19d2cb4de38665c36--49d9ef9158b940c3894f84c2614be3fb 9e408fa3bf3a4bdca516aa6e331e6caf RX(theta₃) 49d9ef9158b940c3894f84c2614be3fb--9e408fa3bf3a4bdca516aa6e331e6caf 42da52c98a9742cdb06daf30b2ff08e6 RY(theta₇) 9e408fa3bf3a4bdca516aa6e331e6caf--42da52c98a9742cdb06daf30b2ff08e6 618333ad8db244ed95e823416df2c46b RX(theta₁₁) 42da52c98a9742cdb06daf30b2ff08e6--618333ad8db244ed95e823416df2c46b bfb2fb36b7524785a1d0d6de8fee2652 X 618333ad8db244ed95e823416df2c46b--bfb2fb36b7524785a1d0d6de8fee2652 bfb2fb36b7524785a1d0d6de8fee2652--84526eb064534d5b96bffb81499a2ad2 9f6a86cf7e984c5f8edf8d6db164652e bfb2fb36b7524785a1d0d6de8fee2652--9f6a86cf7e984c5f8edf8d6db164652e 3f9f1e16dff94a07a760cb829d1e7ade RX(theta₁₅) 9f6a86cf7e984c5f8edf8d6db164652e--3f9f1e16dff94a07a760cb829d1e7ade 970ef6e4e4804b329d3a456f7c3bc09d RY(theta₁₉) 3f9f1e16dff94a07a760cb829d1e7ade--970ef6e4e4804b329d3a456f7c3bc09d c69cce8409844c4fa77aba3a750fa8ab RX(theta₂₃) 970ef6e4e4804b329d3a456f7c3bc09d--c69cce8409844c4fa77aba3a750fa8ab d626fe82e6bc4ebca1799f77c1bb6bc1 X c69cce8409844c4fa77aba3a750fa8ab--d626fe82e6bc4ebca1799f77c1bb6bc1 d626fe82e6bc4ebca1799f77c1bb6bc1--6b9e32408adc4bee8df8a91d8e09340a 4716960f9013441e8e4be8d37c80a56e d626fe82e6bc4ebca1799f77c1bb6bc1--4716960f9013441e8e4be8d37c80a56e 4716960f9013441e8e4be8d37c80a56e--24eb0b516ee94b11a54f600b72ef8799
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_7e440d5d41fb441aa66c0805245ff3c9 Obs. cluster_000bc532e92f45829047d6dbea2c4831 cluster_42641c795437447ba8c130152677bc78 HEA 1e58cedea2bb493fb6cac2e42a51a93b 0 ddacf279ee4c4021b223e66cb36a90a8 RX(theta₀) 1e58cedea2bb493fb6cac2e42a51a93b--ddacf279ee4c4021b223e66cb36a90a8 83c8373ecb854ffeaf794a851d2c03ae 1 ecdb5e7175c94992b856542d98d8c7c3 RY(theta₃) ddacf279ee4c4021b223e66cb36a90a8--ecdb5e7175c94992b856542d98d8c7c3 3c6b1d15a8df4c8e9a88ca99adf8a40e RX(theta₆) ecdb5e7175c94992b856542d98d8c7c3--3c6b1d15a8df4c8e9a88ca99adf8a40e c388befa0d4c41f89a8f4a87f91fef50 3c6b1d15a8df4c8e9a88ca99adf8a40e--c388befa0d4c41f89a8f4a87f91fef50 1ce6aca0d6c04060b0cae701eeca94fa c388befa0d4c41f89a8f4a87f91fef50--1ce6aca0d6c04060b0cae701eeca94fa 799eab57874846839b46eb6b4203e679 RX(theta₉) 1ce6aca0d6c04060b0cae701eeca94fa--799eab57874846839b46eb6b4203e679 0ae81d05a5974fb6bed9dfc53a16bdda RY(theta₁₂) 799eab57874846839b46eb6b4203e679--0ae81d05a5974fb6bed9dfc53a16bdda 607fc7c10c7f45f5ac17498af79c194b RX(theta₁₅) 0ae81d05a5974fb6bed9dfc53a16bdda--607fc7c10c7f45f5ac17498af79c194b 39f05a407c634dc99095682cc32f4bc0 607fc7c10c7f45f5ac17498af79c194b--39f05a407c634dc99095682cc32f4bc0 409d70d5c3554496846e56d00248e380 39f05a407c634dc99095682cc32f4bc0--409d70d5c3554496846e56d00248e380 213f98952c8f4509bdbfbeb02ada759c 409d70d5c3554496846e56d00248e380--213f98952c8f4509bdbfbeb02ada759c 90109253b8d24495a7254111d0ab7436 213f98952c8f4509bdbfbeb02ada759c--90109253b8d24495a7254111d0ab7436 11ee7af6dac045cd8c3c967b22b149f9 a684b0bbe46b465a916cdc6e2e491ef8 RX(theta₁) 83c8373ecb854ffeaf794a851d2c03ae--a684b0bbe46b465a916cdc6e2e491ef8 597ad66ac70f4d9285839f20ecb49427 2 ccd3648fc60f4625b522ae9d1940a480 RY(theta₄) a684b0bbe46b465a916cdc6e2e491ef8--ccd3648fc60f4625b522ae9d1940a480 26c9668faf2c48dba3f1fbb4bbd19dff RX(theta₇) ccd3648fc60f4625b522ae9d1940a480--26c9668faf2c48dba3f1fbb4bbd19dff ca80810b9c5f4270b92c67a9801ab6ed X 26c9668faf2c48dba3f1fbb4bbd19dff--ca80810b9c5f4270b92c67a9801ab6ed ca80810b9c5f4270b92c67a9801ab6ed--c388befa0d4c41f89a8f4a87f91fef50 14684460ba5f4ed7afb8e9f248a784f1 ca80810b9c5f4270b92c67a9801ab6ed--14684460ba5f4ed7afb8e9f248a784f1 1b258b060e1a446c9fe78d5eb7248d0d RX(theta₁₀) 14684460ba5f4ed7afb8e9f248a784f1--1b258b060e1a446c9fe78d5eb7248d0d a822955de98c4b70b6092dca3cf9203d RY(theta₁₃) 1b258b060e1a446c9fe78d5eb7248d0d--a822955de98c4b70b6092dca3cf9203d a4b6c5614efc422090cf5a301275ef66 RX(theta₁₆) a822955de98c4b70b6092dca3cf9203d--a4b6c5614efc422090cf5a301275ef66 ffa7a787b6c9409fb0de1e19c751036e X a4b6c5614efc422090cf5a301275ef66--ffa7a787b6c9409fb0de1e19c751036e ffa7a787b6c9409fb0de1e19c751036e--39f05a407c634dc99095682cc32f4bc0 c3922a43b9a14fb9893abfec3a3db9a3 ffa7a787b6c9409fb0de1e19c751036e--c3922a43b9a14fb9893abfec3a3db9a3 56cbc57146224776b9bc62d0aca90ae8 AddBlock c3922a43b9a14fb9893abfec3a3db9a3--56cbc57146224776b9bc62d0aca90ae8 56cbc57146224776b9bc62d0aca90ae8--11ee7af6dac045cd8c3c967b22b149f9 1675cfc3fd2e4fe3b206286fa4b1fec1 66e9b3e997b041a8a779af881397563f RX(theta₂) 597ad66ac70f4d9285839f20ecb49427--66e9b3e997b041a8a779af881397563f 2bc59c77b81e40e5a0e06e31e21a979e RY(theta₅) 66e9b3e997b041a8a779af881397563f--2bc59c77b81e40e5a0e06e31e21a979e 103e63f27a82454f99c57f5dbd30f645 RX(theta₈) 2bc59c77b81e40e5a0e06e31e21a979e--103e63f27a82454f99c57f5dbd30f645 0606370efe9e420b8bf5ef3c87f1aceb 103e63f27a82454f99c57f5dbd30f645--0606370efe9e420b8bf5ef3c87f1aceb 0c4cc4f9b4c3490d9141f7be58e6f3aa X 0606370efe9e420b8bf5ef3c87f1aceb--0c4cc4f9b4c3490d9141f7be58e6f3aa 0c4cc4f9b4c3490d9141f7be58e6f3aa--14684460ba5f4ed7afb8e9f248a784f1 681ce6a60aea4247ab73770017f8b49e RX(theta₁₁) 0c4cc4f9b4c3490d9141f7be58e6f3aa--681ce6a60aea4247ab73770017f8b49e d1a070d3939542eaab4dded55510638d RY(theta₁₄) 681ce6a60aea4247ab73770017f8b49e--d1a070d3939542eaab4dded55510638d 4a9b7bfdfea04c59a5b0262decc0bf8d RX(theta₁₇) d1a070d3939542eaab4dded55510638d--4a9b7bfdfea04c59a5b0262decc0bf8d 0cf51f0bfc1b4bedb70fe31cbdf779f0 4a9b7bfdfea04c59a5b0262decc0bf8d--0cf51f0bfc1b4bedb70fe31cbdf779f0 3180e8acf8ba465db1157d73023ff278 X 0cf51f0bfc1b4bedb70fe31cbdf779f0--3180e8acf8ba465db1157d73023ff278 3180e8acf8ba465db1157d73023ff278--c3922a43b9a14fb9893abfec3a3db9a3 b787966d4e664661873582196bd348a0 3180e8acf8ba465db1157d73023ff278--b787966d4e664661873582196bd348a0 b787966d4e664661873582196bd348a0--1675cfc3fd2e4fe3b206286fa4b1fec1
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 97e76c8befea4889923ecdfd216d3e62 0 b40eb7c61d4f47f3b4cab9734408b78b 97e76c8befea4889923ecdfd216d3e62--b40eb7c61d4f47f3b4cab9734408b78b 964b14d5a95f4532ae74b0b56beef800 1 84530269894b4afe8653a11b02ea0762 62eebe7aa12a4ec783a6daf73efa9768 b40eb7c61d4f47f3b4cab9734408b78b--62eebe7aa12a4ec783a6daf73efa9768 849bbe4e700748809493b93e1a5ab75d 84530269894b4afe8653a11b02ea0762--849bbe4e700748809493b93e1a5ab75d 9078dc74196044faa88967e9bf2bef63 9d9463e687ea48b3bfd7e9ad33159841 849bbe4e700748809493b93e1a5ab75d--9d9463e687ea48b3bfd7e9ad33159841 f77b72ccff8940949c90273061d377c0 9078dc74196044faa88967e9bf2bef63--f77b72ccff8940949c90273061d377c0 2d1524f9d7ec466b852040355e17fd88 74e61c9cc7f441f182268bf7e6e46e19 964b14d5a95f4532ae74b0b56beef800--74e61c9cc7f441f182268bf7e6e46e19 87ea2f4186944a23be2ea5fa96e1a43f 2 74e61c9cc7f441f182268bf7e6e46e19--84530269894b4afe8653a11b02ea0762 ffcfd125a2c84ccd9513bd0679e0d197 62eebe7aa12a4ec783a6daf73efa9768--ffcfd125a2c84ccd9513bd0679e0d197 0dbea0c668cd4d129f57feca10d443d0 ffcfd125a2c84ccd9513bd0679e0d197--0dbea0c668cd4d129f57feca10d443d0 0dbea0c668cd4d129f57feca10d443d0--2d1524f9d7ec466b852040355e17fd88 87715e9a9e844803b10a27a6fcd41efe 3b06201ea7ad4141b5366d1092559e77 87ea2f4186944a23be2ea5fa96e1a43f--3b06201ea7ad4141b5366d1092559e77 1acd520858f1463789808f5fb451d6ef 3 f5d2e8ddfece444f852ddb3ecd441d7b 3b06201ea7ad4141b5366d1092559e77--f5d2e8ddfece444f852ddb3ecd441d7b dd6c23084fd0445a87c74b537e2811f3 f5d2e8ddfece444f852ddb3ecd441d7b--dd6c23084fd0445a87c74b537e2811f3 2ce8a5d2144442de884e9a33bc893442 dd6c23084fd0445a87c74b537e2811f3--2ce8a5d2144442de884e9a33bc893442 2ce8a5d2144442de884e9a33bc893442--87715e9a9e844803b10a27a6fcd41efe e10961b023b647f7b8a0547409b733d1 615bc4119e1749dcbe8cc8d2e5d5f21f 1acd520858f1463789808f5fb451d6ef--615bc4119e1749dcbe8cc8d2e5d5f21f e70ca3a05c324a278306e545991cfe35 615bc4119e1749dcbe8cc8d2e5d5f21f--e70ca3a05c324a278306e545991cfe35 9dd1228cb674492b8af980f84738375b e70ca3a05c324a278306e545991cfe35--9dd1228cb674492b8af980f84738375b 9dd1228cb674492b8af980f84738375b--9078dc74196044faa88967e9bf2bef63 9d9463e687ea48b3bfd7e9ad33159841--e10961b023b647f7b8a0547409b733d1
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 46b178dcc7164effb0f70f04aa3ec919 0 f47d52d46cd14217bbd483903908a5c0 46b178dcc7164effb0f70f04aa3ec919--f47d52d46cd14217bbd483903908a5c0 dd224e6e259040638761b99414136406 1 b7ff75fd56aa44e19ed44cc571807e6b f47d52d46cd14217bbd483903908a5c0--b7ff75fd56aa44e19ed44cc571807e6b cdc911b6079248c292939632a8c5a46a b7ff75fd56aa44e19ed44cc571807e6b--cdc911b6079248c292939632a8c5a46a 462dc515fcab4f1a949aa619131b58ff cdc911b6079248c292939632a8c5a46a--462dc515fcab4f1a949aa619131b58ff 34b2cfc174a14fec98468e8c527d2b3b 19641df08b7d484796ffb4aad4ceb945 PHASE(0.5) dd224e6e259040638761b99414136406--19641df08b7d484796ffb4aad4ceb945 23a00f51752f4a5ab715653f638b967c 2 19641df08b7d484796ffb4aad4ceb945--f47d52d46cd14217bbd483903908a5c0 221ef403085d49cfb9b5a749828cb9e3 19641df08b7d484796ffb4aad4ceb945--221ef403085d49cfb9b5a749828cb9e3 69ea94a789634767b7670fce594d8c7d 221ef403085d49cfb9b5a749828cb9e3--69ea94a789634767b7670fce594d8c7d 69ea94a789634767b7670fce594d8c7d--34b2cfc174a14fec98468e8c527d2b3b 92b75c6fad2c4e77b0551eede8557766 69ee917f2e79471aa3b20fd5fcc14fe0 23a00f51752f4a5ab715653f638b967c--69ee917f2e79471aa3b20fd5fcc14fe0 7d2427fad08e43e6af43158db634f46f 3 15bc8fc5bfc340b6a0c49457da8ec202 PHASE(0.5) 69ee917f2e79471aa3b20fd5fcc14fe0--15bc8fc5bfc340b6a0c49457da8ec202 15bc8fc5bfc340b6a0c49457da8ec202--b7ff75fd56aa44e19ed44cc571807e6b 99851697b7ee4f3a8ff5c1503d1ebcd3 15bc8fc5bfc340b6a0c49457da8ec202--99851697b7ee4f3a8ff5c1503d1ebcd3 99851697b7ee4f3a8ff5c1503d1ebcd3--92b75c6fad2c4e77b0551eede8557766 abcedaabc4db425187c47831b7444db0 6035213752e84852a8bc08b6e5e70026 7d2427fad08e43e6af43158db634f46f--6035213752e84852a8bc08b6e5e70026 b7e2df831360425d986f4c823d6a96cd 6035213752e84852a8bc08b6e5e70026--b7e2df831360425d986f4c823d6a96cd 979747a890674e6aa16338903836a7f7 PHASE(0.5) b7e2df831360425d986f4c823d6a96cd--979747a890674e6aa16338903836a7f7 979747a890674e6aa16338903836a7f7--cdc911b6079248c292939632a8c5a46a 979747a890674e6aa16338903836a7f7--abcedaabc4db425187c47831b7444db0

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