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 65a12f3b8e164643b3bd6541d35d2620 0 b323a76738054ac4bbe214be86d9904f X 65a12f3b8e164643b3bd6541d35d2620--b323a76738054ac4bbe214be86d9904f a27be237dfad44209116b810a3ec98d4 1 d7ae3b90c19442d2b847df1b7ff8a4c9 b323a76738054ac4bbe214be86d9904f--d7ae3b90c19442d2b847df1b7ff8a4c9 c867c4328332406e8174af26f239bd2d 1b92f31b140c46e28fdb66be7442f23b Y a27be237dfad44209116b810a3ec98d4--1b92f31b140c46e28fdb66be7442f23b 1b92f31b140c46e28fdb66be7442f23b--c867c4328332406e8174af26f239bd2d
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 f9914d6b4e2b43e386074b6ed07aede8 0 0bbf67cc2e4442e1a828536f050c50cf X f9914d6b4e2b43e386074b6ed07aede8--0bbf67cc2e4442e1a828536f050c50cf 7cc964c51e56454a80c4ce9cdc6ec0f7 Y 0bbf67cc2e4442e1a828536f050c50cf--7cc964c51e56454a80c4ce9cdc6ec0f7 c6f27cb851b944908b5461f00c05f9da 7cc964c51e56454a80c4ce9cdc6ec0f7--c6f27cb851b944908b5461f00c05f9da
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 bc0333f6eb0043038d78e40c00fde192 0 39df74736c614c7687f074da1cb8ecee X bc0333f6eb0043038d78e40c00fde192--39df74736c614c7687f074da1cb8ecee 7576027d7c8246909e177f7a917e4e9c 1 b7325a76491b4b65a06747c798556d91 39df74736c614c7687f074da1cb8ecee--b7325a76491b4b65a06747c798556d91 ecc3961af49c452e8e73ada020968588 b7325a76491b4b65a06747c798556d91--ecc3961af49c452e8e73ada020968588 1a16b4057af74e51a38c96583f88c59e 84186a55cc28436e81bff3199b8a35aa 7576027d7c8246909e177f7a917e4e9c--84186a55cc28436e81bff3199b8a35aa e0ed2f568f224525bff9b66995f44153 Y 84186a55cc28436e81bff3199b8a35aa--e0ed2f568f224525bff9b66995f44153 e0ed2f568f224525bff9b66995f44153--1a16b4057af74e51a38c96583f88c59e
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_7258e7417f204025bb9027d1912d0cf4 95ae882c27ec458297c1b82eddaa113e 0 d4c051a4705d42ac96de21099a3653f0 95ae882c27ec458297c1b82eddaa113e--d4c051a4705d42ac96de21099a3653f0 165580d4ea084860b35dc117a54aec9b 1 90ef100ace0c402099d35c3479b901bd d4c051a4705d42ac96de21099a3653f0--90ef100ace0c402099d35c3479b901bd d16e448cae894d51915a808c5322d9ea 53471acd46d44bb3856e01925241b7d6 AddBlock 165580d4ea084860b35dc117a54aec9b--53471acd46d44bb3856e01925241b7d6 56d15214cb8f4b378e8fc97cde03694a 2 53471acd46d44bb3856e01925241b7d6--d16e448cae894d51915a808c5322d9ea bca88addc9864007bae637451df02764 afb1d6a9ea524388872c58942616a5b6 56d15214cb8f4b378e8fc97cde03694a--afb1d6a9ea524388872c58942616a5b6 afb1d6a9ea524388872c58942616a5b6--bca88addc9864007bae637451df02764
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_7e89b60953074b0bb04c9ee270e3277a cluster_02cdea67bdb3476899f2373304644f2a rx 291e1720f4d5421fb89e37d6fc7ab899 0 851b01791db64ee08c26229edc5f6d8c X 291e1720f4d5421fb89e37d6fc7ab899--851b01791db64ee08c26229edc5f6d8c f5d1583d84074315b6bbc19875b65f5c 1 a72b5665e58d4a9893a9f786ac57a596 851b01791db64ee08c26229edc5f6d8c--a72b5665e58d4a9893a9f786ac57a596 5389be42e3c249999b67367b4ec80199 a72b5665e58d4a9893a9f786ac57a596--5389be42e3c249999b67367b4ec80199 9d8bb4a933954a0b9a237d3bc855d8c6 5389be42e3c249999b67367b4ec80199--9d8bb4a933954a0b9a237d3bc855d8c6 657bcfb199d1485e88ed16645e865707 73214d3f8b064c8ba42efdc12cd5be94 Y f5d1583d84074315b6bbc19875b65f5c--73214d3f8b064c8ba42efdc12cd5be94 ea229e5473b24ee0b85e837a8dc84722 2 ba7f5934e3454a258301631f7d6104cc 73214d3f8b064c8ba42efdc12cd5be94--ba7f5934e3454a258301631f7d6104cc be38ce16ebf8492daa835b1b7d5a731b HamEvo ba7f5934e3454a258301631f7d6104cc--be38ce16ebf8492daa835b1b7d5a731b be38ce16ebf8492daa835b1b7d5a731b--657bcfb199d1485e88ed16645e865707 76d560dca51f4cffaf9d7727ffa86062 472fc4847a30401db53d35c87b68b28a RX(x) ea229e5473b24ee0b85e837a8dc84722--472fc4847a30401db53d35c87b68b28a 26ad61221ffe4a10bd4e9afe10aa3b17 3 13e2ab40f2d04b41b40a4d08e41b29d7 472fc4847a30401db53d35c87b68b28a--13e2ab40f2d04b41b40a4d08e41b29d7 01eafac5b45849398ca38f28a0b7943e t = 10 13e2ab40f2d04b41b40a4d08e41b29d7--01eafac5b45849398ca38f28a0b7943e 01eafac5b45849398ca38f28a0b7943e--76d560dca51f4cffaf9d7727ffa86062 8362532cd244477eb1cb249755972adf 0c788357224b4b579ee8d45aa4816a18 RX(0.5) 26ad61221ffe4a10bd4e9afe10aa3b17--0c788357224b4b579ee8d45aa4816a18 b07f8e4d8d1f42a39b1353bc1dd7e26d X 0c788357224b4b579ee8d45aa4816a18--b07f8e4d8d1f42a39b1353bc1dd7e26d b07f8e4d8d1f42a39b1353bc1dd7e26d--13e2ab40f2d04b41b40a4d08e41b29d7 04cd8a3583e143c8b324a89cdd48b14f b07f8e4d8d1f42a39b1353bc1dd7e26d--04cd8a3583e143c8b324a89cdd48b14f 04cd8a3583e143c8b324a89cdd48b14f--8362532cd244477eb1cb249755972adf
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_f7539ff3aeee4e9a9f34a6f0e2970ae1 HEA cluster_5afdc2a91a194efd923909dea2ccf3fe Tower Fourier FM 2d0ee77469d54ea5ab1132f01ddf8890 0 53a2d704267c4a0488341336f333139b RX(1.0*phi) 2d0ee77469d54ea5ab1132f01ddf8890--53a2d704267c4a0488341336f333139b 885726f8c65549b1bc3945ea9948faec 1 e8b533772e5548d381c0036c19ee1c14 RX(theta₀) 53a2d704267c4a0488341336f333139b--e8b533772e5548d381c0036c19ee1c14 08115255fadd4001b9e9c8ce4ef2cd23 RY(theta₄) e8b533772e5548d381c0036c19ee1c14--08115255fadd4001b9e9c8ce4ef2cd23 2c07784d361d4d799394984cc429cdf6 RX(theta₈) 08115255fadd4001b9e9c8ce4ef2cd23--2c07784d361d4d799394984cc429cdf6 01725cfa70d140a58503a7d728b682a7 2c07784d361d4d799394984cc429cdf6--01725cfa70d140a58503a7d728b682a7 90c32d9c824a42f285bf33d873ba676b 01725cfa70d140a58503a7d728b682a7--90c32d9c824a42f285bf33d873ba676b 8b5ddc3aba7b43858c796c17bde1d997 RX(theta₁₂) 90c32d9c824a42f285bf33d873ba676b--8b5ddc3aba7b43858c796c17bde1d997 39fcab5bcd0c4cc9990457baa189f563 RY(theta₁₆) 8b5ddc3aba7b43858c796c17bde1d997--39fcab5bcd0c4cc9990457baa189f563 13564ec6bc59430484e8a2ea77903981 RX(theta₂₀) 39fcab5bcd0c4cc9990457baa189f563--13564ec6bc59430484e8a2ea77903981 34ee1aec2d6647e6afa6d766dfc8e1ff 13564ec6bc59430484e8a2ea77903981--34ee1aec2d6647e6afa6d766dfc8e1ff d6af2fa7325044d7bd83e009c5d3eab0 34ee1aec2d6647e6afa6d766dfc8e1ff--d6af2fa7325044d7bd83e009c5d3eab0 c8d3bbac8a204b1ebf54a9fdab6c79ad d6af2fa7325044d7bd83e009c5d3eab0--c8d3bbac8a204b1ebf54a9fdab6c79ad 75f8217f055548509c076567b6de1cb9 9edf2449dacc4ff584c8331471df953e RX(2.0*phi) 885726f8c65549b1bc3945ea9948faec--9edf2449dacc4ff584c8331471df953e 4f5c38662c8d46baa2dd5168ab459f98 2 43948dbd659f4826896df383bdd0dce1 RX(theta₁) 9edf2449dacc4ff584c8331471df953e--43948dbd659f4826896df383bdd0dce1 26e05f1494374c57bd8f2e7d713d79e7 RY(theta₅) 43948dbd659f4826896df383bdd0dce1--26e05f1494374c57bd8f2e7d713d79e7 ecc43338db264c1db1ee892c9b82867b RX(theta₉) 26e05f1494374c57bd8f2e7d713d79e7--ecc43338db264c1db1ee892c9b82867b df94c6cb6a4e4bc7ac3c90d59eaca511 X ecc43338db264c1db1ee892c9b82867b--df94c6cb6a4e4bc7ac3c90d59eaca511 df94c6cb6a4e4bc7ac3c90d59eaca511--01725cfa70d140a58503a7d728b682a7 1877935a74e14fd980c480c7447a011e df94c6cb6a4e4bc7ac3c90d59eaca511--1877935a74e14fd980c480c7447a011e 0bdd7b42e8a0476a80b567457e55e810 RX(theta₁₃) 1877935a74e14fd980c480c7447a011e--0bdd7b42e8a0476a80b567457e55e810 1540610f2f09437e8256211235e33864 RY(theta₁₇) 0bdd7b42e8a0476a80b567457e55e810--1540610f2f09437e8256211235e33864 9d6c9aae96c94e0f8af5a265c6c0dcf0 RX(theta₂₁) 1540610f2f09437e8256211235e33864--9d6c9aae96c94e0f8af5a265c6c0dcf0 3a6cdf3c8ac8486daf4d6b1e78a9bcd0 X 9d6c9aae96c94e0f8af5a265c6c0dcf0--3a6cdf3c8ac8486daf4d6b1e78a9bcd0 3a6cdf3c8ac8486daf4d6b1e78a9bcd0--34ee1aec2d6647e6afa6d766dfc8e1ff 4bf75f0991554e2c87be75a1ce36d9db 3a6cdf3c8ac8486daf4d6b1e78a9bcd0--4bf75f0991554e2c87be75a1ce36d9db 4bf75f0991554e2c87be75a1ce36d9db--75f8217f055548509c076567b6de1cb9 3c0fa72279ac485da4a5d20d30487a6d 2b1bf0d4e94f44408ad92d0dc94e8085 RX(3.0*phi) 4f5c38662c8d46baa2dd5168ab459f98--2b1bf0d4e94f44408ad92d0dc94e8085 4f840536d731496cbba45ea923189886 3 1b9013282fab46fdadc723a2066cb4ba RX(theta₂) 2b1bf0d4e94f44408ad92d0dc94e8085--1b9013282fab46fdadc723a2066cb4ba 12dc4627569c45749a79a453eea1302e RY(theta₆) 1b9013282fab46fdadc723a2066cb4ba--12dc4627569c45749a79a453eea1302e 72a17b995396415cb95c9b0a4e92dd2f RX(theta₁₀) 12dc4627569c45749a79a453eea1302e--72a17b995396415cb95c9b0a4e92dd2f 978615b8d78b4cdbaaf7be9fbbc4ec9f 72a17b995396415cb95c9b0a4e92dd2f--978615b8d78b4cdbaaf7be9fbbc4ec9f 5bc762ca8ad5460ea3b2da78a6fd61c3 X 978615b8d78b4cdbaaf7be9fbbc4ec9f--5bc762ca8ad5460ea3b2da78a6fd61c3 5bc762ca8ad5460ea3b2da78a6fd61c3--1877935a74e14fd980c480c7447a011e d0968c8274a642f184a8e5c8543e1df1 RX(theta₁₄) 5bc762ca8ad5460ea3b2da78a6fd61c3--d0968c8274a642f184a8e5c8543e1df1 43a5a34ca8b349c7be3b2744621de892 RY(theta₁₈) d0968c8274a642f184a8e5c8543e1df1--43a5a34ca8b349c7be3b2744621de892 2d303efc79914b47a7154019edb6a386 RX(theta₂₂) 43a5a34ca8b349c7be3b2744621de892--2d303efc79914b47a7154019edb6a386 30a27a2124704102adfc6c3d6ba5ccda 2d303efc79914b47a7154019edb6a386--30a27a2124704102adfc6c3d6ba5ccda bc0a8788b3754a05a3fca05ef4480d3e X 30a27a2124704102adfc6c3d6ba5ccda--bc0a8788b3754a05a3fca05ef4480d3e bc0a8788b3754a05a3fca05ef4480d3e--4bf75f0991554e2c87be75a1ce36d9db bc0a8788b3754a05a3fca05ef4480d3e--3c0fa72279ac485da4a5d20d30487a6d e8744a001c224069bd9ef8d58f5f4b0b 462db2b462bf41b493b434b2dbb06c33 RX(4.0*phi) 4f840536d731496cbba45ea923189886--462db2b462bf41b493b434b2dbb06c33 10fd1435a4ca4781afd2f8e70d48b6a4 RX(theta₃) 462db2b462bf41b493b434b2dbb06c33--10fd1435a4ca4781afd2f8e70d48b6a4 d167390cc9eb419f84ad488b1b59e501 RY(theta₇) 10fd1435a4ca4781afd2f8e70d48b6a4--d167390cc9eb419f84ad488b1b59e501 1afc2d8b567a4bd797c8f4fbd0eb90e2 RX(theta₁₁) d167390cc9eb419f84ad488b1b59e501--1afc2d8b567a4bd797c8f4fbd0eb90e2 d0a14ec759994acda2795cb455d6028a X 1afc2d8b567a4bd797c8f4fbd0eb90e2--d0a14ec759994acda2795cb455d6028a d0a14ec759994acda2795cb455d6028a--978615b8d78b4cdbaaf7be9fbbc4ec9f 8abf101d40e4437897903a8899155cd9 d0a14ec759994acda2795cb455d6028a--8abf101d40e4437897903a8899155cd9 1bfcfc2df09c439db185a819fb04515d RX(theta₁₅) 8abf101d40e4437897903a8899155cd9--1bfcfc2df09c439db185a819fb04515d b60dd6f0e0e84f39bc4d3ff8500f054f RY(theta₁₉) 1bfcfc2df09c439db185a819fb04515d--b60dd6f0e0e84f39bc4d3ff8500f054f 612952ff2ea641d995c1f89d29c9c323 RX(theta₂₃) b60dd6f0e0e84f39bc4d3ff8500f054f--612952ff2ea641d995c1f89d29c9c323 a777c13b849f45b5a838f6e77e968c09 X 612952ff2ea641d995c1f89d29c9c323--a777c13b849f45b5a838f6e77e968c09 a777c13b849f45b5a838f6e77e968c09--30a27a2124704102adfc6c3d6ba5ccda 465dae4b627d49dbb0144b09d10a09ba a777c13b849f45b5a838f6e77e968c09--465dae4b627d49dbb0144b09d10a09ba 465dae4b627d49dbb0144b09d10a09ba--e8744a001c224069bd9ef8d58f5f4b0b
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_0172aa193ded4561bb508f97929cf6af Obs. cluster_59f25a63990a42289dfa355c833cbc41 cluster_37c3c4d2d26f4329b16106bf9e8dd430 HEA 24bd9f599ff647ecaf9dd796d61b0722 0 05e5150ce3c14729b9be7af035b7fba0 RX(theta₀) 24bd9f599ff647ecaf9dd796d61b0722--05e5150ce3c14729b9be7af035b7fba0 954dd5c801504673a750182090cf45e0 1 d6ea2b86f802466a87fa3b08fca0b4ce RY(theta₃) 05e5150ce3c14729b9be7af035b7fba0--d6ea2b86f802466a87fa3b08fca0b4ce a86b699bbc5e4143902a8fcb652a6ee7 RX(theta₆) d6ea2b86f802466a87fa3b08fca0b4ce--a86b699bbc5e4143902a8fcb652a6ee7 5e384763c28a47078933540fb414a8de a86b699bbc5e4143902a8fcb652a6ee7--5e384763c28a47078933540fb414a8de cfbc5d2ab680444bab90a6792b09587b 5e384763c28a47078933540fb414a8de--cfbc5d2ab680444bab90a6792b09587b 6113b7903f7f43c6b5a85499fc8800e8 RX(theta₉) cfbc5d2ab680444bab90a6792b09587b--6113b7903f7f43c6b5a85499fc8800e8 94f1f0dae4fa4029ac2f0941fccea3b7 RY(theta₁₂) 6113b7903f7f43c6b5a85499fc8800e8--94f1f0dae4fa4029ac2f0941fccea3b7 6b0dffc920e44aeb92f2ba086e56c27c RX(theta₁₅) 94f1f0dae4fa4029ac2f0941fccea3b7--6b0dffc920e44aeb92f2ba086e56c27c 4d76dcdb798f455394711166775a5b82 6b0dffc920e44aeb92f2ba086e56c27c--4d76dcdb798f455394711166775a5b82 8516da1605db4905bb09d71144529803 4d76dcdb798f455394711166775a5b82--8516da1605db4905bb09d71144529803 5ad9a438c4a44868b495ca68b0d74572 8516da1605db4905bb09d71144529803--5ad9a438c4a44868b495ca68b0d74572 7076d7e3b563465e9668506f710f0ba2 5ad9a438c4a44868b495ca68b0d74572--7076d7e3b563465e9668506f710f0ba2 5864c9f6a8ab457aa8ae7699d9b5c107 079fcfae5b2c42c7997e33b121afad4d RX(theta₁) 954dd5c801504673a750182090cf45e0--079fcfae5b2c42c7997e33b121afad4d 5d2089294460443191018226b0160b2f 2 622ca6d71e7b4bd1bc3ff1af1d0c2e3d RY(theta₄) 079fcfae5b2c42c7997e33b121afad4d--622ca6d71e7b4bd1bc3ff1af1d0c2e3d 448f78b560db4580aa14c464c5c627b3 RX(theta₇) 622ca6d71e7b4bd1bc3ff1af1d0c2e3d--448f78b560db4580aa14c464c5c627b3 16f0a736b5744e22b827ee1a245c8951 X 448f78b560db4580aa14c464c5c627b3--16f0a736b5744e22b827ee1a245c8951 16f0a736b5744e22b827ee1a245c8951--5e384763c28a47078933540fb414a8de 979c45ca929d434aaa24201d37e1e2e4 16f0a736b5744e22b827ee1a245c8951--979c45ca929d434aaa24201d37e1e2e4 946923ce41314227af5b8f596750bdf5 RX(theta₁₀) 979c45ca929d434aaa24201d37e1e2e4--946923ce41314227af5b8f596750bdf5 5a04c52f47d14bae8cfe10ca270b27a6 RY(theta₁₃) 946923ce41314227af5b8f596750bdf5--5a04c52f47d14bae8cfe10ca270b27a6 3db333a4c1fd42899a0f6f4c88504310 RX(theta₁₆) 5a04c52f47d14bae8cfe10ca270b27a6--3db333a4c1fd42899a0f6f4c88504310 d8df4929558f439e8b6d6ab4c79e4f28 X 3db333a4c1fd42899a0f6f4c88504310--d8df4929558f439e8b6d6ab4c79e4f28 d8df4929558f439e8b6d6ab4c79e4f28--4d76dcdb798f455394711166775a5b82 8c42dd97d3f7431884e82df43d7313c1 d8df4929558f439e8b6d6ab4c79e4f28--8c42dd97d3f7431884e82df43d7313c1 3b82adbb366d4717ac997ca2a6027189 AddBlock 8c42dd97d3f7431884e82df43d7313c1--3b82adbb366d4717ac997ca2a6027189 3b82adbb366d4717ac997ca2a6027189--5864c9f6a8ab457aa8ae7699d9b5c107 c8d60dc39dc748eeb71c4b3f225bdfc4 a742669411fd48fbb8a917b4d76d5c48 RX(theta₂) 5d2089294460443191018226b0160b2f--a742669411fd48fbb8a917b4d76d5c48 ac9e099bbf0f447aa490f0e8f38ee5b8 RY(theta₅) a742669411fd48fbb8a917b4d76d5c48--ac9e099bbf0f447aa490f0e8f38ee5b8 1fe9d04aa6dd447c918a4d3401679eb0 RX(theta₈) ac9e099bbf0f447aa490f0e8f38ee5b8--1fe9d04aa6dd447c918a4d3401679eb0 20cbfb1ef6744c5db784f261210ee03d 1fe9d04aa6dd447c918a4d3401679eb0--20cbfb1ef6744c5db784f261210ee03d 1d73822038964cd3bfd47c81b83772d6 X 20cbfb1ef6744c5db784f261210ee03d--1d73822038964cd3bfd47c81b83772d6 1d73822038964cd3bfd47c81b83772d6--979c45ca929d434aaa24201d37e1e2e4 fa38d4545c63408d87d6800d6f513df0 RX(theta₁₁) 1d73822038964cd3bfd47c81b83772d6--fa38d4545c63408d87d6800d6f513df0 df455bc6b6994704997a18abab5c609d RY(theta₁₄) fa38d4545c63408d87d6800d6f513df0--df455bc6b6994704997a18abab5c609d 55e85233d47f43308b19f700156cebd4 RX(theta₁₇) df455bc6b6994704997a18abab5c609d--55e85233d47f43308b19f700156cebd4 f5012c49523f4cc0b0e92e59633bfcda 55e85233d47f43308b19f700156cebd4--f5012c49523f4cc0b0e92e59633bfcda c616823bb91141f18d4f4ec2b25f725f X f5012c49523f4cc0b0e92e59633bfcda--c616823bb91141f18d4f4ec2b25f725f c616823bb91141f18d4f4ec2b25f725f--8c42dd97d3f7431884e82df43d7313c1 12f48c3889fa440cb11b130f3c932aa3 c616823bb91141f18d4f4ec2b25f725f--12f48c3889fa440cb11b130f3c932aa3 12f48c3889fa440cb11b130f3c932aa3--c8d60dc39dc748eeb71c4b3f225bdfc4

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