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 85cdc30ecc934c07a1bd33eb12f16347 0 2767cae1c037464eacaef23c81ca8b3f X 85cdc30ecc934c07a1bd33eb12f16347--2767cae1c037464eacaef23c81ca8b3f cc7e5886e9de4fdcb7cdb93b4ff5f0d4 1 2d551a52517843b8b0f445b2abf656d8 2767cae1c037464eacaef23c81ca8b3f--2d551a52517843b8b0f445b2abf656d8 ecce8985a9a04b13bfda3fc9eb39f39f 3d36613641ab4bf7abf7ddfb73a9c2dc Y cc7e5886e9de4fdcb7cdb93b4ff5f0d4--3d36613641ab4bf7abf7ddfb73a9c2dc 3d36613641ab4bf7abf7ddfb73a9c2dc--ecce8985a9a04b13bfda3fc9eb39f39f
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 1274c00cedd948708b2db79092277025 0 2861c33121084a49a0dfaca93a086eb0 X 1274c00cedd948708b2db79092277025--2861c33121084a49a0dfaca93a086eb0 ff82f97277b04911afe24e8d230095d5 Y 2861c33121084a49a0dfaca93a086eb0--ff82f97277b04911afe24e8d230095d5 8b2853d14aca44559a826bccff2c7c02 ff82f97277b04911afe24e8d230095d5--8b2853d14aca44559a826bccff2c7c02
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 02ef007b376c4a029a7602d46d203f0e 0 fdb0f8ff378d4c66a4eed3f6a1c29399 X 02ef007b376c4a029a7602d46d203f0e--fdb0f8ff378d4c66a4eed3f6a1c29399 e49691d4ec0a41af81918f2a4412b37d 1 4272a7cf43fa4085a8e092e8645a97fd fdb0f8ff378d4c66a4eed3f6a1c29399--4272a7cf43fa4085a8e092e8645a97fd 9160fa15058a47e2af3e151bd821ffe5 4272a7cf43fa4085a8e092e8645a97fd--9160fa15058a47e2af3e151bd821ffe5 46fae4d90f224f0f96b86f6f43f81e93 76a3ae708aa340a5a53073ed9a2a44a9 e49691d4ec0a41af81918f2a4412b37d--76a3ae708aa340a5a53073ed9a2a44a9 c4924c24f3e24976a9b9d434225b889a Y 76a3ae708aa340a5a53073ed9a2a44a9--c4924c24f3e24976a9b9d434225b889a c4924c24f3e24976a9b9d434225b889a--46fae4d90f224f0f96b86f6f43f81e93
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_04ab24a05ff84b81805ecd25ff7d2477 f8ba9bbc65454df9b4ac6cc886d0acb6 0 63ede74740e1466991f931667650cd7f f8ba9bbc65454df9b4ac6cc886d0acb6--63ede74740e1466991f931667650cd7f bb96678c6bfd45d3bdb6a34106f40e04 1 0b711f25b45d4f39ab1c08a2587a18a0 63ede74740e1466991f931667650cd7f--0b711f25b45d4f39ab1c08a2587a18a0 ca3c3a5e75e14e07b4752db31bab0fa0 388ec462dc7a4010a98b30bca3c12aa4 AddBlock bb96678c6bfd45d3bdb6a34106f40e04--388ec462dc7a4010a98b30bca3c12aa4 1df37737ffb949f3875d0ca6dbb6cc97 2 388ec462dc7a4010a98b30bca3c12aa4--ca3c3a5e75e14e07b4752db31bab0fa0 fea4842616064cc3852eae542ceddd97 b1e234add386443ba36248f000e10e6e 1df37737ffb949f3875d0ca6dbb6cc97--b1e234add386443ba36248f000e10e6e b1e234add386443ba36248f000e10e6e--fea4842616064cc3852eae542ceddd97
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_3f14df3c37024ecdba072c4f8c1df491 cluster_69d64e35a06349b189d3a0217e09f581 rx 9c679aa02c4c4a55ba91cceb6c94e198 0 b0b4ac65c26b428fa34f6216e84c3c63 X 9c679aa02c4c4a55ba91cceb6c94e198--b0b4ac65c26b428fa34f6216e84c3c63 bcdfdac1f29547e5a88e1b11c6616171 1 f8f12847ebbb4106b8776eefd7193948 b0b4ac65c26b428fa34f6216e84c3c63--f8f12847ebbb4106b8776eefd7193948 029b3afda923428f822c3c65a740f1b2 f8f12847ebbb4106b8776eefd7193948--029b3afda923428f822c3c65a740f1b2 6d851a3c95d846f19a4a16512bb639f1 029b3afda923428f822c3c65a740f1b2--6d851a3c95d846f19a4a16512bb639f1 73341e89f9034dd180c98a410c3a2e54 4793300f12a0435ea6302fbcdfef62af Y bcdfdac1f29547e5a88e1b11c6616171--4793300f12a0435ea6302fbcdfef62af 7dd9909be9c748cab5f870c9bf852704 2 3269c3dd93dd49e7a077e2aad3cfc184 4793300f12a0435ea6302fbcdfef62af--3269c3dd93dd49e7a077e2aad3cfc184 c055205962464c98b88da434cae61eef HamEvo 3269c3dd93dd49e7a077e2aad3cfc184--c055205962464c98b88da434cae61eef c055205962464c98b88da434cae61eef--73341e89f9034dd180c98a410c3a2e54 fa2e6265488f4f1ea53d17ad48b36976 9aaf1d0c2380428db688f0a18d7b575f RX(x) 7dd9909be9c748cab5f870c9bf852704--9aaf1d0c2380428db688f0a18d7b575f 7a0669904bef443d99b109c29560efed 3 8a9e8734858e4e82b3600624cf78a279 9aaf1d0c2380428db688f0a18d7b575f--8a9e8734858e4e82b3600624cf78a279 20da1db17c2047bfb576bf2e3a87b8d6 t = 10 8a9e8734858e4e82b3600624cf78a279--20da1db17c2047bfb576bf2e3a87b8d6 20da1db17c2047bfb576bf2e3a87b8d6--fa2e6265488f4f1ea53d17ad48b36976 7444e970bf2d41de90f71022712080d5 3081aefd14204f94ae4f63233f78164b RX(0.5) 7a0669904bef443d99b109c29560efed--3081aefd14204f94ae4f63233f78164b ad5d492376e64e838f8cda3797614fa4 X 3081aefd14204f94ae4f63233f78164b--ad5d492376e64e838f8cda3797614fa4 ad5d492376e64e838f8cda3797614fa4--8a9e8734858e4e82b3600624cf78a279 09cc71e9609447668f230f5ff51167fb ad5d492376e64e838f8cda3797614fa4--09cc71e9609447668f230f5ff51167fb 09cc71e9609447668f230f5ff51167fb--7444e970bf2d41de90f71022712080d5
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_863b715cfcbe450db8d51447b166ba57 HEA cluster_f3832945912c4129b96793207ebbc562 Tower Fourier FM 6319d5bdaccf48f5b9256df99218616b 0 a487c14d52ac4ebaa6f439be3cc42931 RX(1.0*phi) 6319d5bdaccf48f5b9256df99218616b--a487c14d52ac4ebaa6f439be3cc42931 62bf0434fdbc490786fc106a44d329ef 1 b752cd22deb34d4da32e00c6dd2d27c1 RX(theta₀) a487c14d52ac4ebaa6f439be3cc42931--b752cd22deb34d4da32e00c6dd2d27c1 9cbc0ea88f204dd4bd17172570b677b5 RY(theta₄) b752cd22deb34d4da32e00c6dd2d27c1--9cbc0ea88f204dd4bd17172570b677b5 ddaff3ba01af42e49ce3bb3a3ae65d5d RX(theta₈) 9cbc0ea88f204dd4bd17172570b677b5--ddaff3ba01af42e49ce3bb3a3ae65d5d 98d5114b51254ae4ba5cb23d2471ea2b ddaff3ba01af42e49ce3bb3a3ae65d5d--98d5114b51254ae4ba5cb23d2471ea2b 74698a3583e2451a8c0f467ede3e2089 98d5114b51254ae4ba5cb23d2471ea2b--74698a3583e2451a8c0f467ede3e2089 ed4f1038aefc45cbb73bdff66be99d52 RX(theta₁₂) 74698a3583e2451a8c0f467ede3e2089--ed4f1038aefc45cbb73bdff66be99d52 d74fc373880a40c981d5efdb5f88d8d0 RY(theta₁₆) ed4f1038aefc45cbb73bdff66be99d52--d74fc373880a40c981d5efdb5f88d8d0 df053834700745e4b6e865d108cf663b RX(theta₂₀) d74fc373880a40c981d5efdb5f88d8d0--df053834700745e4b6e865d108cf663b 603c346dd30f41858d32202304cf1427 df053834700745e4b6e865d108cf663b--603c346dd30f41858d32202304cf1427 c84a723ad54a4feab9ec4541a0fbf53b 603c346dd30f41858d32202304cf1427--c84a723ad54a4feab9ec4541a0fbf53b f150a948b0494d90b2fa55d90ebe45e2 c84a723ad54a4feab9ec4541a0fbf53b--f150a948b0494d90b2fa55d90ebe45e2 b32d1130188d4191ac1fa28cfd92fbab 1968d307948841afb7ca49045c0855f5 RX(2.0*phi) 62bf0434fdbc490786fc106a44d329ef--1968d307948841afb7ca49045c0855f5 0e67a9cb310f49b3b4d920da73007d6c 2 1420a430f87b4b64b9ff3ca79ffc5e2e RX(theta₁) 1968d307948841afb7ca49045c0855f5--1420a430f87b4b64b9ff3ca79ffc5e2e 85f5230d8acc4c72838cb82957cc4114 RY(theta₅) 1420a430f87b4b64b9ff3ca79ffc5e2e--85f5230d8acc4c72838cb82957cc4114 e6bec35a6b104c9cade6d1aea7ec1185 RX(theta₉) 85f5230d8acc4c72838cb82957cc4114--e6bec35a6b104c9cade6d1aea7ec1185 87fa7ff9159a4104bc8cce124cfb9f51 X e6bec35a6b104c9cade6d1aea7ec1185--87fa7ff9159a4104bc8cce124cfb9f51 87fa7ff9159a4104bc8cce124cfb9f51--98d5114b51254ae4ba5cb23d2471ea2b ca190745f7a542ba8d43c92643602b93 87fa7ff9159a4104bc8cce124cfb9f51--ca190745f7a542ba8d43c92643602b93 eafaae868d674fb0ac7075df104c260f RX(theta₁₃) ca190745f7a542ba8d43c92643602b93--eafaae868d674fb0ac7075df104c260f 9ee52aae81f54e51823a72182afbab4c RY(theta₁₇) eafaae868d674fb0ac7075df104c260f--9ee52aae81f54e51823a72182afbab4c b5f3afcd64a94308b70333592734c7f2 RX(theta₂₁) 9ee52aae81f54e51823a72182afbab4c--b5f3afcd64a94308b70333592734c7f2 037aa45ef65643a9aefd7b4a1994107c X b5f3afcd64a94308b70333592734c7f2--037aa45ef65643a9aefd7b4a1994107c 037aa45ef65643a9aefd7b4a1994107c--603c346dd30f41858d32202304cf1427 1f0ffd43843149d39f174085e084a816 037aa45ef65643a9aefd7b4a1994107c--1f0ffd43843149d39f174085e084a816 1f0ffd43843149d39f174085e084a816--b32d1130188d4191ac1fa28cfd92fbab e532def849e54295a7d1530e96bd6d70 ad1d857adb6c45cfbb18ef1f8192f1d9 RX(3.0*phi) 0e67a9cb310f49b3b4d920da73007d6c--ad1d857adb6c45cfbb18ef1f8192f1d9 ef02a50034674d069ad5052b19a40c77 3 07bea2af5c794c788171b7ad1cfe3999 RX(theta₂) ad1d857adb6c45cfbb18ef1f8192f1d9--07bea2af5c794c788171b7ad1cfe3999 f76a5da2648643e99b9d67c7b76a05de RY(theta₆) 07bea2af5c794c788171b7ad1cfe3999--f76a5da2648643e99b9d67c7b76a05de b4c3e6767228465692be32915403b915 RX(theta₁₀) f76a5da2648643e99b9d67c7b76a05de--b4c3e6767228465692be32915403b915 bbdd2599438b4cd59b9ac8a8207900a1 b4c3e6767228465692be32915403b915--bbdd2599438b4cd59b9ac8a8207900a1 c60ae8a446b94ec8a13c8d3ac2e8452b X bbdd2599438b4cd59b9ac8a8207900a1--c60ae8a446b94ec8a13c8d3ac2e8452b c60ae8a446b94ec8a13c8d3ac2e8452b--ca190745f7a542ba8d43c92643602b93 3b21bbae9c4244cca9f4ccf1a523dce4 RX(theta₁₄) c60ae8a446b94ec8a13c8d3ac2e8452b--3b21bbae9c4244cca9f4ccf1a523dce4 21b1a8380520461b9138058b4df1f1c4 RY(theta₁₈) 3b21bbae9c4244cca9f4ccf1a523dce4--21b1a8380520461b9138058b4df1f1c4 6f5823bc5aba4e6695809b57e7eb80a4 RX(theta₂₂) 21b1a8380520461b9138058b4df1f1c4--6f5823bc5aba4e6695809b57e7eb80a4 3415f55dd5464116ac23be644b2c52d2 6f5823bc5aba4e6695809b57e7eb80a4--3415f55dd5464116ac23be644b2c52d2 0836d74d14d7484892499f3d1c312be3 X 3415f55dd5464116ac23be644b2c52d2--0836d74d14d7484892499f3d1c312be3 0836d74d14d7484892499f3d1c312be3--1f0ffd43843149d39f174085e084a816 0836d74d14d7484892499f3d1c312be3--e532def849e54295a7d1530e96bd6d70 55fb95a97b0848e3b54ab8107127c7a1 74bf426dd6d940118020e9f5663b15a9 RX(4.0*phi) ef02a50034674d069ad5052b19a40c77--74bf426dd6d940118020e9f5663b15a9 deb6c4c7cf3d456bb3e48f846a1f7386 RX(theta₃) 74bf426dd6d940118020e9f5663b15a9--deb6c4c7cf3d456bb3e48f846a1f7386 8d2bd3a077604a60ba7ae99c25a3c78c RY(theta₇) deb6c4c7cf3d456bb3e48f846a1f7386--8d2bd3a077604a60ba7ae99c25a3c78c 62381c426cd54b3f878ca6458cfd9f66 RX(theta₁₁) 8d2bd3a077604a60ba7ae99c25a3c78c--62381c426cd54b3f878ca6458cfd9f66 004e30b0734e42bba6c7d8c92fcd3293 X 62381c426cd54b3f878ca6458cfd9f66--004e30b0734e42bba6c7d8c92fcd3293 004e30b0734e42bba6c7d8c92fcd3293--bbdd2599438b4cd59b9ac8a8207900a1 246edd0c11b649d6945cb1c2b93d5f2c 004e30b0734e42bba6c7d8c92fcd3293--246edd0c11b649d6945cb1c2b93d5f2c aaedfc9f8dcd4cbbb46357f6ba55d23d RX(theta₁₅) 246edd0c11b649d6945cb1c2b93d5f2c--aaedfc9f8dcd4cbbb46357f6ba55d23d edc80e50e5b840c4a3bbe603925754d2 RY(theta₁₉) aaedfc9f8dcd4cbbb46357f6ba55d23d--edc80e50e5b840c4a3bbe603925754d2 6c69423ebb344b7998ef2f844d320c02 RX(theta₂₃) edc80e50e5b840c4a3bbe603925754d2--6c69423ebb344b7998ef2f844d320c02 9a8fffa351e44994b4496d0691cbd25b X 6c69423ebb344b7998ef2f844d320c02--9a8fffa351e44994b4496d0691cbd25b 9a8fffa351e44994b4496d0691cbd25b--3415f55dd5464116ac23be644b2c52d2 f4fb0dbb6dd34076b0f5828cea6ad5c1 9a8fffa351e44994b4496d0691cbd25b--f4fb0dbb6dd34076b0f5828cea6ad5c1 f4fb0dbb6dd34076b0f5828cea6ad5c1--55fb95a97b0848e3b54ab8107127c7a1
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_2810b903f5b942c1aad3057dfb0e1eeb Obs. cluster_8cc8e712f3a3429b9554f728f2a447ed cluster_747ec221fd4d41a2a3a7f8b78bf7c615 HEA 872a631f3c7f4636805b8aa212759255 0 5e12ac7445ae44d38a416cbc639c6d96 RX(theta₀) 872a631f3c7f4636805b8aa212759255--5e12ac7445ae44d38a416cbc639c6d96 417d30a6c06e4d479acba6c4f5e9ad26 1 6d88d623a5464f99b695f63f3f685277 RY(theta₃) 5e12ac7445ae44d38a416cbc639c6d96--6d88d623a5464f99b695f63f3f685277 e00df3b156f944369c316d4f67217c87 RX(theta₆) 6d88d623a5464f99b695f63f3f685277--e00df3b156f944369c316d4f67217c87 c411a4088272494cb361c5959498e4ea e00df3b156f944369c316d4f67217c87--c411a4088272494cb361c5959498e4ea addaf67494314f7fb775cb8c8280b24a c411a4088272494cb361c5959498e4ea--addaf67494314f7fb775cb8c8280b24a 9117cb36814a4de48cedb53c56f60d5f RX(theta₉) addaf67494314f7fb775cb8c8280b24a--9117cb36814a4de48cedb53c56f60d5f 501d9d904e6f41a9a9a498a0e38257d1 RY(theta₁₂) 9117cb36814a4de48cedb53c56f60d5f--501d9d904e6f41a9a9a498a0e38257d1 51b178ae8ade41b0a46832f9adf3d5d4 RX(theta₁₅) 501d9d904e6f41a9a9a498a0e38257d1--51b178ae8ade41b0a46832f9adf3d5d4 9483640d52554d8aae4172257c6c9354 51b178ae8ade41b0a46832f9adf3d5d4--9483640d52554d8aae4172257c6c9354 fc2485bc30d7416ebda6fc4ae334d9fa 9483640d52554d8aae4172257c6c9354--fc2485bc30d7416ebda6fc4ae334d9fa 3e766f37d9d94afd84cf0e5915fe6e03 fc2485bc30d7416ebda6fc4ae334d9fa--3e766f37d9d94afd84cf0e5915fe6e03 2ea00b6184164c0fb3afd0e4d5c256f1 3e766f37d9d94afd84cf0e5915fe6e03--2ea00b6184164c0fb3afd0e4d5c256f1 692573f78ce64b179a0fff763ff5d33a 493aeb984cb0496d9d4de4a5115171b5 RX(theta₁) 417d30a6c06e4d479acba6c4f5e9ad26--493aeb984cb0496d9d4de4a5115171b5 54f54bb3be924ecab76cf99c0f71ec92 2 777998a0ef53487a8b9fadd7a4842005 RY(theta₄) 493aeb984cb0496d9d4de4a5115171b5--777998a0ef53487a8b9fadd7a4842005 9b0a1c0a6e6f440ca62048d90e93702f RX(theta₇) 777998a0ef53487a8b9fadd7a4842005--9b0a1c0a6e6f440ca62048d90e93702f 5f59bac03b6d407980a67b472676bed0 X 9b0a1c0a6e6f440ca62048d90e93702f--5f59bac03b6d407980a67b472676bed0 5f59bac03b6d407980a67b472676bed0--c411a4088272494cb361c5959498e4ea e5e2fd3fd2ff4706a51e571bdbc1acbb 5f59bac03b6d407980a67b472676bed0--e5e2fd3fd2ff4706a51e571bdbc1acbb d670743fc9784dcb9aa9a6f27925ef97 RX(theta₁₀) e5e2fd3fd2ff4706a51e571bdbc1acbb--d670743fc9784dcb9aa9a6f27925ef97 3cd5482cc4ec43b2908a87e94af76fea RY(theta₁₃) d670743fc9784dcb9aa9a6f27925ef97--3cd5482cc4ec43b2908a87e94af76fea a0ddd2d616984e778d4ccf1b9073de23 RX(theta₁₆) 3cd5482cc4ec43b2908a87e94af76fea--a0ddd2d616984e778d4ccf1b9073de23 07670fafeecd412eae41ef68dc6576e6 X a0ddd2d616984e778d4ccf1b9073de23--07670fafeecd412eae41ef68dc6576e6 07670fafeecd412eae41ef68dc6576e6--9483640d52554d8aae4172257c6c9354 8741db66aa9141c69838ffd1298e2a13 07670fafeecd412eae41ef68dc6576e6--8741db66aa9141c69838ffd1298e2a13 5b9a1485e9d54aeea2d439e6ad8cca34 AddBlock 8741db66aa9141c69838ffd1298e2a13--5b9a1485e9d54aeea2d439e6ad8cca34 5b9a1485e9d54aeea2d439e6ad8cca34--692573f78ce64b179a0fff763ff5d33a c280cb5ebbe548baa850633e51552f69 4c16ddf4d9af44baa4a4df78080be339 RX(theta₂) 54f54bb3be924ecab76cf99c0f71ec92--4c16ddf4d9af44baa4a4df78080be339 8084a90a5f3441ea9e5d8f3d025086cf RY(theta₅) 4c16ddf4d9af44baa4a4df78080be339--8084a90a5f3441ea9e5d8f3d025086cf 199f0bfcfba34472a4abee5da0650181 RX(theta₈) 8084a90a5f3441ea9e5d8f3d025086cf--199f0bfcfba34472a4abee5da0650181 cc8a26b061c74ae6b6147f951f3c35a7 199f0bfcfba34472a4abee5da0650181--cc8a26b061c74ae6b6147f951f3c35a7 035e35168ee841db8518ac151fdfb85c X cc8a26b061c74ae6b6147f951f3c35a7--035e35168ee841db8518ac151fdfb85c 035e35168ee841db8518ac151fdfb85c--e5e2fd3fd2ff4706a51e571bdbc1acbb 2df65c23888242b7bfc790cd48ae73fe RX(theta₁₁) 035e35168ee841db8518ac151fdfb85c--2df65c23888242b7bfc790cd48ae73fe 3664b5208a9644789c601ee21cad8459 RY(theta₁₄) 2df65c23888242b7bfc790cd48ae73fe--3664b5208a9644789c601ee21cad8459 e16464b789f740658fb8f155e440a278 RX(theta₁₇) 3664b5208a9644789c601ee21cad8459--e16464b789f740658fb8f155e440a278 cf103580ed0d44c1a627eed940d8e35b e16464b789f740658fb8f155e440a278--cf103580ed0d44c1a627eed940d8e35b e363a4f18fb94a448301411efbe09a2b X cf103580ed0d44c1a627eed940d8e35b--e363a4f18fb94a448301411efbe09a2b e363a4f18fb94a448301411efbe09a2b--8741db66aa9141c69838ffd1298e2a13 126ab666812c43d7a2b7dd24df56d604 e363a4f18fb94a448301411efbe09a2b--126ab666812c43d7a2b7dd24df56d604 126ab666812c43d7a2b7dd24df56d604--c280cb5ebbe548baa850633e51552f69
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 d24e7d27854a403c82c42cb8a767e270 0 3fc265eb408043b5b18da8a174b517d8 d24e7d27854a403c82c42cb8a767e270--3fc265eb408043b5b18da8a174b517d8 8a9c0078ac744f3eabf773f0d91a5c0f 1 67d4d32ef6704dba82a20a9d73a54339 a4ad5aba01de4c7698cacb60107be4f7 3fc265eb408043b5b18da8a174b517d8--a4ad5aba01de4c7698cacb60107be4f7 66ea3c7d63094bfb90b43708276f995d 67d4d32ef6704dba82a20a9d73a54339--66ea3c7d63094bfb90b43708276f995d d97fe8910a6a482facd2d840174d7cc9 02c2779b3ea2459f9e58aa60611961a9 66ea3c7d63094bfb90b43708276f995d--02c2779b3ea2459f9e58aa60611961a9 e7c2c3857daa4ff99ab6ce97313c7dd4 d97fe8910a6a482facd2d840174d7cc9--e7c2c3857daa4ff99ab6ce97313c7dd4 cbc093e414084f4cad7d9f901ca535e1 32fe1c97050243f3a06c5d3ea9a1c9a3 8a9c0078ac744f3eabf773f0d91a5c0f--32fe1c97050243f3a06c5d3ea9a1c9a3 0b85dea650734e9aa8cf2c63ef584546 2 32fe1c97050243f3a06c5d3ea9a1c9a3--67d4d32ef6704dba82a20a9d73a54339 1b054d35af6e42809a404644165eab54 a4ad5aba01de4c7698cacb60107be4f7--1b054d35af6e42809a404644165eab54 b9f86d584d64449ba563cb4538c598d6 1b054d35af6e42809a404644165eab54--b9f86d584d64449ba563cb4538c598d6 b9f86d584d64449ba563cb4538c598d6--cbc093e414084f4cad7d9f901ca535e1 9634c7634ccd4ed780468d4b6b27ee43 759e4fae54264eec8b2bf1cd7e9314a8 0b85dea650734e9aa8cf2c63ef584546--759e4fae54264eec8b2bf1cd7e9314a8 68d4c7256a864996b05eec4540b5bbbf 3 46a64e1a50224415af375026beda7be1 759e4fae54264eec8b2bf1cd7e9314a8--46a64e1a50224415af375026beda7be1 c8b1ab2da4a742c59114ef1dab40f04d 46a64e1a50224415af375026beda7be1--c8b1ab2da4a742c59114ef1dab40f04d 0c9e22ce22094fd89fbdc0e47d3cd963 c8b1ab2da4a742c59114ef1dab40f04d--0c9e22ce22094fd89fbdc0e47d3cd963 0c9e22ce22094fd89fbdc0e47d3cd963--9634c7634ccd4ed780468d4b6b27ee43 45d2e42ed437417e9c1aa62b702897f3 e88c09a56f144dd59ce046a0bd93d559 68d4c7256a864996b05eec4540b5bbbf--e88c09a56f144dd59ce046a0bd93d559 b10650008e664eca97ba1562b9606466 e88c09a56f144dd59ce046a0bd93d559--b10650008e664eca97ba1562b9606466 b8fa41b8786846aa8977f1022d1f7755 b10650008e664eca97ba1562b9606466--b8fa41b8786846aa8977f1022d1f7755 b8fa41b8786846aa8977f1022d1f7755--d97fe8910a6a482facd2d840174d7cc9 02c2779b3ea2459f9e58aa60611961a9--45d2e42ed437417e9c1aa62b702897f3
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 e7a8997e61454b38ae4461b6c15461b2 0 8b640b46fe934f538a7e4e9120da09a0 e7a8997e61454b38ae4461b6c15461b2--8b640b46fe934f538a7e4e9120da09a0 c3377ec1198a4606be815a7d246ca98e 1 c998441dc0b44af3a98315b5394a8070 8b640b46fe934f538a7e4e9120da09a0--c998441dc0b44af3a98315b5394a8070 8be395b281784431898104663d37056c c998441dc0b44af3a98315b5394a8070--8be395b281784431898104663d37056c 608b7b2c6b0f46c887c3391b7439c1b9 8be395b281784431898104663d37056c--608b7b2c6b0f46c887c3391b7439c1b9 502924e174db456c864acf457ed655ca 82b4477a181d42c684c6a5b4d95a7098 PHASE(0.5) c3377ec1198a4606be815a7d246ca98e--82b4477a181d42c684c6a5b4d95a7098 e59f75f4a69241c588831e2847c73dcc 2 82b4477a181d42c684c6a5b4d95a7098--8b640b46fe934f538a7e4e9120da09a0 bee65acb89a04b91a29ae62e70ea8570 82b4477a181d42c684c6a5b4d95a7098--bee65acb89a04b91a29ae62e70ea8570 e5db052b7c5246abacc024404fe1163b bee65acb89a04b91a29ae62e70ea8570--e5db052b7c5246abacc024404fe1163b e5db052b7c5246abacc024404fe1163b--502924e174db456c864acf457ed655ca 1828f05598c74ef0afae140e84869ef0 4dd3c7b39f1047e499c2cbd8d837fd4c e59f75f4a69241c588831e2847c73dcc--4dd3c7b39f1047e499c2cbd8d837fd4c 1eab4d61577c4efeb9ebbcf1bc306eb2 3 1b066a96893c4b359352cb05de669a76 PHASE(0.5) 4dd3c7b39f1047e499c2cbd8d837fd4c--1b066a96893c4b359352cb05de669a76 1b066a96893c4b359352cb05de669a76--c998441dc0b44af3a98315b5394a8070 47306651581f4db4a892426e63227e5b 1b066a96893c4b359352cb05de669a76--47306651581f4db4a892426e63227e5b 47306651581f4db4a892426e63227e5b--1828f05598c74ef0afae140e84869ef0 bd47d84de9b24d0188a7737f16b3a4ed c96a5388f642414086a7858a0c227468 1eab4d61577c4efeb9ebbcf1bc306eb2--c96a5388f642414086a7858a0c227468 36940997d5654afcab4116d8e65b44c1 c96a5388f642414086a7858a0c227468--36940997d5654afcab4116d8e65b44c1 40c27c441ae246a19dfb5a20d218356e PHASE(0.5) 36940997d5654afcab4116d8e65b44c1--40c27c441ae246a19dfb5a20d218356e 40c27c441ae246a19dfb5a20d218356e--8be395b281784431898104663d37056c 40c27c441ae246a19dfb5a20d218356e--bd47d84de9b24d0188a7737f16b3a4ed

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