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 b445fe2c07cc4a51834082b1f60be937 0 35b62d591c2c499282e2e1a8169ea8d7 X b445fe2c07cc4a51834082b1f60be937--35b62d591c2c499282e2e1a8169ea8d7 4244785ea52a4eea9f0454f513a8c391 1 ac29e5b0c2d04802aec9d2496b3f8113 35b62d591c2c499282e2e1a8169ea8d7--ac29e5b0c2d04802aec9d2496b3f8113 601c9242d86941408f73c294ffdd62e7 1f0343e90dc3497ba7c00bf2b4fcfe77 Y 4244785ea52a4eea9f0454f513a8c391--1f0343e90dc3497ba7c00bf2b4fcfe77 1f0343e90dc3497ba7c00bf2b4fcfe77--601c9242d86941408f73c294ffdd62e7
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 1070d66619b34457bee5c383b7d17dc8 0 2a7f29fac3074537b30f19cbb1cb37a8 X 1070d66619b34457bee5c383b7d17dc8--2a7f29fac3074537b30f19cbb1cb37a8 7371409b1d6a4a36ac36f6a17aa57d0f Y 2a7f29fac3074537b30f19cbb1cb37a8--7371409b1d6a4a36ac36f6a17aa57d0f 6306e4f0dfd0451aaf9133f6f0497e8e 7371409b1d6a4a36ac36f6a17aa57d0f--6306e4f0dfd0451aaf9133f6f0497e8e
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 726fd2d7161342188e8d8a2a3e2ec766 0 6c48ba8c823c4f2ea3d83bb8321e07c7 X 726fd2d7161342188e8d8a2a3e2ec766--6c48ba8c823c4f2ea3d83bb8321e07c7 f573e6aa516b4492b3371f9262a97bf0 1 d7871a91f0b444d6886c2180ecc97b99 6c48ba8c823c4f2ea3d83bb8321e07c7--d7871a91f0b444d6886c2180ecc97b99 897f508dcf3047b99b405970a5cd9e2c d7871a91f0b444d6886c2180ecc97b99--897f508dcf3047b99b405970a5cd9e2c 136dba3e844e4a319282cea0a9deb664 0c2ce1ef270a4714810daa920663a843 f573e6aa516b4492b3371f9262a97bf0--0c2ce1ef270a4714810daa920663a843 76708741a3e94fa589a19d72cabfdc5e Y 0c2ce1ef270a4714810daa920663a843--76708741a3e94fa589a19d72cabfdc5e 76708741a3e94fa589a19d72cabfdc5e--136dba3e844e4a319282cea0a9deb664
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_19a4e2cde5564196aef7b157c501425e b34e0b0306c245168b1b9d628e6b08bb 0 e2594a447e1c42afb2e0dcb3e667d3dc b34e0b0306c245168b1b9d628e6b08bb--e2594a447e1c42afb2e0dcb3e667d3dc 5c4c28cefcbe43b9b817998fa4bbd331 1 5442b271a9e74d74b4fe5fa32fd584a5 e2594a447e1c42afb2e0dcb3e667d3dc--5442b271a9e74d74b4fe5fa32fd584a5 037142ad8a1645dab8e76122bd6e23a6 5e2e6306ac8f4a18a0eced95a69f0adf AddBlock 5c4c28cefcbe43b9b817998fa4bbd331--5e2e6306ac8f4a18a0eced95a69f0adf cf924e2b2e274f7c888cfd1e429cdba6 2 5e2e6306ac8f4a18a0eced95a69f0adf--037142ad8a1645dab8e76122bd6e23a6 b1ed139b3c844404a30b30eedb6b909a 0efbd8964ade46228c8766b78cb0f6f6 cf924e2b2e274f7c888cfd1e429cdba6--0efbd8964ade46228c8766b78cb0f6f6 0efbd8964ade46228c8766b78cb0f6f6--b1ed139b3c844404a30b30eedb6b909a
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_9f1069d06737490ab99fd4b81bd5dee1 cluster_0bf988f2ee794366aacc3d470e88652a rx c1a16247b6b64b839c1dbdddab8e88b1 0 7b9ce7b33d2949d8bf2f3c0f82cce7e0 X c1a16247b6b64b839c1dbdddab8e88b1--7b9ce7b33d2949d8bf2f3c0f82cce7e0 6f714eb16d104f7eb844fc6759da4e61 1 d42bb99d034542d9ba6a0e2890346e59 7b9ce7b33d2949d8bf2f3c0f82cce7e0--d42bb99d034542d9ba6a0e2890346e59 a5d67f7645cf4a4a838cda34abd9604e d42bb99d034542d9ba6a0e2890346e59--a5d67f7645cf4a4a838cda34abd9604e 4923e11a39ec48f794add4146173aedc a5d67f7645cf4a4a838cda34abd9604e--4923e11a39ec48f794add4146173aedc 4622e68d0bf2456ca4faa836151ccb15 2a8ac31158604b29b24bb65a230be519 Y 6f714eb16d104f7eb844fc6759da4e61--2a8ac31158604b29b24bb65a230be519 5a11d4dbbc3b4240a67520b062ef6688 2 b5b627b9acc54261b0bd857891ce8531 2a8ac31158604b29b24bb65a230be519--b5b627b9acc54261b0bd857891ce8531 09edde79f09b482c845e9d2e2d627200 HamEvo b5b627b9acc54261b0bd857891ce8531--09edde79f09b482c845e9d2e2d627200 09edde79f09b482c845e9d2e2d627200--4622e68d0bf2456ca4faa836151ccb15 1dd3b4b58bdd4369834fe3365080eea7 b55927b927e549508a621f2aa36d8561 RX(x) 5a11d4dbbc3b4240a67520b062ef6688--b55927b927e549508a621f2aa36d8561 798aea13fe2c4da283e9c46550c3be25 3 a0573f7fe2db4d1e9d805c0214711cda b55927b927e549508a621f2aa36d8561--a0573f7fe2db4d1e9d805c0214711cda 6f5c6be0def54302893746e422cf63b9 t = 10 a0573f7fe2db4d1e9d805c0214711cda--6f5c6be0def54302893746e422cf63b9 6f5c6be0def54302893746e422cf63b9--1dd3b4b58bdd4369834fe3365080eea7 c0dad84b777d4d279ba55f33d119da4c 8c8d2707af4041dfa67197a1d3d49bf4 RX(0.5) 798aea13fe2c4da283e9c46550c3be25--8c8d2707af4041dfa67197a1d3d49bf4 c31b2e29f5954d82adaa754ac71aab98 X 8c8d2707af4041dfa67197a1d3d49bf4--c31b2e29f5954d82adaa754ac71aab98 c31b2e29f5954d82adaa754ac71aab98--a0573f7fe2db4d1e9d805c0214711cda 0b5ec24b13514f58b1938719cf4173e1 c31b2e29f5954d82adaa754ac71aab98--0b5ec24b13514f58b1938719cf4173e1 0b5ec24b13514f58b1938719cf4173e1--c0dad84b777d4d279ba55f33d119da4c
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_14340cfad8fd4b799a15a463820587b0 HEA cluster_8c0f4d004a0746c9bda0a4e943233d98 Tower Fourier FM 5696b2162ced4281a1e5537319462f7e 0 acbb2b7bba744dc6bb65fac1f1b35889 RX(1.0*phi) 5696b2162ced4281a1e5537319462f7e--acbb2b7bba744dc6bb65fac1f1b35889 5e702c2ec73245829bf473b05bfae01d 1 850a64202de440728ab0609fab0a7957 RX(theta₀) acbb2b7bba744dc6bb65fac1f1b35889--850a64202de440728ab0609fab0a7957 91666d92c36f4cc8a92c72148665a147 RY(theta₄) 850a64202de440728ab0609fab0a7957--91666d92c36f4cc8a92c72148665a147 718ccdbbdd0144f2a742f22f55ad3bc2 RX(theta₈) 91666d92c36f4cc8a92c72148665a147--718ccdbbdd0144f2a742f22f55ad3bc2 29e5e3d063474b2b93576f7d731d5520 718ccdbbdd0144f2a742f22f55ad3bc2--29e5e3d063474b2b93576f7d731d5520 bd8350b8a4f047cd8d5f76dab984682f 29e5e3d063474b2b93576f7d731d5520--bd8350b8a4f047cd8d5f76dab984682f 544a375887ca4ef6992c5d632ba1ba46 RX(theta₁₂) bd8350b8a4f047cd8d5f76dab984682f--544a375887ca4ef6992c5d632ba1ba46 f73eecbc12c04116a836b7225c6d7b17 RY(theta₁₆) 544a375887ca4ef6992c5d632ba1ba46--f73eecbc12c04116a836b7225c6d7b17 4d858e6cad4e4218aa172658e6b42207 RX(theta₂₀) f73eecbc12c04116a836b7225c6d7b17--4d858e6cad4e4218aa172658e6b42207 b472b6ebb0294701be96c19e47ee5699 4d858e6cad4e4218aa172658e6b42207--b472b6ebb0294701be96c19e47ee5699 69495ce31864439ba8a4cf4fa7016fe2 b472b6ebb0294701be96c19e47ee5699--69495ce31864439ba8a4cf4fa7016fe2 5c292b6420aa413a936503969df916cf 69495ce31864439ba8a4cf4fa7016fe2--5c292b6420aa413a936503969df916cf 540b6810804b4f8a85636a5971c26b33 5d4d314dcee94b8f8725181d1a1b6eba RX(2.0*phi) 5e702c2ec73245829bf473b05bfae01d--5d4d314dcee94b8f8725181d1a1b6eba bc2d57e771124758b2da2b23983e9167 2 d0da28f43397470aa94a0f4bcb31e299 RX(theta₁) 5d4d314dcee94b8f8725181d1a1b6eba--d0da28f43397470aa94a0f4bcb31e299 5e921878b32340fcac12e4b72a27b7df RY(theta₅) d0da28f43397470aa94a0f4bcb31e299--5e921878b32340fcac12e4b72a27b7df 9d6d450b3780412e9c86fdf6bcda1285 RX(theta₉) 5e921878b32340fcac12e4b72a27b7df--9d6d450b3780412e9c86fdf6bcda1285 f8cb94e91aee41f79b7c0efaebd39fac X 9d6d450b3780412e9c86fdf6bcda1285--f8cb94e91aee41f79b7c0efaebd39fac f8cb94e91aee41f79b7c0efaebd39fac--29e5e3d063474b2b93576f7d731d5520 e2478af016384ab8afd09637b20e712a f8cb94e91aee41f79b7c0efaebd39fac--e2478af016384ab8afd09637b20e712a 76b7858d8e4142b1b38db5dc73962f66 RX(theta₁₃) e2478af016384ab8afd09637b20e712a--76b7858d8e4142b1b38db5dc73962f66 602193fdc3e14773b1fc493e9e3811f8 RY(theta₁₇) 76b7858d8e4142b1b38db5dc73962f66--602193fdc3e14773b1fc493e9e3811f8 9b6b91a9f3d14296bcec9ecbeee45b0c RX(theta₂₁) 602193fdc3e14773b1fc493e9e3811f8--9b6b91a9f3d14296bcec9ecbeee45b0c aa878a1df49144c1944d3f1ee51c499b X 9b6b91a9f3d14296bcec9ecbeee45b0c--aa878a1df49144c1944d3f1ee51c499b aa878a1df49144c1944d3f1ee51c499b--b472b6ebb0294701be96c19e47ee5699 441049805cfb42d4a1ece1ec2b4c0b20 aa878a1df49144c1944d3f1ee51c499b--441049805cfb42d4a1ece1ec2b4c0b20 441049805cfb42d4a1ece1ec2b4c0b20--540b6810804b4f8a85636a5971c26b33 4340039b01994d2e8d4d57b84382a661 1d2c6a9b0d8c44d1b02fd34a63b4663e RX(3.0*phi) bc2d57e771124758b2da2b23983e9167--1d2c6a9b0d8c44d1b02fd34a63b4663e beb82e18fa9145b19ee9bcfb7dbe4125 3 e8b1b930be6349b5a1291ab49a2d2d16 RX(theta₂) 1d2c6a9b0d8c44d1b02fd34a63b4663e--e8b1b930be6349b5a1291ab49a2d2d16 9f9ec7166ccc4b9e8851b87eb5682c26 RY(theta₆) e8b1b930be6349b5a1291ab49a2d2d16--9f9ec7166ccc4b9e8851b87eb5682c26 a0cd7e66c53141a5bacf7580f058402e RX(theta₁₀) 9f9ec7166ccc4b9e8851b87eb5682c26--a0cd7e66c53141a5bacf7580f058402e b8ef476ef0274133bbf9a4cd8fbdd3f9 a0cd7e66c53141a5bacf7580f058402e--b8ef476ef0274133bbf9a4cd8fbdd3f9 a668e0c8d44541189a3f05b135162709 X b8ef476ef0274133bbf9a4cd8fbdd3f9--a668e0c8d44541189a3f05b135162709 a668e0c8d44541189a3f05b135162709--e2478af016384ab8afd09637b20e712a d44643ae310342f8828496d79c719fe1 RX(theta₁₄) a668e0c8d44541189a3f05b135162709--d44643ae310342f8828496d79c719fe1 fe119851797c43f8bb2da7255996a32f RY(theta₁₈) d44643ae310342f8828496d79c719fe1--fe119851797c43f8bb2da7255996a32f 0912a77fd61048b295acc6d2268849d9 RX(theta₂₂) fe119851797c43f8bb2da7255996a32f--0912a77fd61048b295acc6d2268849d9 b126fe3667f14ab0b8f3c92b8ec39b58 0912a77fd61048b295acc6d2268849d9--b126fe3667f14ab0b8f3c92b8ec39b58 bb066b7d92fb46b184674fa0539d9371 X b126fe3667f14ab0b8f3c92b8ec39b58--bb066b7d92fb46b184674fa0539d9371 bb066b7d92fb46b184674fa0539d9371--441049805cfb42d4a1ece1ec2b4c0b20 bb066b7d92fb46b184674fa0539d9371--4340039b01994d2e8d4d57b84382a661 d8e2f32438144fb0af9e5b0595728a68 f16930ca337349dfbaeddaca4fa65839 RX(4.0*phi) beb82e18fa9145b19ee9bcfb7dbe4125--f16930ca337349dfbaeddaca4fa65839 32c312bd11054850a52ad5dbdbe11e22 RX(theta₃) f16930ca337349dfbaeddaca4fa65839--32c312bd11054850a52ad5dbdbe11e22 ec901bb3bc9448eaa27c30d7e2479bea RY(theta₇) 32c312bd11054850a52ad5dbdbe11e22--ec901bb3bc9448eaa27c30d7e2479bea bb96b5944ce14551ab33b476e03c5f5a RX(theta₁₁) ec901bb3bc9448eaa27c30d7e2479bea--bb96b5944ce14551ab33b476e03c5f5a 543d375877c04711b5fb34913435023c X bb96b5944ce14551ab33b476e03c5f5a--543d375877c04711b5fb34913435023c 543d375877c04711b5fb34913435023c--b8ef476ef0274133bbf9a4cd8fbdd3f9 c9f6534c0de64f5fba7668aa47b0d516 543d375877c04711b5fb34913435023c--c9f6534c0de64f5fba7668aa47b0d516 65bd417211eb4169977ef34ed4eee9f6 RX(theta₁₅) c9f6534c0de64f5fba7668aa47b0d516--65bd417211eb4169977ef34ed4eee9f6 28d8abb49130454f98b2c32f20d56015 RY(theta₁₉) 65bd417211eb4169977ef34ed4eee9f6--28d8abb49130454f98b2c32f20d56015 1e1014650ae64f348478334480c37848 RX(theta₂₃) 28d8abb49130454f98b2c32f20d56015--1e1014650ae64f348478334480c37848 79062146212947749c02231e60f466e7 X 1e1014650ae64f348478334480c37848--79062146212947749c02231e60f466e7 79062146212947749c02231e60f466e7--b126fe3667f14ab0b8f3c92b8ec39b58 6d4199ebab614fac97fe51b47071c993 79062146212947749c02231e60f466e7--6d4199ebab614fac97fe51b47071c993 6d4199ebab614fac97fe51b47071c993--d8e2f32438144fb0af9e5b0595728a68
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_e6090e7257004be582202914c63f21d2 Obs. cluster_623327e272fc40abbba5baa55f5737da cluster_0568175e17f2415793dcf700dc3f3b58 HEA e4d1ff163edc4580b7ab6ede70114083 0 85c74a807aed437a8886a8311909bece RX(theta₀) e4d1ff163edc4580b7ab6ede70114083--85c74a807aed437a8886a8311909bece 983238dcb20a480fbcf6cfc8e532f578 1 e9064aa0f8b34c8386797388fd2cd74e RY(theta₃) 85c74a807aed437a8886a8311909bece--e9064aa0f8b34c8386797388fd2cd74e 2b75220716074b7da7f3101b651d0e04 RX(theta₆) e9064aa0f8b34c8386797388fd2cd74e--2b75220716074b7da7f3101b651d0e04 49f3dfe1614d4a538cfc2012d1e2614b 2b75220716074b7da7f3101b651d0e04--49f3dfe1614d4a538cfc2012d1e2614b b37239b8f8af4653bc1d327fb2c32e5c 49f3dfe1614d4a538cfc2012d1e2614b--b37239b8f8af4653bc1d327fb2c32e5c cff74f965bab440181608729c9b5b57d RX(theta₉) b37239b8f8af4653bc1d327fb2c32e5c--cff74f965bab440181608729c9b5b57d dd012a54176a420c82abf51e46ffa491 RY(theta₁₂) cff74f965bab440181608729c9b5b57d--dd012a54176a420c82abf51e46ffa491 b086f134780f4ed88554a5d0cb3435d2 RX(theta₁₅) dd012a54176a420c82abf51e46ffa491--b086f134780f4ed88554a5d0cb3435d2 b092abcc06a74905a16ed557964dd531 b086f134780f4ed88554a5d0cb3435d2--b092abcc06a74905a16ed557964dd531 ff41fca00bd94004b79db151bc4e1dc6 b092abcc06a74905a16ed557964dd531--ff41fca00bd94004b79db151bc4e1dc6 c8bd1cb7162c4e839854fc62e2b5ef08 ff41fca00bd94004b79db151bc4e1dc6--c8bd1cb7162c4e839854fc62e2b5ef08 ecbb7c1fc3e649e5a75dbbfb390878ac c8bd1cb7162c4e839854fc62e2b5ef08--ecbb7c1fc3e649e5a75dbbfb390878ac 6709306417424d71ab5486c76ef47c96 3003dbe8255c451dbfe72ad5745be6b5 RX(theta₁) 983238dcb20a480fbcf6cfc8e532f578--3003dbe8255c451dbfe72ad5745be6b5 191b5c20ea864778bb8c555961a1781b 2 6d0dd480225a4bcf9ff3c7a6c32815b7 RY(theta₄) 3003dbe8255c451dbfe72ad5745be6b5--6d0dd480225a4bcf9ff3c7a6c32815b7 2e7cc1d414cd416c9708f7eac5d3caed RX(theta₇) 6d0dd480225a4bcf9ff3c7a6c32815b7--2e7cc1d414cd416c9708f7eac5d3caed 1ddb67ca2ea94e1d85a0becd31760b8f X 2e7cc1d414cd416c9708f7eac5d3caed--1ddb67ca2ea94e1d85a0becd31760b8f 1ddb67ca2ea94e1d85a0becd31760b8f--49f3dfe1614d4a538cfc2012d1e2614b d2403ea863ca469f8936567d5dcbf55d 1ddb67ca2ea94e1d85a0becd31760b8f--d2403ea863ca469f8936567d5dcbf55d f9351f6d900248e0afa00c9c97f3ce7c RX(theta₁₀) d2403ea863ca469f8936567d5dcbf55d--f9351f6d900248e0afa00c9c97f3ce7c 4cee25d3c6c14eb38dc28f618a3e8a4a RY(theta₁₃) f9351f6d900248e0afa00c9c97f3ce7c--4cee25d3c6c14eb38dc28f618a3e8a4a 4f647cd0faf947eab5e7563cbbeb0ab0 RX(theta₁₆) 4cee25d3c6c14eb38dc28f618a3e8a4a--4f647cd0faf947eab5e7563cbbeb0ab0 4a878c814d9548fcb57053f9570e3bab X 4f647cd0faf947eab5e7563cbbeb0ab0--4a878c814d9548fcb57053f9570e3bab 4a878c814d9548fcb57053f9570e3bab--b092abcc06a74905a16ed557964dd531 2401c4b066ec4ae08fad66c1ea4d565a 4a878c814d9548fcb57053f9570e3bab--2401c4b066ec4ae08fad66c1ea4d565a 48fcf48c5d1446618922dd4a8a68101f AddBlock 2401c4b066ec4ae08fad66c1ea4d565a--48fcf48c5d1446618922dd4a8a68101f 48fcf48c5d1446618922dd4a8a68101f--6709306417424d71ab5486c76ef47c96 360006705b24499bac2d355b78068fe8 c7a20b6029ad424ea228eb2f3ecf5939 RX(theta₂) 191b5c20ea864778bb8c555961a1781b--c7a20b6029ad424ea228eb2f3ecf5939 f98928fa7a8445bfbab080ad69da9db7 RY(theta₅) c7a20b6029ad424ea228eb2f3ecf5939--f98928fa7a8445bfbab080ad69da9db7 010ebc896b0b472d9ce8475f58b6b261 RX(theta₈) f98928fa7a8445bfbab080ad69da9db7--010ebc896b0b472d9ce8475f58b6b261 5ab4b638e4bc4172a0d18072993cffd6 010ebc896b0b472d9ce8475f58b6b261--5ab4b638e4bc4172a0d18072993cffd6 5ebb5b40381d47709ca392fc4f16639d X 5ab4b638e4bc4172a0d18072993cffd6--5ebb5b40381d47709ca392fc4f16639d 5ebb5b40381d47709ca392fc4f16639d--d2403ea863ca469f8936567d5dcbf55d 1a50152f1caa45afa6fe7692502a7bf3 RX(theta₁₁) 5ebb5b40381d47709ca392fc4f16639d--1a50152f1caa45afa6fe7692502a7bf3 86b5f4b4e82944e08c4a2166b45dfdce RY(theta₁₄) 1a50152f1caa45afa6fe7692502a7bf3--86b5f4b4e82944e08c4a2166b45dfdce c5334eb2d8ed494780406eea4c996c66 RX(theta₁₇) 86b5f4b4e82944e08c4a2166b45dfdce--c5334eb2d8ed494780406eea4c996c66 08b43f54fac04e008901fbeae8a5069b c5334eb2d8ed494780406eea4c996c66--08b43f54fac04e008901fbeae8a5069b ceaea6df7e6c46c69bf4318a5ca94f12 X 08b43f54fac04e008901fbeae8a5069b--ceaea6df7e6c46c69bf4318a5ca94f12 ceaea6df7e6c46c69bf4318a5ca94f12--2401c4b066ec4ae08fad66c1ea4d565a ae149535eeb04466926b8c1a17f44cd3 ceaea6df7e6c46c69bf4318a5ca94f12--ae149535eeb04466926b8c1a17f44cd3 ae149535eeb04466926b8c1a17f44cd3--360006705b24499bac2d355b78068fe8

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