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 3f3e152e900e4a57984a28763aa38882 0 89a298b9623c46899543b3c8c1fb4708 X 3f3e152e900e4a57984a28763aa38882--89a298b9623c46899543b3c8c1fb4708 2f359d9bc5634ed4a51bf9acf3c58ba6 1 2746717bb51244999512370ad249af57 89a298b9623c46899543b3c8c1fb4708--2746717bb51244999512370ad249af57 cff9b9176860415cbf1bb0c24229258d 4a478781398341349994167dae282439 Y 2f359d9bc5634ed4a51bf9acf3c58ba6--4a478781398341349994167dae282439 4a478781398341349994167dae282439--cff9b9176860415cbf1bb0c24229258d
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 528e51c68f454ef3a3773bcd267cc614 0 014e3ffc93c341cb832dd94b4bb04102 X 528e51c68f454ef3a3773bcd267cc614--014e3ffc93c341cb832dd94b4bb04102 1190c030ee884fbaab0345bdcaefdc27 Y 014e3ffc93c341cb832dd94b4bb04102--1190c030ee884fbaab0345bdcaefdc27 e05e269d994c45b0a3f56153d3e20aff 1190c030ee884fbaab0345bdcaefdc27--e05e269d994c45b0a3f56153d3e20aff
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 2f356bf71ff94ba592a9290cbe006668 0 f79a783346074fe5a148e522ce422bab X 2f356bf71ff94ba592a9290cbe006668--f79a783346074fe5a148e522ce422bab 58e9628a3d4c4f8780acd0ae304d604c 1 9473a41b6c5546ceb4f344eb13aa5998 f79a783346074fe5a148e522ce422bab--9473a41b6c5546ceb4f344eb13aa5998 51938cebae644df5b080736b7d79f5fe 9473a41b6c5546ceb4f344eb13aa5998--51938cebae644df5b080736b7d79f5fe 346ba73f21df4a6eab3695a948d39bc9 d3fa843eb57446a3bb4e9e604774ee83 58e9628a3d4c4f8780acd0ae304d604c--d3fa843eb57446a3bb4e9e604774ee83 d79303df949d47e4b42037b0bf647562 Y d3fa843eb57446a3bb4e9e604774ee83--d79303df949d47e4b42037b0bf647562 d79303df949d47e4b42037b0bf647562--346ba73f21df4a6eab3695a948d39bc9
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_b08b3cd193fa4e3e86e3116d0d45e07e 6c5742cc618145dbba8647e964a3701e 0 06782b934cb64d868f14f0defeecb186 6c5742cc618145dbba8647e964a3701e--06782b934cb64d868f14f0defeecb186 7dfb210a7eb24988838b2482ce71b586 1 868c09c2e4ef48cf8a09684f9968c5bd 06782b934cb64d868f14f0defeecb186--868c09c2e4ef48cf8a09684f9968c5bd 68e31765ea17402aa5f112bd27f707eb 298f2cbc3dc145169a3f905ab2f3f3a5 AddBlock 7dfb210a7eb24988838b2482ce71b586--298f2cbc3dc145169a3f905ab2f3f3a5 754bf688086641908a9de15fc82b1b74 2 298f2cbc3dc145169a3f905ab2f3f3a5--68e31765ea17402aa5f112bd27f707eb 438af0d67beb4756879a5d37c6cbf357 ac1b5517024047e09bc43dccc2f58fa8 754bf688086641908a9de15fc82b1b74--ac1b5517024047e09bc43dccc2f58fa8 ac1b5517024047e09bc43dccc2f58fa8--438af0d67beb4756879a5d37c6cbf357
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_2845bb2301484fe2a5ed687af819b544 cluster_b03cf52b677f4ea6a7071b332a8be5e4 rx e99656b7f3334e71b54a39b3a235056b 0 43f5af2f5e52430796997a94267ea305 X e99656b7f3334e71b54a39b3a235056b--43f5af2f5e52430796997a94267ea305 b8ccf636c21540c88a1da0ca7b62b320 1 f61f9914c8294e3ebd29241295fd082d 43f5af2f5e52430796997a94267ea305--f61f9914c8294e3ebd29241295fd082d cc95577eba944485805d12f0eaedb964 f61f9914c8294e3ebd29241295fd082d--cc95577eba944485805d12f0eaedb964 faf3535d4260442386321e317ae61988 cc95577eba944485805d12f0eaedb964--faf3535d4260442386321e317ae61988 df06953d15734903bd7a1f05027d8f4c a15fa5bdeb9347e1914e221448d2f84d Y b8ccf636c21540c88a1da0ca7b62b320--a15fa5bdeb9347e1914e221448d2f84d ff17bae874694fcc8eddd01f423eb0b3 2 06995d895e114638aa711168f07ecea7 a15fa5bdeb9347e1914e221448d2f84d--06995d895e114638aa711168f07ecea7 b9ed6ba7156f453192bd8fb00292dd45 HamEvo 06995d895e114638aa711168f07ecea7--b9ed6ba7156f453192bd8fb00292dd45 b9ed6ba7156f453192bd8fb00292dd45--df06953d15734903bd7a1f05027d8f4c dd66111fbb234b4398b8c4929f6f71b4 5639c424dfcf4eefa56f5b0a1bf50a5e RX(x) ff17bae874694fcc8eddd01f423eb0b3--5639c424dfcf4eefa56f5b0a1bf50a5e 07fd1bef357145e48cd37dc7f992db4a 3 66038b30ef4a4ce18be8711bd3744625 5639c424dfcf4eefa56f5b0a1bf50a5e--66038b30ef4a4ce18be8711bd3744625 8a9a1088f45e48a98671d2f25ff61bc5 t = 10 66038b30ef4a4ce18be8711bd3744625--8a9a1088f45e48a98671d2f25ff61bc5 8a9a1088f45e48a98671d2f25ff61bc5--dd66111fbb234b4398b8c4929f6f71b4 cf16241893f04676a4d87159ce2a546a 3ecbebb6be2042a28355d0d0d56ba4be RX(0.5) 07fd1bef357145e48cd37dc7f992db4a--3ecbebb6be2042a28355d0d0d56ba4be 254ba747d5004713a31f75699a7662a9 X 3ecbebb6be2042a28355d0d0d56ba4be--254ba747d5004713a31f75699a7662a9 254ba747d5004713a31f75699a7662a9--66038b30ef4a4ce18be8711bd3744625 531cf2e44e6d45bc97b244ee08783e3f 254ba747d5004713a31f75699a7662a9--531cf2e44e6d45bc97b244ee08783e3f 531cf2e44e6d45bc97b244ee08783e3f--cf16241893f04676a4d87159ce2a546a
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_094a9c65934842cdb359c354d600f0ea HEA cluster_4c7c042c44084328b96b594cedff7195 Tower Fourier FM debde932aa6c4ccdb0c97c2750865bda 0 425d442db417436782dee3a877f73926 RX(1.0*phi) debde932aa6c4ccdb0c97c2750865bda--425d442db417436782dee3a877f73926 e057c42e305c41c296a3af02c559015c 1 d506811d86364c79a6540e60eb3efc85 RX(theta₀) 425d442db417436782dee3a877f73926--d506811d86364c79a6540e60eb3efc85 02fd74edc6d74ddb9fae8696baa98516 RY(theta₄) d506811d86364c79a6540e60eb3efc85--02fd74edc6d74ddb9fae8696baa98516 b4f49ddc75124a5698293a834e4e1e70 RX(theta₈) 02fd74edc6d74ddb9fae8696baa98516--b4f49ddc75124a5698293a834e4e1e70 b679ffcd9efb47f28bb850212c22fbbe b4f49ddc75124a5698293a834e4e1e70--b679ffcd9efb47f28bb850212c22fbbe 2c2048a700994623ac20728aabcd0e1c b679ffcd9efb47f28bb850212c22fbbe--2c2048a700994623ac20728aabcd0e1c 3de1490ca68744fda6c1ae2f87029c90 RX(theta₁₂) 2c2048a700994623ac20728aabcd0e1c--3de1490ca68744fda6c1ae2f87029c90 f491ee418f2741ff9ac55c6e92639b09 RY(theta₁₆) 3de1490ca68744fda6c1ae2f87029c90--f491ee418f2741ff9ac55c6e92639b09 550db8be56c44d798a7a415d09a712e5 RX(theta₂₀) f491ee418f2741ff9ac55c6e92639b09--550db8be56c44d798a7a415d09a712e5 da4954a215d245b8ad4f9b63c5440b91 550db8be56c44d798a7a415d09a712e5--da4954a215d245b8ad4f9b63c5440b91 96a912f67fc64569b898ebdcc4a39726 da4954a215d245b8ad4f9b63c5440b91--96a912f67fc64569b898ebdcc4a39726 a80b3f8b2c1b4571810a30f3fc76ccd5 96a912f67fc64569b898ebdcc4a39726--a80b3f8b2c1b4571810a30f3fc76ccd5 8e65e2b62dc7401b81121d51536ed45f cffacc20a434434986ed8d1e16ae9301 RX(2.0*phi) e057c42e305c41c296a3af02c559015c--cffacc20a434434986ed8d1e16ae9301 0b86579e96b14a198bf747db2cc036ed 2 499e77f3d126438fa42f2b434c3fd615 RX(theta₁) cffacc20a434434986ed8d1e16ae9301--499e77f3d126438fa42f2b434c3fd615 e2f6d9c141514a22a9e5f374e80c0ff4 RY(theta₅) 499e77f3d126438fa42f2b434c3fd615--e2f6d9c141514a22a9e5f374e80c0ff4 a45e31b2d69143ff8d9be6eb30f552b3 RX(theta₉) e2f6d9c141514a22a9e5f374e80c0ff4--a45e31b2d69143ff8d9be6eb30f552b3 0d9ba9e15a9c4c50a549a6ca37f88f8a X a45e31b2d69143ff8d9be6eb30f552b3--0d9ba9e15a9c4c50a549a6ca37f88f8a 0d9ba9e15a9c4c50a549a6ca37f88f8a--b679ffcd9efb47f28bb850212c22fbbe 3ced04d9317d4b40a26a8ce10181dc69 0d9ba9e15a9c4c50a549a6ca37f88f8a--3ced04d9317d4b40a26a8ce10181dc69 f65cb685d18d4589a54f9bafaa003b49 RX(theta₁₃) 3ced04d9317d4b40a26a8ce10181dc69--f65cb685d18d4589a54f9bafaa003b49 8cebbaa3f8c843cd9f8a54d24f93bb4b RY(theta₁₇) f65cb685d18d4589a54f9bafaa003b49--8cebbaa3f8c843cd9f8a54d24f93bb4b d76f62f1b8b646b69b783c4cb7cedc6e RX(theta₂₁) 8cebbaa3f8c843cd9f8a54d24f93bb4b--d76f62f1b8b646b69b783c4cb7cedc6e 565d41654abf40e39cb22a40381b09dc X d76f62f1b8b646b69b783c4cb7cedc6e--565d41654abf40e39cb22a40381b09dc 565d41654abf40e39cb22a40381b09dc--da4954a215d245b8ad4f9b63c5440b91 65f6e32274e043ea9899bf70e042b201 565d41654abf40e39cb22a40381b09dc--65f6e32274e043ea9899bf70e042b201 65f6e32274e043ea9899bf70e042b201--8e65e2b62dc7401b81121d51536ed45f a8b7b117c4fc4699a51a6adbb312807f 1e26b1a03ee342b98e2ae4134d0d5c56 RX(3.0*phi) 0b86579e96b14a198bf747db2cc036ed--1e26b1a03ee342b98e2ae4134d0d5c56 7517c80b088b43459befa1d09c4e9da2 3 f2ccbae80f9b49d19fb6eee03fc8cf6d RX(theta₂) 1e26b1a03ee342b98e2ae4134d0d5c56--f2ccbae80f9b49d19fb6eee03fc8cf6d 7cefa77ddc464ab397fb075d78e5f171 RY(theta₆) f2ccbae80f9b49d19fb6eee03fc8cf6d--7cefa77ddc464ab397fb075d78e5f171 65980f7639ec46b796ec4185f1c36df5 RX(theta₁₀) 7cefa77ddc464ab397fb075d78e5f171--65980f7639ec46b796ec4185f1c36df5 7831071859d74fd587100e5d0206aa48 65980f7639ec46b796ec4185f1c36df5--7831071859d74fd587100e5d0206aa48 d81201d62dc547fdb70a4060d275b445 X 7831071859d74fd587100e5d0206aa48--d81201d62dc547fdb70a4060d275b445 d81201d62dc547fdb70a4060d275b445--3ced04d9317d4b40a26a8ce10181dc69 655c0ef301f2447c8521b1a21d15d77b RX(theta₁₄) d81201d62dc547fdb70a4060d275b445--655c0ef301f2447c8521b1a21d15d77b 46a453f025144856b45a7d40633ab47e RY(theta₁₈) 655c0ef301f2447c8521b1a21d15d77b--46a453f025144856b45a7d40633ab47e b56a981e4b9241ec85823e2ba31f252d RX(theta₂₂) 46a453f025144856b45a7d40633ab47e--b56a981e4b9241ec85823e2ba31f252d eed8eda01ce84483a200c2df5d997e6e b56a981e4b9241ec85823e2ba31f252d--eed8eda01ce84483a200c2df5d997e6e 7489b306dfe8444d8b8dc3c8375d6314 X eed8eda01ce84483a200c2df5d997e6e--7489b306dfe8444d8b8dc3c8375d6314 7489b306dfe8444d8b8dc3c8375d6314--65f6e32274e043ea9899bf70e042b201 7489b306dfe8444d8b8dc3c8375d6314--a8b7b117c4fc4699a51a6adbb312807f b2e4294486ce42b989067f493cb791aa 4969b0ad34174c33958a3b91910a395a RX(4.0*phi) 7517c80b088b43459befa1d09c4e9da2--4969b0ad34174c33958a3b91910a395a b6aae2e0a0024ea7bf10738d969c56f3 RX(theta₃) 4969b0ad34174c33958a3b91910a395a--b6aae2e0a0024ea7bf10738d969c56f3 dd602e9c14d045e698ade69518401e1d RY(theta₇) b6aae2e0a0024ea7bf10738d969c56f3--dd602e9c14d045e698ade69518401e1d 9525aa6f4a574228a448b99d3cb89a17 RX(theta₁₁) dd602e9c14d045e698ade69518401e1d--9525aa6f4a574228a448b99d3cb89a17 a3600ec6ad154f8794f27e6a37e32435 X 9525aa6f4a574228a448b99d3cb89a17--a3600ec6ad154f8794f27e6a37e32435 a3600ec6ad154f8794f27e6a37e32435--7831071859d74fd587100e5d0206aa48 dc094860870444dfa352dce3925daead a3600ec6ad154f8794f27e6a37e32435--dc094860870444dfa352dce3925daead dbc8b0fe5ea8448db6a58f690f152ff0 RX(theta₁₅) dc094860870444dfa352dce3925daead--dbc8b0fe5ea8448db6a58f690f152ff0 101e3c2eec0142528f28ab474b62f275 RY(theta₁₉) dbc8b0fe5ea8448db6a58f690f152ff0--101e3c2eec0142528f28ab474b62f275 3da34cc3e36c46038cf3e923283e3d22 RX(theta₂₃) 101e3c2eec0142528f28ab474b62f275--3da34cc3e36c46038cf3e923283e3d22 72e99116d6844dfbb56a75397f28876d X 3da34cc3e36c46038cf3e923283e3d22--72e99116d6844dfbb56a75397f28876d 72e99116d6844dfbb56a75397f28876d--eed8eda01ce84483a200c2df5d997e6e e7f30dd07f5045dea1173e2a3168d8c7 72e99116d6844dfbb56a75397f28876d--e7f30dd07f5045dea1173e2a3168d8c7 e7f30dd07f5045dea1173e2a3168d8c7--b2e4294486ce42b989067f493cb791aa
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_b560c46d018a4332bf6c9c1e0b6ee5f7 Obs. cluster_ec7e385787c5466190baa0520ea33e11 cluster_93e604058d2443fbb41be7e5c7e28282 HEA fd4df4ac521f43818230c4fb9f9951f6 0 d1f021faa8b34774badf986194d65256 RX(theta₀) fd4df4ac521f43818230c4fb9f9951f6--d1f021faa8b34774badf986194d65256 3142b7d03dae46b39538ae0e2a12a40f 1 f3f098160e054c65b08ffbe253b9b4c3 RY(theta₃) d1f021faa8b34774badf986194d65256--f3f098160e054c65b08ffbe253b9b4c3 5791e475cb384a26811ceb7ca62ad1d0 RX(theta₆) f3f098160e054c65b08ffbe253b9b4c3--5791e475cb384a26811ceb7ca62ad1d0 7d4e76556d514334a36f4f595ce0f15c 5791e475cb384a26811ceb7ca62ad1d0--7d4e76556d514334a36f4f595ce0f15c 41fe5383843848469bd1b9f300a4f91c 7d4e76556d514334a36f4f595ce0f15c--41fe5383843848469bd1b9f300a4f91c d3881ad025aa45a898c07eb5adfb6848 RX(theta₉) 41fe5383843848469bd1b9f300a4f91c--d3881ad025aa45a898c07eb5adfb6848 2e5ca6ffe4594944be1816d135a76092 RY(theta₁₂) d3881ad025aa45a898c07eb5adfb6848--2e5ca6ffe4594944be1816d135a76092 1875eaad076b4e03a8706908bd5a3b36 RX(theta₁₅) 2e5ca6ffe4594944be1816d135a76092--1875eaad076b4e03a8706908bd5a3b36 e6c44558c2a24821ba3eee0b7ce73b06 1875eaad076b4e03a8706908bd5a3b36--e6c44558c2a24821ba3eee0b7ce73b06 93301c8306554deea6800c4d7bcd21b6 e6c44558c2a24821ba3eee0b7ce73b06--93301c8306554deea6800c4d7bcd21b6 f65f484c5ebb45acab9c4008826c397a 93301c8306554deea6800c4d7bcd21b6--f65f484c5ebb45acab9c4008826c397a e810584a64da4204b13dcc1ab7c81c42 f65f484c5ebb45acab9c4008826c397a--e810584a64da4204b13dcc1ab7c81c42 ad6110142e474d5485ce3d4b0ae43363 0f2e0eaddb074d86b96905ad41847c32 RX(theta₁) 3142b7d03dae46b39538ae0e2a12a40f--0f2e0eaddb074d86b96905ad41847c32 f99e2de33b0049f7b99b1c8cfb49277f 2 cd1d23fd38d6407a9e43856a9d77c76a RY(theta₄) 0f2e0eaddb074d86b96905ad41847c32--cd1d23fd38d6407a9e43856a9d77c76a c702bc7ebf13495d9db0dd24ca7b92f1 RX(theta₇) cd1d23fd38d6407a9e43856a9d77c76a--c702bc7ebf13495d9db0dd24ca7b92f1 b6ab5014a0114b1a99c6070c819ee82e X c702bc7ebf13495d9db0dd24ca7b92f1--b6ab5014a0114b1a99c6070c819ee82e b6ab5014a0114b1a99c6070c819ee82e--7d4e76556d514334a36f4f595ce0f15c 057457e337cc45bbae5ce129ce2793ca b6ab5014a0114b1a99c6070c819ee82e--057457e337cc45bbae5ce129ce2793ca 489bbb0f8fbe4ea2aa32ae861e97b5ba RX(theta₁₀) 057457e337cc45bbae5ce129ce2793ca--489bbb0f8fbe4ea2aa32ae861e97b5ba 87fe4f668dc442d7ac66e6944e92b5e0 RY(theta₁₃) 489bbb0f8fbe4ea2aa32ae861e97b5ba--87fe4f668dc442d7ac66e6944e92b5e0 1092c79cceab4e12ace8271e4e8acf46 RX(theta₁₆) 87fe4f668dc442d7ac66e6944e92b5e0--1092c79cceab4e12ace8271e4e8acf46 dad648ede2384d92898f0cba6842f226 X 1092c79cceab4e12ace8271e4e8acf46--dad648ede2384d92898f0cba6842f226 dad648ede2384d92898f0cba6842f226--e6c44558c2a24821ba3eee0b7ce73b06 51f6db3fac924983b0ddf69c125c9c35 dad648ede2384d92898f0cba6842f226--51f6db3fac924983b0ddf69c125c9c35 3dc48e6b75c54bae9717a02c1ace5088 AddBlock 51f6db3fac924983b0ddf69c125c9c35--3dc48e6b75c54bae9717a02c1ace5088 3dc48e6b75c54bae9717a02c1ace5088--ad6110142e474d5485ce3d4b0ae43363 7a33248b5550405f80b0fcb7a4c366d0 6153a77daf04496c87b9d9090be3a7d9 RX(theta₂) f99e2de33b0049f7b99b1c8cfb49277f--6153a77daf04496c87b9d9090be3a7d9 080befcfdbe74f8681da6158873e56e2 RY(theta₅) 6153a77daf04496c87b9d9090be3a7d9--080befcfdbe74f8681da6158873e56e2 d714cd99178d4385b142f4e231247b16 RX(theta₈) 080befcfdbe74f8681da6158873e56e2--d714cd99178d4385b142f4e231247b16 6a0c206dc6f14448a4f4263bc4a44eaa d714cd99178d4385b142f4e231247b16--6a0c206dc6f14448a4f4263bc4a44eaa 1b5b710ff65b4fc08ea3e30351e585dd X 6a0c206dc6f14448a4f4263bc4a44eaa--1b5b710ff65b4fc08ea3e30351e585dd 1b5b710ff65b4fc08ea3e30351e585dd--057457e337cc45bbae5ce129ce2793ca 0fae7d5e35b141279439062cdc523449 RX(theta₁₁) 1b5b710ff65b4fc08ea3e30351e585dd--0fae7d5e35b141279439062cdc523449 9146c9f1cd8b4b95b2ade70a54811c25 RY(theta₁₄) 0fae7d5e35b141279439062cdc523449--9146c9f1cd8b4b95b2ade70a54811c25 cedb3b441a2f499793863cb8eb8fd66b RX(theta₁₇) 9146c9f1cd8b4b95b2ade70a54811c25--cedb3b441a2f499793863cb8eb8fd66b 12b5b6c9d9ee41a581599d3b1d8d4e91 cedb3b441a2f499793863cb8eb8fd66b--12b5b6c9d9ee41a581599d3b1d8d4e91 8b32da246cec4711b4110a50c4418f4a X 12b5b6c9d9ee41a581599d3b1d8d4e91--8b32da246cec4711b4110a50c4418f4a 8b32da246cec4711b4110a50c4418f4a--51f6db3fac924983b0ddf69c125c9c35 d14e551779ef41af87e36f5cf829a414 8b32da246cec4711b4110a50c4418f4a--d14e551779ef41af87e36f5cf829a414 d14e551779ef41af87e36f5cf829a414--7a33248b5550405f80b0fcb7a4c366d0
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 60458896f8124b89a614574fa5dd7488 0 5cf2558ae3b94879b8920d7d12f41763 60458896f8124b89a614574fa5dd7488--5cf2558ae3b94879b8920d7d12f41763 b8e9049a911f4a048084a12b560b7728 1 004a12c86648473aaa3d9af6771d0cee 0873016260d04d85bd028e1aff921827 5cf2558ae3b94879b8920d7d12f41763--0873016260d04d85bd028e1aff921827 ad8a2c4ddfe1494ca2876729e8d758ed 004a12c86648473aaa3d9af6771d0cee--ad8a2c4ddfe1494ca2876729e8d758ed bd750f94ce844b4db5daa23a92169881 ca7808299cbc49e79eb5b55f88c07e6c ad8a2c4ddfe1494ca2876729e8d758ed--ca7808299cbc49e79eb5b55f88c07e6c 4a3224b738f043bea784b6325ded00e1 bd750f94ce844b4db5daa23a92169881--4a3224b738f043bea784b6325ded00e1 39a6e93ab482413e8d241a64b843f6b6 50c02433e91046308d2de9f3b19193f7 b8e9049a911f4a048084a12b560b7728--50c02433e91046308d2de9f3b19193f7 9d2fb63406014bcab23c275433ef9fb5 2 50c02433e91046308d2de9f3b19193f7--004a12c86648473aaa3d9af6771d0cee 4564a22e56414d08ba0a9760ff1c7fb9 0873016260d04d85bd028e1aff921827--4564a22e56414d08ba0a9760ff1c7fb9 5cd2335c1d32405e9ac4553833a759b7 4564a22e56414d08ba0a9760ff1c7fb9--5cd2335c1d32405e9ac4553833a759b7 5cd2335c1d32405e9ac4553833a759b7--39a6e93ab482413e8d241a64b843f6b6 a75b76ac43b94cfea16c41912de88c11 b4e9cd88570d4ef085d920268d29171f 9d2fb63406014bcab23c275433ef9fb5--b4e9cd88570d4ef085d920268d29171f fc666a2031f44abb9116a9126e983126 3 f59232150ac14a15813812e46807eddd b4e9cd88570d4ef085d920268d29171f--f59232150ac14a15813812e46807eddd 17de66a234594e4c86c6c52cebb6e41e f59232150ac14a15813812e46807eddd--17de66a234594e4c86c6c52cebb6e41e 0cc6b29b33f84c0b899b1cc24ac263c3 17de66a234594e4c86c6c52cebb6e41e--0cc6b29b33f84c0b899b1cc24ac263c3 0cc6b29b33f84c0b899b1cc24ac263c3--a75b76ac43b94cfea16c41912de88c11 2fc104a4b3324b14b5c80e6cc6db64e6 f7ed80b535a04ea6a57d6adbfcda52e6 fc666a2031f44abb9116a9126e983126--f7ed80b535a04ea6a57d6adbfcda52e6 da23ee672d9f48efbbe3e9ae01758489 f7ed80b535a04ea6a57d6adbfcda52e6--da23ee672d9f48efbbe3e9ae01758489 493ef6c131e74f7ca7468ff4b73438df da23ee672d9f48efbbe3e9ae01758489--493ef6c131e74f7ca7468ff4b73438df 493ef6c131e74f7ca7468ff4b73438df--bd750f94ce844b4db5daa23a92169881 ca7808299cbc49e79eb5b55f88c07e6c--2fc104a4b3324b14b5c80e6cc6db64e6
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 db83b04e9f804b8da6f094c109717654 0 0fc499ea7c50474dab6a5728fcaa195f db83b04e9f804b8da6f094c109717654--0fc499ea7c50474dab6a5728fcaa195f 1700dbdfeb7942e289e3f91e2b21e6ee 1 dc2c3d8a96da42a480e6f3c41dd1b9cc 0fc499ea7c50474dab6a5728fcaa195f--dc2c3d8a96da42a480e6f3c41dd1b9cc b370f919700e4276b346117e4d0a20d0 dc2c3d8a96da42a480e6f3c41dd1b9cc--b370f919700e4276b346117e4d0a20d0 2c9d0af7b42e4b0fa843478cd57563a1 b370f919700e4276b346117e4d0a20d0--2c9d0af7b42e4b0fa843478cd57563a1 5b883a6fad074f4c8bb054b522e389a4 145cb2a963514d8193b261e6fab163a9 PHASE(0.5) 1700dbdfeb7942e289e3f91e2b21e6ee--145cb2a963514d8193b261e6fab163a9 9d496d6dc1a841d390a73765a2767bc7 2 145cb2a963514d8193b261e6fab163a9--0fc499ea7c50474dab6a5728fcaa195f ea7c96f01d1947019430d73fa1a52468 145cb2a963514d8193b261e6fab163a9--ea7c96f01d1947019430d73fa1a52468 d6ed1a3bbfec4fc28c5b33bdced750c3 ea7c96f01d1947019430d73fa1a52468--d6ed1a3bbfec4fc28c5b33bdced750c3 d6ed1a3bbfec4fc28c5b33bdced750c3--5b883a6fad074f4c8bb054b522e389a4 01b8ecf5a411464db7e5718ae886d1eb e24a1251d8334fa587fc28863ef50c0b 9d496d6dc1a841d390a73765a2767bc7--e24a1251d8334fa587fc28863ef50c0b 65a1c3e131184f80bae17a78a62a6457 3 11cc3e9ec01c4d3e8e26ed1c4e559932 PHASE(0.5) e24a1251d8334fa587fc28863ef50c0b--11cc3e9ec01c4d3e8e26ed1c4e559932 11cc3e9ec01c4d3e8e26ed1c4e559932--dc2c3d8a96da42a480e6f3c41dd1b9cc f9b4763884de420ea271d574458f0b72 11cc3e9ec01c4d3e8e26ed1c4e559932--f9b4763884de420ea271d574458f0b72 f9b4763884de420ea271d574458f0b72--01b8ecf5a411464db7e5718ae886d1eb 98f3c8e9718d4341b0921af43f48da59 e55b8fdb92e641888eb8277fb67cce5f 65a1c3e131184f80bae17a78a62a6457--e55b8fdb92e641888eb8277fb67cce5f 6782e46c8d2f45449b24f678e523839a e55b8fdb92e641888eb8277fb67cce5f--6782e46c8d2f45449b24f678e523839a 7fd9ebbd9bf14c829eb7e6aa7fb5bc0f PHASE(0.5) 6782e46c8d2f45449b24f678e523839a--7fd9ebbd9bf14c829eb7e6aa7fb5bc0f 7fd9ebbd9bf14c829eb7e6aa7fb5bc0f--b370f919700e4276b346117e4d0a20d0 7fd9ebbd9bf14c829eb7e6aa7fb5bc0f--98f3c8e9718d4341b0921af43f48da59

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