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 5169fa77ea8f4ba9930c397c768ffa14 0 834aa9acf0d24c66933c0905939d4096 X 5169fa77ea8f4ba9930c397c768ffa14--834aa9acf0d24c66933c0905939d4096 3d5462b7fc0648228da0ec4ae3ca62ca 1 7fe4a475704a479fbccc338f6166a0cb 834aa9acf0d24c66933c0905939d4096--7fe4a475704a479fbccc338f6166a0cb 1a7bb2afb5b44b33a748a9b81e274d2c c3aef1da7b5a4cbeb65b3589751edd2e Y 3d5462b7fc0648228da0ec4ae3ca62ca--c3aef1da7b5a4cbeb65b3589751edd2e c3aef1da7b5a4cbeb65b3589751edd2e--1a7bb2afb5b44b33a748a9b81e274d2c
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 01651670aaf84636bf3246b107c97169 0 f96610536155427c9e79cd0723a58acd X 01651670aaf84636bf3246b107c97169--f96610536155427c9e79cd0723a58acd 28778a6b65274283bd6d28ab1e4acaa0 Y f96610536155427c9e79cd0723a58acd--28778a6b65274283bd6d28ab1e4acaa0 6ec6df2e13194223ad89a97d2e52d203 28778a6b65274283bd6d28ab1e4acaa0--6ec6df2e13194223ad89a97d2e52d203
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 8a6a51499c2849ca8165e15a092f3d41 0 8ef5ce82edaa4d5db45e61d4486cf654 X 8a6a51499c2849ca8165e15a092f3d41--8ef5ce82edaa4d5db45e61d4486cf654 df4907eeebf14516a96dabb372ac6e64 1 4eb86d5482964f9194bf85d2fa05b4de 8ef5ce82edaa4d5db45e61d4486cf654--4eb86d5482964f9194bf85d2fa05b4de 82107f467f344027b926868e18121924 4eb86d5482964f9194bf85d2fa05b4de--82107f467f344027b926868e18121924 39296710ca1f47b5847c656baf9a9f01 ff25e08afbb84c838f9d876f6bbeac46 df4907eeebf14516a96dabb372ac6e64--ff25e08afbb84c838f9d876f6bbeac46 4c1627e6013d42319868f23581146e22 Y ff25e08afbb84c838f9d876f6bbeac46--4c1627e6013d42319868f23581146e22 4c1627e6013d42319868f23581146e22--39296710ca1f47b5847c656baf9a9f01
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_ab1cc49044b74e1a8d465121bb681fe7 3fbc11aa81ec454b8b1144600b3a5e79 0 54be5e78c4d7490daa2fe870d31d5d79 3fbc11aa81ec454b8b1144600b3a5e79--54be5e78c4d7490daa2fe870d31d5d79 865fe3075b25405891c3d919560bc80c 1 499903a66b184098984855f6bb976941 54be5e78c4d7490daa2fe870d31d5d79--499903a66b184098984855f6bb976941 3f0165d5c21240c59a4e31c7b9569a6d 057221b1be9e46419b47ef63a2ac9105 AddBlock 865fe3075b25405891c3d919560bc80c--057221b1be9e46419b47ef63a2ac9105 14121ba001e34541bca2d02b2ddb2915 2 057221b1be9e46419b47ef63a2ac9105--3f0165d5c21240c59a4e31c7b9569a6d 7f83400b3fac44c296e97bd8f2db6ab7 f106c26e915247e49df6b9880c28ab39 14121ba001e34541bca2d02b2ddb2915--f106c26e915247e49df6b9880c28ab39 f106c26e915247e49df6b9880c28ab39--7f83400b3fac44c296e97bd8f2db6ab7
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_10cbc520f1164e67abed97412c5e085f cluster_9e6159c518204210a22912041c395205 rx 9924e22f26c0499a8cd0b37fb4af19bf 0 0f1d666f2a964838908c54119744bffd X 9924e22f26c0499a8cd0b37fb4af19bf--0f1d666f2a964838908c54119744bffd a6b0442c1b324a2f9938f40c1a365bac 1 e7797dd8dabb4cfb8131e50487f69de9 0f1d666f2a964838908c54119744bffd--e7797dd8dabb4cfb8131e50487f69de9 5103a89b86ee40e8bcd4df5cca509ce8 e7797dd8dabb4cfb8131e50487f69de9--5103a89b86ee40e8bcd4df5cca509ce8 9ceaeec7806e444ba5a0afc292af5218 5103a89b86ee40e8bcd4df5cca509ce8--9ceaeec7806e444ba5a0afc292af5218 710cbf6908c2451b98482272715e669d 05ac1ec028934474abab7ac29aeede45 Y a6b0442c1b324a2f9938f40c1a365bac--05ac1ec028934474abab7ac29aeede45 6e94c2dbf34a42c68ae32c070ae1dc90 2 a241ca2c444942659c4c16dd04a08084 05ac1ec028934474abab7ac29aeede45--a241ca2c444942659c4c16dd04a08084 a8f7800e3d0440059b694d031324a1c7 HamEvo a241ca2c444942659c4c16dd04a08084--a8f7800e3d0440059b694d031324a1c7 a8f7800e3d0440059b694d031324a1c7--710cbf6908c2451b98482272715e669d 02199127bff84ea4a8efdbbb23b6ee72 af7494a2dd3643818f5a84fa9ea58d4a RX(x) 6e94c2dbf34a42c68ae32c070ae1dc90--af7494a2dd3643818f5a84fa9ea58d4a 7fcd5c22fc24453ca2c270ebeb845092 3 396577f7f88545df9677a630815382f8 af7494a2dd3643818f5a84fa9ea58d4a--396577f7f88545df9677a630815382f8 f54c45eb652d4ecfb4eb4828de9c044f t = 10 396577f7f88545df9677a630815382f8--f54c45eb652d4ecfb4eb4828de9c044f f54c45eb652d4ecfb4eb4828de9c044f--02199127bff84ea4a8efdbbb23b6ee72 e801dea818f844c09eb9cb0a4be30b70 894bdfbaee084860bc7bd21dc7baf73b RX(0.5) 7fcd5c22fc24453ca2c270ebeb845092--894bdfbaee084860bc7bd21dc7baf73b 595719327edd4424bbc1740405668145 X 894bdfbaee084860bc7bd21dc7baf73b--595719327edd4424bbc1740405668145 595719327edd4424bbc1740405668145--396577f7f88545df9677a630815382f8 e230ec8f4470430a9c3fa3ad6b8a05dd 595719327edd4424bbc1740405668145--e230ec8f4470430a9c3fa3ad6b8a05dd e230ec8f4470430a9c3fa3ad6b8a05dd--e801dea818f844c09eb9cb0a4be30b70
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_97e7e860ec8948019fba92fc56fe7a9c HEA cluster_8720137b01d446e4820c60dae17c3d6b Tower Fourier FM 0d3fc45be0cc42e9be1112dd72328be9 0 bae5ad713c484ce38268ff44be5d34c5 RX(1.0*phi) 0d3fc45be0cc42e9be1112dd72328be9--bae5ad713c484ce38268ff44be5d34c5 487f6ff4ea0e4a2f8a0f2834e6521750 1 bb581cea378f4c459dc26dc3a3fb0fe1 RX(theta₀) bae5ad713c484ce38268ff44be5d34c5--bb581cea378f4c459dc26dc3a3fb0fe1 d1ad45a2839e4208b95fc6413a0cbba3 RY(theta₄) bb581cea378f4c459dc26dc3a3fb0fe1--d1ad45a2839e4208b95fc6413a0cbba3 65d9a39eae444b9d8d6e301194a24803 RX(theta₈) d1ad45a2839e4208b95fc6413a0cbba3--65d9a39eae444b9d8d6e301194a24803 cc8b07ba149248888842bb371660dffe 65d9a39eae444b9d8d6e301194a24803--cc8b07ba149248888842bb371660dffe 8b977cb23c5d4dea8f903b8dc08fc6c0 cc8b07ba149248888842bb371660dffe--8b977cb23c5d4dea8f903b8dc08fc6c0 c1ff44029c814f50ba44f904674342a9 RX(theta₁₂) 8b977cb23c5d4dea8f903b8dc08fc6c0--c1ff44029c814f50ba44f904674342a9 ecd1695d7aca43ec9235e9eeeaddab0e RY(theta₁₆) c1ff44029c814f50ba44f904674342a9--ecd1695d7aca43ec9235e9eeeaddab0e c26237e5fc6f4f54a94762b668a61896 RX(theta₂₀) ecd1695d7aca43ec9235e9eeeaddab0e--c26237e5fc6f4f54a94762b668a61896 257196d7d88a41d5a09023dd47e04862 c26237e5fc6f4f54a94762b668a61896--257196d7d88a41d5a09023dd47e04862 737920bbfad9401cb318f0a409db4934 257196d7d88a41d5a09023dd47e04862--737920bbfad9401cb318f0a409db4934 37611f50f8224462957be1f8137228f4 737920bbfad9401cb318f0a409db4934--37611f50f8224462957be1f8137228f4 8bdcdc5d7c884262bf850da46c53850e c47278effe4b475b94458224dccfc711 RX(2.0*phi) 487f6ff4ea0e4a2f8a0f2834e6521750--c47278effe4b475b94458224dccfc711 fccc3adce43d4865b0e5c65d79f769b6 2 a63b95aabfff45ad8e16f2cf2d3c36bd RX(theta₁) c47278effe4b475b94458224dccfc711--a63b95aabfff45ad8e16f2cf2d3c36bd b5e6db08689048c68b7c9c8f9f38c4b4 RY(theta₅) a63b95aabfff45ad8e16f2cf2d3c36bd--b5e6db08689048c68b7c9c8f9f38c4b4 b9669e20d4aa48349b6ccf2207270d95 RX(theta₉) b5e6db08689048c68b7c9c8f9f38c4b4--b9669e20d4aa48349b6ccf2207270d95 4e81f436471b4921bdb604f183c4bd59 X b9669e20d4aa48349b6ccf2207270d95--4e81f436471b4921bdb604f183c4bd59 4e81f436471b4921bdb604f183c4bd59--cc8b07ba149248888842bb371660dffe c8f1a1884b9e4034a1386271c7c98f20 4e81f436471b4921bdb604f183c4bd59--c8f1a1884b9e4034a1386271c7c98f20 795cb673c1d741339960e04956469f29 RX(theta₁₃) c8f1a1884b9e4034a1386271c7c98f20--795cb673c1d741339960e04956469f29 435cc06d95c24c35b24d5607b782972f RY(theta₁₇) 795cb673c1d741339960e04956469f29--435cc06d95c24c35b24d5607b782972f 771dcfecb3264543935859dc700a4245 RX(theta₂₁) 435cc06d95c24c35b24d5607b782972f--771dcfecb3264543935859dc700a4245 01d64a2e21064d61be3d0a1aef974d4c X 771dcfecb3264543935859dc700a4245--01d64a2e21064d61be3d0a1aef974d4c 01d64a2e21064d61be3d0a1aef974d4c--257196d7d88a41d5a09023dd47e04862 f889520b4cdc440ea8feab6f57aa6e56 01d64a2e21064d61be3d0a1aef974d4c--f889520b4cdc440ea8feab6f57aa6e56 f889520b4cdc440ea8feab6f57aa6e56--8bdcdc5d7c884262bf850da46c53850e 21ecb55aa677493a9243a25ab982052a 3a9370f7ff444b90b315ef8baa281ac9 RX(3.0*phi) fccc3adce43d4865b0e5c65d79f769b6--3a9370f7ff444b90b315ef8baa281ac9 7239341656fb4747924fb4f52eb518ff 3 21f91f3db3aa44318ac7d7b131b54f69 RX(theta₂) 3a9370f7ff444b90b315ef8baa281ac9--21f91f3db3aa44318ac7d7b131b54f69 629d4635c0024d3894b0f0ccc84ff8cc RY(theta₆) 21f91f3db3aa44318ac7d7b131b54f69--629d4635c0024d3894b0f0ccc84ff8cc 2d80e3a436114220a23d91ea81f02332 RX(theta₁₀) 629d4635c0024d3894b0f0ccc84ff8cc--2d80e3a436114220a23d91ea81f02332 cb1151a9cfc644479222fc1912333ca7 2d80e3a436114220a23d91ea81f02332--cb1151a9cfc644479222fc1912333ca7 f71193e58e454f99b24b77a283b89469 X cb1151a9cfc644479222fc1912333ca7--f71193e58e454f99b24b77a283b89469 f71193e58e454f99b24b77a283b89469--c8f1a1884b9e4034a1386271c7c98f20 70b708a7c8ed40268b7c3172292514a3 RX(theta₁₄) f71193e58e454f99b24b77a283b89469--70b708a7c8ed40268b7c3172292514a3 4d1d04e2ff214df58ae88a53e22e73e9 RY(theta₁₈) 70b708a7c8ed40268b7c3172292514a3--4d1d04e2ff214df58ae88a53e22e73e9 a54563ec6068488daf1cba2648a72822 RX(theta₂₂) 4d1d04e2ff214df58ae88a53e22e73e9--a54563ec6068488daf1cba2648a72822 ef565cf219a54a7d950bb058d20874f7 a54563ec6068488daf1cba2648a72822--ef565cf219a54a7d950bb058d20874f7 f33d02ce2c8a421cbd4de42f83487bc7 X ef565cf219a54a7d950bb058d20874f7--f33d02ce2c8a421cbd4de42f83487bc7 f33d02ce2c8a421cbd4de42f83487bc7--f889520b4cdc440ea8feab6f57aa6e56 f33d02ce2c8a421cbd4de42f83487bc7--21ecb55aa677493a9243a25ab982052a 79584573a6b74da4bd6802af7fc566d5 e31fc2df213b44b69c1d958d69e14d3e RX(4.0*phi) 7239341656fb4747924fb4f52eb518ff--e31fc2df213b44b69c1d958d69e14d3e 469b2edf0ad3460a91398fcf6908e31f RX(theta₃) e31fc2df213b44b69c1d958d69e14d3e--469b2edf0ad3460a91398fcf6908e31f 22c389ec16e641c8996ebed0512345df RY(theta₇) 469b2edf0ad3460a91398fcf6908e31f--22c389ec16e641c8996ebed0512345df c9e1d3ada3134d118125b7f7ec765287 RX(theta₁₁) 22c389ec16e641c8996ebed0512345df--c9e1d3ada3134d118125b7f7ec765287 48805f61cd784376906f5aed5d7502dc X c9e1d3ada3134d118125b7f7ec765287--48805f61cd784376906f5aed5d7502dc 48805f61cd784376906f5aed5d7502dc--cb1151a9cfc644479222fc1912333ca7 2844cc8372c2419ca4c7b232eda6d5a6 48805f61cd784376906f5aed5d7502dc--2844cc8372c2419ca4c7b232eda6d5a6 bed557b6174d40179c46ad6b118ea9eb RX(theta₁₅) 2844cc8372c2419ca4c7b232eda6d5a6--bed557b6174d40179c46ad6b118ea9eb 9c518762214443ea87bd252bc416ed47 RY(theta₁₉) bed557b6174d40179c46ad6b118ea9eb--9c518762214443ea87bd252bc416ed47 79d0d3601b7f40be9247aed42b2c4b60 RX(theta₂₃) 9c518762214443ea87bd252bc416ed47--79d0d3601b7f40be9247aed42b2c4b60 1c00f70d8a1d4875ace028e7a6a52536 X 79d0d3601b7f40be9247aed42b2c4b60--1c00f70d8a1d4875ace028e7a6a52536 1c00f70d8a1d4875ace028e7a6a52536--ef565cf219a54a7d950bb058d20874f7 e93d9912724f4c8b8003d9739dda9d12 1c00f70d8a1d4875ace028e7a6a52536--e93d9912724f4c8b8003d9739dda9d12 e93d9912724f4c8b8003d9739dda9d12--79584573a6b74da4bd6802af7fc566d5
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_ad2994cf555241499abe5321e33fefc6 Obs. cluster_79600a7cfa1947bf8022d2d8461b70d4 cluster_2ee17acdd07d413f8679e6fcf13f8472 HEA 72f162764ca54c628dd073e5cd7874fb 0 bd40b714d09a4fd2b1d358cf7b64d034 RX(theta₀) 72f162764ca54c628dd073e5cd7874fb--bd40b714d09a4fd2b1d358cf7b64d034 c06d4f049912437d90a8ce488ba5f224 1 3c8d630cac8340afa50ab19202608f22 RY(theta₃) bd40b714d09a4fd2b1d358cf7b64d034--3c8d630cac8340afa50ab19202608f22 6b8d1594d96749b09590354477207dc2 RX(theta₆) 3c8d630cac8340afa50ab19202608f22--6b8d1594d96749b09590354477207dc2 9375cfe09f534737aeb648855580c265 6b8d1594d96749b09590354477207dc2--9375cfe09f534737aeb648855580c265 a28f74d4afc04785968a6af738b5e7cf 9375cfe09f534737aeb648855580c265--a28f74d4afc04785968a6af738b5e7cf 9368f684b35e4184992d35885f4bd9d6 RX(theta₉) a28f74d4afc04785968a6af738b5e7cf--9368f684b35e4184992d35885f4bd9d6 b4b34a53bcdd4165a758bfb06939d9d0 RY(theta₁₂) 9368f684b35e4184992d35885f4bd9d6--b4b34a53bcdd4165a758bfb06939d9d0 93f8e7c7d2a44ba891afcbcf896d3c01 RX(theta₁₅) b4b34a53bcdd4165a758bfb06939d9d0--93f8e7c7d2a44ba891afcbcf896d3c01 116aad07351b43a7b34753583076b77b 93f8e7c7d2a44ba891afcbcf896d3c01--116aad07351b43a7b34753583076b77b 1aa0ee66b6a540bbb92f2c1d722f574b 116aad07351b43a7b34753583076b77b--1aa0ee66b6a540bbb92f2c1d722f574b a7a5d446365b47d5be1e120c1ddeaabd 1aa0ee66b6a540bbb92f2c1d722f574b--a7a5d446365b47d5be1e120c1ddeaabd 083636af32a74574a7ced379d423ea45 a7a5d446365b47d5be1e120c1ddeaabd--083636af32a74574a7ced379d423ea45 9ad634eafc894f83a43456c1f9e5432e a3b1775d1dac4873bb609e292a8f30e8 RX(theta₁) c06d4f049912437d90a8ce488ba5f224--a3b1775d1dac4873bb609e292a8f30e8 bebcb492d5194adf8e4111907d78fa2a 2 3b7ec544873841b09e2eebb285250aef RY(theta₄) a3b1775d1dac4873bb609e292a8f30e8--3b7ec544873841b09e2eebb285250aef 17ddb8291fd84398bf6ab833106b1a40 RX(theta₇) 3b7ec544873841b09e2eebb285250aef--17ddb8291fd84398bf6ab833106b1a40 f6c3d23b9ad8496c978a8ff08c94c760 X 17ddb8291fd84398bf6ab833106b1a40--f6c3d23b9ad8496c978a8ff08c94c760 f6c3d23b9ad8496c978a8ff08c94c760--9375cfe09f534737aeb648855580c265 33333a3907b14764819bfb886cd5f658 f6c3d23b9ad8496c978a8ff08c94c760--33333a3907b14764819bfb886cd5f658 f8163e6a924146a2ac7bc26aa978c90b RX(theta₁₀) 33333a3907b14764819bfb886cd5f658--f8163e6a924146a2ac7bc26aa978c90b 7cad4fe86a81413aae975e27cd9836d8 RY(theta₁₃) f8163e6a924146a2ac7bc26aa978c90b--7cad4fe86a81413aae975e27cd9836d8 4afb55c52c5b4d418209391bfd184052 RX(theta₁₆) 7cad4fe86a81413aae975e27cd9836d8--4afb55c52c5b4d418209391bfd184052 4a648bace39f4d0b98390561add5581e X 4afb55c52c5b4d418209391bfd184052--4a648bace39f4d0b98390561add5581e 4a648bace39f4d0b98390561add5581e--116aad07351b43a7b34753583076b77b 587f43f4b4444bd082859e413005d3e1 4a648bace39f4d0b98390561add5581e--587f43f4b4444bd082859e413005d3e1 9ec7c7e1a77c49a594890ca5c027116c AddBlock 587f43f4b4444bd082859e413005d3e1--9ec7c7e1a77c49a594890ca5c027116c 9ec7c7e1a77c49a594890ca5c027116c--9ad634eafc894f83a43456c1f9e5432e bb4cb0a7dde542e8b0087fee637836e4 54b2a37cb88c465792468704782ab933 RX(theta₂) bebcb492d5194adf8e4111907d78fa2a--54b2a37cb88c465792468704782ab933 1f3cd11583ff4bc2bfc9de8e3c1070c4 RY(theta₅) 54b2a37cb88c465792468704782ab933--1f3cd11583ff4bc2bfc9de8e3c1070c4 825cb9fa0f354f069fd2884d9c2482ed RX(theta₈) 1f3cd11583ff4bc2bfc9de8e3c1070c4--825cb9fa0f354f069fd2884d9c2482ed a80e5b591522413b8d9b71405fa6da07 825cb9fa0f354f069fd2884d9c2482ed--a80e5b591522413b8d9b71405fa6da07 bc43a373130e462290a9a78a1d7ad039 X a80e5b591522413b8d9b71405fa6da07--bc43a373130e462290a9a78a1d7ad039 bc43a373130e462290a9a78a1d7ad039--33333a3907b14764819bfb886cd5f658 129b27d19a7b4b02be5b3c5f65f3c291 RX(theta₁₁) bc43a373130e462290a9a78a1d7ad039--129b27d19a7b4b02be5b3c5f65f3c291 4d90c392c59341aba65b18dae3a25e3a RY(theta₁₄) 129b27d19a7b4b02be5b3c5f65f3c291--4d90c392c59341aba65b18dae3a25e3a 1e4ca633eff34415b61944c0dd8b9c6d RX(theta₁₇) 4d90c392c59341aba65b18dae3a25e3a--1e4ca633eff34415b61944c0dd8b9c6d 63281dff7b954d468ad235b71d20bd4a 1e4ca633eff34415b61944c0dd8b9c6d--63281dff7b954d468ad235b71d20bd4a 4f278df99dfd4e498cceb49a8a122a0c X 63281dff7b954d468ad235b71d20bd4a--4f278df99dfd4e498cceb49a8a122a0c 4f278df99dfd4e498cceb49a8a122a0c--587f43f4b4444bd082859e413005d3e1 8d8385207dc94d0589b454c5f979fcd7 4f278df99dfd4e498cceb49a8a122a0c--8d8385207dc94d0589b454c5f979fcd7 8d8385207dc94d0589b454c5f979fcd7--bb4cb0a7dde542e8b0087fee637836e4
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 c47e43301182430e8419064d6441df72 0 1d6147762aaf48fdb3c157be04fd11bf c47e43301182430e8419064d6441df72--1d6147762aaf48fdb3c157be04fd11bf 0cfb8f15c46249f59486e86a72d0364e 1 e48c089cd48645d28c63648e07aa06c4 49c53d2da0734b04a6c20ced7b132c37 1d6147762aaf48fdb3c157be04fd11bf--49c53d2da0734b04a6c20ced7b132c37 055a48e477fe4c1b81bed65db1abfcb7 e48c089cd48645d28c63648e07aa06c4--055a48e477fe4c1b81bed65db1abfcb7 97ae454ca55a48e488ed37eef47adf0a 0f0c433b7b204f9aab3538c908e62d24 055a48e477fe4c1b81bed65db1abfcb7--0f0c433b7b204f9aab3538c908e62d24 89cc294487f54b2abd48f379855afd27 97ae454ca55a48e488ed37eef47adf0a--89cc294487f54b2abd48f379855afd27 c32b00767b73410c99db6fdf239dd9b1 3366640fef7944e182ceb7951e757f2c 0cfb8f15c46249f59486e86a72d0364e--3366640fef7944e182ceb7951e757f2c e391f71ead1c4ec59245022f7061687a 2 3366640fef7944e182ceb7951e757f2c--e48c089cd48645d28c63648e07aa06c4 ed6f759e56704c18bc972af4ed8edc86 49c53d2da0734b04a6c20ced7b132c37--ed6f759e56704c18bc972af4ed8edc86 f2adfe9bdc9d4b2980148089840990d3 ed6f759e56704c18bc972af4ed8edc86--f2adfe9bdc9d4b2980148089840990d3 f2adfe9bdc9d4b2980148089840990d3--c32b00767b73410c99db6fdf239dd9b1 1bfc95309e6d4f67ada2e5e12eb09d31 4b059725dc7f408d998248d78ec04722 e391f71ead1c4ec59245022f7061687a--4b059725dc7f408d998248d78ec04722 46d96b0c78a94455b8cdf094decd7fcb 3 1e125b0603014c94b693e9da02065705 4b059725dc7f408d998248d78ec04722--1e125b0603014c94b693e9da02065705 28b45e5b38554f7ca1c55e85bf0192ef 1e125b0603014c94b693e9da02065705--28b45e5b38554f7ca1c55e85bf0192ef 31aba041d07c4a7eaf6b455d6c8bddb1 28b45e5b38554f7ca1c55e85bf0192ef--31aba041d07c4a7eaf6b455d6c8bddb1 31aba041d07c4a7eaf6b455d6c8bddb1--1bfc95309e6d4f67ada2e5e12eb09d31 79e1ae0b071140feb1f844633e4b7b67 281be78c3e524a18909679d3f2e99451 46d96b0c78a94455b8cdf094decd7fcb--281be78c3e524a18909679d3f2e99451 fd14d72977e646618aabbfc8222de809 281be78c3e524a18909679d3f2e99451--fd14d72977e646618aabbfc8222de809 b76215a9752a4f03b4441d46be33169d fd14d72977e646618aabbfc8222de809--b76215a9752a4f03b4441d46be33169d b76215a9752a4f03b4441d46be33169d--97ae454ca55a48e488ed37eef47adf0a 0f0c433b7b204f9aab3538c908e62d24--79e1ae0b071140feb1f844633e4b7b67
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 e740d83ea6824560af39f1c11cc79f52 0 90ff8ea39faa4285a96c56a7cfca4f1f e740d83ea6824560af39f1c11cc79f52--90ff8ea39faa4285a96c56a7cfca4f1f 6325c4c1cd7b4f58855272dfe46e7643 1 b96657de48a34ccca0a6653dbd6a45d9 90ff8ea39faa4285a96c56a7cfca4f1f--b96657de48a34ccca0a6653dbd6a45d9 11513b6aca4443a18d56547850a44364 b96657de48a34ccca0a6653dbd6a45d9--11513b6aca4443a18d56547850a44364 f199a61ea29440e09c17b89b97de836e 11513b6aca4443a18d56547850a44364--f199a61ea29440e09c17b89b97de836e d5dd69d622204f5492e9d426c2496393 179d9a9ae7044086af12abbda3c38a4b PHASE(0.5) 6325c4c1cd7b4f58855272dfe46e7643--179d9a9ae7044086af12abbda3c38a4b d7c008a4ad1449faa3f82cf5a01024db 2 179d9a9ae7044086af12abbda3c38a4b--90ff8ea39faa4285a96c56a7cfca4f1f 4b406674ea6e4a5888bb09e253f16827 179d9a9ae7044086af12abbda3c38a4b--4b406674ea6e4a5888bb09e253f16827 e912f262bd6f4a8ab124aa59b8f04790 4b406674ea6e4a5888bb09e253f16827--e912f262bd6f4a8ab124aa59b8f04790 e912f262bd6f4a8ab124aa59b8f04790--d5dd69d622204f5492e9d426c2496393 2bd1ccd150c14609b1215b4710603f9c 501c42b85c704672b395d852d65db294 d7c008a4ad1449faa3f82cf5a01024db--501c42b85c704672b395d852d65db294 19466cfe11e74db6a5460b9afcfa42be 3 7ba92278a92342aaaaa8ac7ee38d7cd0 PHASE(0.5) 501c42b85c704672b395d852d65db294--7ba92278a92342aaaaa8ac7ee38d7cd0 7ba92278a92342aaaaa8ac7ee38d7cd0--b96657de48a34ccca0a6653dbd6a45d9 7155000fe87a4edda97faa93d4838eb9 7ba92278a92342aaaaa8ac7ee38d7cd0--7155000fe87a4edda97faa93d4838eb9 7155000fe87a4edda97faa93d4838eb9--2bd1ccd150c14609b1215b4710603f9c a8a95d0403034313980b85da9267da7c 20cb37591d384a95b15689743b41077a 19466cfe11e74db6a5460b9afcfa42be--20cb37591d384a95b15689743b41077a 242bc31065a34660a9c3c4fc625908e5 20cb37591d384a95b15689743b41077a--242bc31065a34660a9c3c4fc625908e5 f74fec97ca7e41479ccdfd05939dbccb PHASE(0.5) 242bc31065a34660a9c3c4fc625908e5--f74fec97ca7e41479ccdfd05939dbccb f74fec97ca7e41479ccdfd05939dbccb--11513b6aca4443a18d56547850a44364 f74fec97ca7e41479ccdfd05939dbccb--a8a95d0403034313980b85da9267da7c

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