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 2700a0edb4cb49fc90239babb5b0abd5 0 f32a71ded1394c57b6f2fb6ff2c73018 X 2700a0edb4cb49fc90239babb5b0abd5--f32a71ded1394c57b6f2fb6ff2c73018 39c4fa88bf5c458e8039c3fe2fb4fd29 1 90756f21d8ff4c1caf059ea6911740d0 f32a71ded1394c57b6f2fb6ff2c73018--90756f21d8ff4c1caf059ea6911740d0 ef0e6d12cc054daf98da58ae9d0132e3 6040219e549f42cb89650be95908a305 Y 39c4fa88bf5c458e8039c3fe2fb4fd29--6040219e549f42cb89650be95908a305 6040219e549f42cb89650be95908a305--ef0e6d12cc054daf98da58ae9d0132e3
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 ee00ea89376d4296aabf9482bb93fbf4 0 a9d8bbe2a45d4df1929d08c9efab5e70 X ee00ea89376d4296aabf9482bb93fbf4--a9d8bbe2a45d4df1929d08c9efab5e70 817f1e1163004dc8b26871e78a89b3d4 Y a9d8bbe2a45d4df1929d08c9efab5e70--817f1e1163004dc8b26871e78a89b3d4 3d17db15ba004a4488228944a519b024 817f1e1163004dc8b26871e78a89b3d4--3d17db15ba004a4488228944a519b024
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 05b7d69ce8fd4d8d84b611df5cd9dc9c 0 385dd1b77b2c431082a6bb3d5a546a69 X 05b7d69ce8fd4d8d84b611df5cd9dc9c--385dd1b77b2c431082a6bb3d5a546a69 02dd9ec561594283a1800989ecee6f11 1 7237ff731a2a449a9671c194fe6373be 385dd1b77b2c431082a6bb3d5a546a69--7237ff731a2a449a9671c194fe6373be bdc4cb65da774fc89e2866e51ee211d2 7237ff731a2a449a9671c194fe6373be--bdc4cb65da774fc89e2866e51ee211d2 e4d64aad4c65476486b4e20890b08252 4820bc997e894350a05be441bedf6e47 02dd9ec561594283a1800989ecee6f11--4820bc997e894350a05be441bedf6e47 7eb6a372d9ae40309fcbd16b19dfc66f Y 4820bc997e894350a05be441bedf6e47--7eb6a372d9ae40309fcbd16b19dfc66f 7eb6a372d9ae40309fcbd16b19dfc66f--e4d64aad4c65476486b4e20890b08252
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_945266ddf848464ca8c08f09aaddf4b7 9cee0219131a4d4186f607aa2e9c984c 0 53332314e45d45d8ba64bb8302c070e8 9cee0219131a4d4186f607aa2e9c984c--53332314e45d45d8ba64bb8302c070e8 00948afec01c4faebeaefa67495a92a3 1 15905ed464514bfa9ff8fad2a44b35fd 53332314e45d45d8ba64bb8302c070e8--15905ed464514bfa9ff8fad2a44b35fd 725de836e2d04419b350692e21ca028c f177150954df4c9db2de0dc787dfe9a9 AddBlock 00948afec01c4faebeaefa67495a92a3--f177150954df4c9db2de0dc787dfe9a9 6667afed643b4568830dd474628565b0 2 f177150954df4c9db2de0dc787dfe9a9--725de836e2d04419b350692e21ca028c e7fe93edb3a54932ae803429ba4c79a8 7f8888304b8345008d5d5b3031f2e1b7 6667afed643b4568830dd474628565b0--7f8888304b8345008d5d5b3031f2e1b7 7f8888304b8345008d5d5b3031f2e1b7--e7fe93edb3a54932ae803429ba4c79a8
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_75238310045944568828da0b5436f259 cluster_18aa77e1e79a4a1f824d3934f51343ba rx cce4a2ae9de749ce8a33e2ba3a99a407 0 54496de3ee4f4a7ebdc9c3039408235e X cce4a2ae9de749ce8a33e2ba3a99a407--54496de3ee4f4a7ebdc9c3039408235e 309914c5e47248099233e9b0c59b4a41 1 e66584db14b249e4a8e536a820cb718a 54496de3ee4f4a7ebdc9c3039408235e--e66584db14b249e4a8e536a820cb718a 7efd6f13a3ea44f2a33b7070f56603c7 e66584db14b249e4a8e536a820cb718a--7efd6f13a3ea44f2a33b7070f56603c7 5c72ff66e3524ed786406873480e3551 7efd6f13a3ea44f2a33b7070f56603c7--5c72ff66e3524ed786406873480e3551 eadba4197d3644d78bb640a40cff3d2e 4bf4e889d92e4fa2b9a456842d2a479f Y 309914c5e47248099233e9b0c59b4a41--4bf4e889d92e4fa2b9a456842d2a479f 17f6783084944e7fb375ba9d60ae2678 2 cf54b1c17cc246c6965763772bd4ec12 4bf4e889d92e4fa2b9a456842d2a479f--cf54b1c17cc246c6965763772bd4ec12 f46c3fe441a6478691275cdbd25947e9 HamEvo cf54b1c17cc246c6965763772bd4ec12--f46c3fe441a6478691275cdbd25947e9 f46c3fe441a6478691275cdbd25947e9--eadba4197d3644d78bb640a40cff3d2e 56b7501b39cd49a6b7308b160ee3f81d 17d6f3c645e64950bf58f2c68255a1d2 RX(x) 17f6783084944e7fb375ba9d60ae2678--17d6f3c645e64950bf58f2c68255a1d2 9702d51a2499417fa30e3944ebfe4048 3 a1066912d63d4e94916bd47f043d2a7c 17d6f3c645e64950bf58f2c68255a1d2--a1066912d63d4e94916bd47f043d2a7c 92f73168eac04b69bcf610170a5ff179 t = 10 a1066912d63d4e94916bd47f043d2a7c--92f73168eac04b69bcf610170a5ff179 92f73168eac04b69bcf610170a5ff179--56b7501b39cd49a6b7308b160ee3f81d f8c0bf20585548d7b8515f53f5e14be2 22ecdad677654f5e836a0afc3e6bcda6 RX(0.5) 9702d51a2499417fa30e3944ebfe4048--22ecdad677654f5e836a0afc3e6bcda6 16771a5ddb84462eb249c8cfecaddbce X 22ecdad677654f5e836a0afc3e6bcda6--16771a5ddb84462eb249c8cfecaddbce 16771a5ddb84462eb249c8cfecaddbce--a1066912d63d4e94916bd47f043d2a7c 7c2b44b98cc44deaa3180d8b27661af9 16771a5ddb84462eb249c8cfecaddbce--7c2b44b98cc44deaa3180d8b27661af9 7c2b44b98cc44deaa3180d8b27661af9--f8c0bf20585548d7b8515f53f5e14be2
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_2f3e46edda1f4752b2d15ed1fedf702c HEA cluster_0e9b7d60f3a24070a5f3a40f2b240d30 Tower Fourier FM 09f5045eff014152919243a853582872 0 bd1b45c655f44a39bf3b3f78f4a20565 RX(1.0*phi) 09f5045eff014152919243a853582872--bd1b45c655f44a39bf3b3f78f4a20565 81a93c345f054564a5bf84b40a01c9c8 1 3a02c4a67619447ca01129df2b32d677 RX(theta₀) bd1b45c655f44a39bf3b3f78f4a20565--3a02c4a67619447ca01129df2b32d677 c3d889ad702a483bb7b8f962b7958c0b RY(theta₄) 3a02c4a67619447ca01129df2b32d677--c3d889ad702a483bb7b8f962b7958c0b cf0954bb92804efba8c637d26db2acaf RX(theta₈) c3d889ad702a483bb7b8f962b7958c0b--cf0954bb92804efba8c637d26db2acaf aaa0fee4ee894710be2ef81915b202d9 cf0954bb92804efba8c637d26db2acaf--aaa0fee4ee894710be2ef81915b202d9 c362fc91bc6b40258befd9a5ed3f431c aaa0fee4ee894710be2ef81915b202d9--c362fc91bc6b40258befd9a5ed3f431c 9efe739bd50940f99bbea6d539aa8e83 RX(theta₁₂) c362fc91bc6b40258befd9a5ed3f431c--9efe739bd50940f99bbea6d539aa8e83 ed987b3ce8914d5cb426e4a14137a69b RY(theta₁₆) 9efe739bd50940f99bbea6d539aa8e83--ed987b3ce8914d5cb426e4a14137a69b 4f80f6a44ff948c5b0a5a69df3d8f863 RX(theta₂₀) ed987b3ce8914d5cb426e4a14137a69b--4f80f6a44ff948c5b0a5a69df3d8f863 da176e727b3f4237903a9a89877f7a9d 4f80f6a44ff948c5b0a5a69df3d8f863--da176e727b3f4237903a9a89877f7a9d 5deed6685238471ea989e60840bf0272 da176e727b3f4237903a9a89877f7a9d--5deed6685238471ea989e60840bf0272 efc30e46558947b681bb5dc586e4aea4 5deed6685238471ea989e60840bf0272--efc30e46558947b681bb5dc586e4aea4 6a664675a3944a9ba617a9a628929e3c cbf93e5db6dc4a54bd813cbe5dadc157 RX(2.0*phi) 81a93c345f054564a5bf84b40a01c9c8--cbf93e5db6dc4a54bd813cbe5dadc157 36781f3b7dbe4da283a7e13f9081f731 2 5cbf4c9dd4f04c579bc1d193cb7601d4 RX(theta₁) cbf93e5db6dc4a54bd813cbe5dadc157--5cbf4c9dd4f04c579bc1d193cb7601d4 73c1332cdc6f43e0a8fbb6b37d4adee2 RY(theta₅) 5cbf4c9dd4f04c579bc1d193cb7601d4--73c1332cdc6f43e0a8fbb6b37d4adee2 c978b67a060741e99920960d012b1e3b RX(theta₉) 73c1332cdc6f43e0a8fbb6b37d4adee2--c978b67a060741e99920960d012b1e3b d5607fca5367428086777a2d1af4999c X c978b67a060741e99920960d012b1e3b--d5607fca5367428086777a2d1af4999c d5607fca5367428086777a2d1af4999c--aaa0fee4ee894710be2ef81915b202d9 e3d8496374054360b9a698f12d2e8f49 d5607fca5367428086777a2d1af4999c--e3d8496374054360b9a698f12d2e8f49 9102fa5c0b81447bafd8b028a92e6e1b RX(theta₁₃) e3d8496374054360b9a698f12d2e8f49--9102fa5c0b81447bafd8b028a92e6e1b 8bf283f37d6240ed879743898a28d6bb RY(theta₁₇) 9102fa5c0b81447bafd8b028a92e6e1b--8bf283f37d6240ed879743898a28d6bb f195caad545c48098a5d554592491a37 RX(theta₂₁) 8bf283f37d6240ed879743898a28d6bb--f195caad545c48098a5d554592491a37 8f664e23e18947c590cbaf30a23536bc X f195caad545c48098a5d554592491a37--8f664e23e18947c590cbaf30a23536bc 8f664e23e18947c590cbaf30a23536bc--da176e727b3f4237903a9a89877f7a9d 66b1845d89e9436abe3b4af3f8c58410 8f664e23e18947c590cbaf30a23536bc--66b1845d89e9436abe3b4af3f8c58410 66b1845d89e9436abe3b4af3f8c58410--6a664675a3944a9ba617a9a628929e3c a33d1ffd929647f2ad810c5d4517cb48 8c2e5f1ee4de49aa81d497a2c126ee95 RX(3.0*phi) 36781f3b7dbe4da283a7e13f9081f731--8c2e5f1ee4de49aa81d497a2c126ee95 2622f0789f7b47b5bec0a0b3ff018c05 3 f8257680c507425f97edee700ada8f76 RX(theta₂) 8c2e5f1ee4de49aa81d497a2c126ee95--f8257680c507425f97edee700ada8f76 65750165deff407798b65766551ece72 RY(theta₆) f8257680c507425f97edee700ada8f76--65750165deff407798b65766551ece72 1b9677b91e474f3fa4cdd945a5e16a82 RX(theta₁₀) 65750165deff407798b65766551ece72--1b9677b91e474f3fa4cdd945a5e16a82 25d0ac23468f43c3b9a5a3f0487f9192 1b9677b91e474f3fa4cdd945a5e16a82--25d0ac23468f43c3b9a5a3f0487f9192 68328f902c8b48b99e19c6a2399d0e29 X 25d0ac23468f43c3b9a5a3f0487f9192--68328f902c8b48b99e19c6a2399d0e29 68328f902c8b48b99e19c6a2399d0e29--e3d8496374054360b9a698f12d2e8f49 0d352a112c55479482cbb05b8077b722 RX(theta₁₄) 68328f902c8b48b99e19c6a2399d0e29--0d352a112c55479482cbb05b8077b722 f531bec14cd34af3bee9433d00c9750c RY(theta₁₈) 0d352a112c55479482cbb05b8077b722--f531bec14cd34af3bee9433d00c9750c 9378ad04f84d4de1a41b1a4b50413e3b RX(theta₂₂) f531bec14cd34af3bee9433d00c9750c--9378ad04f84d4de1a41b1a4b50413e3b d7b03a3962254060a8339e9a5196c280 9378ad04f84d4de1a41b1a4b50413e3b--d7b03a3962254060a8339e9a5196c280 6031e7f215f443b983ef75c34c1c65a6 X d7b03a3962254060a8339e9a5196c280--6031e7f215f443b983ef75c34c1c65a6 6031e7f215f443b983ef75c34c1c65a6--66b1845d89e9436abe3b4af3f8c58410 6031e7f215f443b983ef75c34c1c65a6--a33d1ffd929647f2ad810c5d4517cb48 f36afc6a9c7c4343af45eb2171eebe55 536196d24abc43cfb901121b9ab1b668 RX(4.0*phi) 2622f0789f7b47b5bec0a0b3ff018c05--536196d24abc43cfb901121b9ab1b668 1ac9deb030b243f5898313b6bf1c7787 RX(theta₃) 536196d24abc43cfb901121b9ab1b668--1ac9deb030b243f5898313b6bf1c7787 0f990373ebc3414f862c97b261f22edf RY(theta₇) 1ac9deb030b243f5898313b6bf1c7787--0f990373ebc3414f862c97b261f22edf 6a107610cde648c3b2d0f81038279f95 RX(theta₁₁) 0f990373ebc3414f862c97b261f22edf--6a107610cde648c3b2d0f81038279f95 bbccf8c90cbb40dea04f3c2f40462134 X 6a107610cde648c3b2d0f81038279f95--bbccf8c90cbb40dea04f3c2f40462134 bbccf8c90cbb40dea04f3c2f40462134--25d0ac23468f43c3b9a5a3f0487f9192 9b31650add9e481a8014226846228189 bbccf8c90cbb40dea04f3c2f40462134--9b31650add9e481a8014226846228189 a6501a24218c447fa0a865396b8f3a6d RX(theta₁₅) 9b31650add9e481a8014226846228189--a6501a24218c447fa0a865396b8f3a6d bfa9b86f0a7349c0ab3b8571456c8167 RY(theta₁₉) a6501a24218c447fa0a865396b8f3a6d--bfa9b86f0a7349c0ab3b8571456c8167 cb3c97269ea64bac8a9011d0757e9242 RX(theta₂₃) bfa9b86f0a7349c0ab3b8571456c8167--cb3c97269ea64bac8a9011d0757e9242 df8f4561597f4b92a5072aa496645143 X cb3c97269ea64bac8a9011d0757e9242--df8f4561597f4b92a5072aa496645143 df8f4561597f4b92a5072aa496645143--d7b03a3962254060a8339e9a5196c280 0f10320046f843da99744dfa13f4acc9 df8f4561597f4b92a5072aa496645143--0f10320046f843da99744dfa13f4acc9 0f10320046f843da99744dfa13f4acc9--f36afc6a9c7c4343af45eb2171eebe55
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_91f4ff4966d2439e88c617fb830aa203 Obs. cluster_fd865ff9edb3453a9d9b315e2e21126f cluster_0b714affc0cd461284360228d30f51af HEA 198aca6e135d48e4ab7e9af1e1332501 0 7a3285d3e9cc4867924025240870c085 RX(theta₀) 198aca6e135d48e4ab7e9af1e1332501--7a3285d3e9cc4867924025240870c085 1dad855ba91049c08dd67d7f342bae4b 1 798a60196b554f1f84a87f4d7e9d8231 RY(theta₃) 7a3285d3e9cc4867924025240870c085--798a60196b554f1f84a87f4d7e9d8231 402889f102424e6eb10051c792d61c3e RX(theta₆) 798a60196b554f1f84a87f4d7e9d8231--402889f102424e6eb10051c792d61c3e 179011195d264aad81beb1b510fe008a 402889f102424e6eb10051c792d61c3e--179011195d264aad81beb1b510fe008a 60eddbf09ddd4228b0d55ad2720dd5a9 179011195d264aad81beb1b510fe008a--60eddbf09ddd4228b0d55ad2720dd5a9 4289c15307ac4c87bebb79cc74112678 RX(theta₉) 60eddbf09ddd4228b0d55ad2720dd5a9--4289c15307ac4c87bebb79cc74112678 5f637838487748bd82bbe3b32e7abdb6 RY(theta₁₂) 4289c15307ac4c87bebb79cc74112678--5f637838487748bd82bbe3b32e7abdb6 d4c9aa67c2464164ad0ec89eed494367 RX(theta₁₅) 5f637838487748bd82bbe3b32e7abdb6--d4c9aa67c2464164ad0ec89eed494367 b08ab10eb8dd4710a77cde2df99eb092 d4c9aa67c2464164ad0ec89eed494367--b08ab10eb8dd4710a77cde2df99eb092 f76e28f07abf42cc964d4f3224e56922 b08ab10eb8dd4710a77cde2df99eb092--f76e28f07abf42cc964d4f3224e56922 5215d560e8b14c2c9702d2b63fcf21fe f76e28f07abf42cc964d4f3224e56922--5215d560e8b14c2c9702d2b63fcf21fe ec132158eb8c47a3a35459415eef7987 5215d560e8b14c2c9702d2b63fcf21fe--ec132158eb8c47a3a35459415eef7987 cdffd9b32b714d9eb1309211e4bfd13e 8d0abbf735b24b76b9b3a3c23b6a5ea3 RX(theta₁) 1dad855ba91049c08dd67d7f342bae4b--8d0abbf735b24b76b9b3a3c23b6a5ea3 fa7f0cf4ef46472b88582acd7d8f030e 2 038c2b49bedc4a9ea45c02c9994eb4c4 RY(theta₄) 8d0abbf735b24b76b9b3a3c23b6a5ea3--038c2b49bedc4a9ea45c02c9994eb4c4 6025e12b407d41e5a5bd7faf700ceae3 RX(theta₇) 038c2b49bedc4a9ea45c02c9994eb4c4--6025e12b407d41e5a5bd7faf700ceae3 a23d2bd7e1b644f997312635eb908666 X 6025e12b407d41e5a5bd7faf700ceae3--a23d2bd7e1b644f997312635eb908666 a23d2bd7e1b644f997312635eb908666--179011195d264aad81beb1b510fe008a 34c037ed77ca403f8bac2af55ed50a58 a23d2bd7e1b644f997312635eb908666--34c037ed77ca403f8bac2af55ed50a58 3c7760cc7e6d4156b9afd01c133e463a RX(theta₁₀) 34c037ed77ca403f8bac2af55ed50a58--3c7760cc7e6d4156b9afd01c133e463a 5052e994050842c4a59730436e1a9be2 RY(theta₁₃) 3c7760cc7e6d4156b9afd01c133e463a--5052e994050842c4a59730436e1a9be2 ee2aa39b52b840fd8a7d37678d41ef88 RX(theta₁₆) 5052e994050842c4a59730436e1a9be2--ee2aa39b52b840fd8a7d37678d41ef88 b8c9ad46d47447bebd7da88481f5d1de X ee2aa39b52b840fd8a7d37678d41ef88--b8c9ad46d47447bebd7da88481f5d1de b8c9ad46d47447bebd7da88481f5d1de--b08ab10eb8dd4710a77cde2df99eb092 97d820c615074f0e850497d38d373d73 b8c9ad46d47447bebd7da88481f5d1de--97d820c615074f0e850497d38d373d73 79bc77c4e7294604ab88e69637724bf9 AddBlock 97d820c615074f0e850497d38d373d73--79bc77c4e7294604ab88e69637724bf9 79bc77c4e7294604ab88e69637724bf9--cdffd9b32b714d9eb1309211e4bfd13e 5aee1d95e9834e239d121c02c5dc0aad cb7f73720d6b443d9a7f2822b1015974 RX(theta₂) fa7f0cf4ef46472b88582acd7d8f030e--cb7f73720d6b443d9a7f2822b1015974 3490da4c914743009e5417316af53969 RY(theta₅) cb7f73720d6b443d9a7f2822b1015974--3490da4c914743009e5417316af53969 e746f4d06ece4d10a111a7128d41962f RX(theta₈) 3490da4c914743009e5417316af53969--e746f4d06ece4d10a111a7128d41962f 032fb8d5c7074702a4c4d2484297fa52 e746f4d06ece4d10a111a7128d41962f--032fb8d5c7074702a4c4d2484297fa52 987472185db744d9afe0eae84d901407 X 032fb8d5c7074702a4c4d2484297fa52--987472185db744d9afe0eae84d901407 987472185db744d9afe0eae84d901407--34c037ed77ca403f8bac2af55ed50a58 90ffbbd1285d4462ae6bb9b09738a9f6 RX(theta₁₁) 987472185db744d9afe0eae84d901407--90ffbbd1285d4462ae6bb9b09738a9f6 6e02ff97b58c4394bc7d4dbdcff0e08a RY(theta₁₄) 90ffbbd1285d4462ae6bb9b09738a9f6--6e02ff97b58c4394bc7d4dbdcff0e08a 418b29fb64404abfb2446a02321ad51c RX(theta₁₇) 6e02ff97b58c4394bc7d4dbdcff0e08a--418b29fb64404abfb2446a02321ad51c 99654d75d07f4efc83216ab4caea031c 418b29fb64404abfb2446a02321ad51c--99654d75d07f4efc83216ab4caea031c ef6a633a78e84d108e0071d24bac9eb8 X 99654d75d07f4efc83216ab4caea031c--ef6a633a78e84d108e0071d24bac9eb8 ef6a633a78e84d108e0071d24bac9eb8--97d820c615074f0e850497d38d373d73 ab8e64e75a5c4203b5ecc1f1a1bde37b ef6a633a78e84d108e0071d24bac9eb8--ab8e64e75a5c4203b5ecc1f1a1bde37b ab8e64e75a5c4203b5ecc1f1a1bde37b--5aee1d95e9834e239d121c02c5dc0aad
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 45b9f007b4b54072b7c70513be7e43d4 0 64978d03eca443a2ab579eb19154cdc8 45b9f007b4b54072b7c70513be7e43d4--64978d03eca443a2ab579eb19154cdc8 167b05efc5b64fc88f8857ba5590552e 1 065aca1b33124146b4757fa582a9a545 c55651740d36470f80d79d111fa5c898 64978d03eca443a2ab579eb19154cdc8--c55651740d36470f80d79d111fa5c898 1c375f39b61a4ef790ce9bd7fca4b490 065aca1b33124146b4757fa582a9a545--1c375f39b61a4ef790ce9bd7fca4b490 f74999178f904c84a4314e96f3f65f8d 84af8e244986465eb5d03c32f343cb30 1c375f39b61a4ef790ce9bd7fca4b490--84af8e244986465eb5d03c32f343cb30 fd526f9e94204b5ea05c39cfb83d6d76 f74999178f904c84a4314e96f3f65f8d--fd526f9e94204b5ea05c39cfb83d6d76 c8f3ca43854241df9004d4f5f30f2780 25e8fac107054488a8c0f9f0ba44c526 167b05efc5b64fc88f8857ba5590552e--25e8fac107054488a8c0f9f0ba44c526 22621302f45b477a91789857cd14b8fb 2 25e8fac107054488a8c0f9f0ba44c526--065aca1b33124146b4757fa582a9a545 ff74fe3d283a451ba2155729f5db82ca c55651740d36470f80d79d111fa5c898--ff74fe3d283a451ba2155729f5db82ca 089cd4cdeccc4bb8ab4fb74efd3ce197 ff74fe3d283a451ba2155729f5db82ca--089cd4cdeccc4bb8ab4fb74efd3ce197 089cd4cdeccc4bb8ab4fb74efd3ce197--c8f3ca43854241df9004d4f5f30f2780 ab17b4aad65b41ce82baf3cee1386a64 37eafee0e7ef497aac69450203c028fe 22621302f45b477a91789857cd14b8fb--37eafee0e7ef497aac69450203c028fe 117b56ec4e3d467eabe283c6642e2227 3 1dbd3447ff9d4ff2bec85bd31e8dbc27 37eafee0e7ef497aac69450203c028fe--1dbd3447ff9d4ff2bec85bd31e8dbc27 8c7818c6608a42b99ce10fab6f6b5df0 1dbd3447ff9d4ff2bec85bd31e8dbc27--8c7818c6608a42b99ce10fab6f6b5df0 221e426ecfd6422999fb7a612be4beca 8c7818c6608a42b99ce10fab6f6b5df0--221e426ecfd6422999fb7a612be4beca 221e426ecfd6422999fb7a612be4beca--ab17b4aad65b41ce82baf3cee1386a64 2bdc389855d14309a62fa65dacc2eeb3 bc1ac29981db45ada8f3031af1bd31df 117b56ec4e3d467eabe283c6642e2227--bc1ac29981db45ada8f3031af1bd31df 33b0c5dd91114130a9467fda2285c790 bc1ac29981db45ada8f3031af1bd31df--33b0c5dd91114130a9467fda2285c790 d14a85b521094d31ac03c61b22b68c1b 33b0c5dd91114130a9467fda2285c790--d14a85b521094d31ac03c61b22b68c1b d14a85b521094d31ac03c61b22b68c1b--f74999178f904c84a4314e96f3f65f8d 84af8e244986465eb5d03c32f343cb30--2bdc389855d14309a62fa65dacc2eeb3
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 da006866cb554b6cba5b006fc0dd25f6 0 640aeae8aef049ebb5b6e44812c5f67d da006866cb554b6cba5b006fc0dd25f6--640aeae8aef049ebb5b6e44812c5f67d 917a7d8856414cd0ac9b77cae007b56a 1 a817e934018946909cc3335711e9a738 640aeae8aef049ebb5b6e44812c5f67d--a817e934018946909cc3335711e9a738 fe60bbc221c348679449ecb729482ba6 a817e934018946909cc3335711e9a738--fe60bbc221c348679449ecb729482ba6 f7e5df80a69c4c09afd7569f46dd4dbb fe60bbc221c348679449ecb729482ba6--f7e5df80a69c4c09afd7569f46dd4dbb d221122a4f7243e6a893f4113be35023 9567c00d2ddc40f685590a41075953ef PHASE(0.5) 917a7d8856414cd0ac9b77cae007b56a--9567c00d2ddc40f685590a41075953ef e03dceef58e6460eb024c3c59086d3e4 2 9567c00d2ddc40f685590a41075953ef--640aeae8aef049ebb5b6e44812c5f67d af9af44380c54f89a94926f5e789b3f6 9567c00d2ddc40f685590a41075953ef--af9af44380c54f89a94926f5e789b3f6 ef969e292f3a48bea33df38a18dcfe0c af9af44380c54f89a94926f5e789b3f6--ef969e292f3a48bea33df38a18dcfe0c ef969e292f3a48bea33df38a18dcfe0c--d221122a4f7243e6a893f4113be35023 4ccb7ac91fd246fd9da9604651bc6f24 e77fc1bc717f4752897004b214b904a9 e03dceef58e6460eb024c3c59086d3e4--e77fc1bc717f4752897004b214b904a9 d514918c4e434fa6b72af793b2d99458 3 222692936cce4343b3e6dacb544bc740 PHASE(0.5) e77fc1bc717f4752897004b214b904a9--222692936cce4343b3e6dacb544bc740 222692936cce4343b3e6dacb544bc740--a817e934018946909cc3335711e9a738 d695c4208bc446d49b2acf3aef600be9 222692936cce4343b3e6dacb544bc740--d695c4208bc446d49b2acf3aef600be9 d695c4208bc446d49b2acf3aef600be9--4ccb7ac91fd246fd9da9604651bc6f24 9d2bf44afa48474eb7f485ee6b311964 ce7cfec8836c4115b75b96fc10195f24 d514918c4e434fa6b72af793b2d99458--ce7cfec8836c4115b75b96fc10195f24 f284087e699246d6bd07fb66d61de5ed ce7cfec8836c4115b75b96fc10195f24--f284087e699246d6bd07fb66d61de5ed 59d2c8795f854af6aace5cbb84c5137f PHASE(0.5) f284087e699246d6bd07fb66d61de5ed--59d2c8795f854af6aace5cbb84c5137f 59d2c8795f854af6aace5cbb84c5137f--fe60bbc221c348679449ecb729482ba6 59d2c8795f854af6aace5cbb84c5137f--9d2bf44afa48474eb7f485ee6b311964

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