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 1a7764fb65ec477dbc3f19187b323b71 0 dc3f4dfacd6244899bd3a8f5892af80d X 1a7764fb65ec477dbc3f19187b323b71--dc3f4dfacd6244899bd3a8f5892af80d 154d0e6ae7374118978c4c7a1eb801d8 1 f6e8b7345a5b4f94a41a7821d6e1cb36 dc3f4dfacd6244899bd3a8f5892af80d--f6e8b7345a5b4f94a41a7821d6e1cb36 0b90990365694e82937df77d8b7a999a da7dea2e0da644a581c06992081a1c9d Y 154d0e6ae7374118978c4c7a1eb801d8--da7dea2e0da644a581c06992081a1c9d da7dea2e0da644a581c06992081a1c9d--0b90990365694e82937df77d8b7a999a
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 dbb570222c5b4d8f804abf5045536b8b 0 a7b12a0d154a411eaed8a0558600df62 X dbb570222c5b4d8f804abf5045536b8b--a7b12a0d154a411eaed8a0558600df62 026f3c26f38e45c6987616d3325dbee3 Y a7b12a0d154a411eaed8a0558600df62--026f3c26f38e45c6987616d3325dbee3 692248bf988540bba6e9e123df60b4a4 026f3c26f38e45c6987616d3325dbee3--692248bf988540bba6e9e123df60b4a4
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 632095763647483889d91503be5f61c4 0 c2c2e98923024ac0a6ff71ac68d01bad X 632095763647483889d91503be5f61c4--c2c2e98923024ac0a6ff71ac68d01bad 4b0a7223d5964126a2706204802a19a2 1 511d86063d0441dfbfe0379775bb67a6 c2c2e98923024ac0a6ff71ac68d01bad--511d86063d0441dfbfe0379775bb67a6 c87e1133f8084bb38e9a757a00263d7f 511d86063d0441dfbfe0379775bb67a6--c87e1133f8084bb38e9a757a00263d7f a590bf668f8f46d389768822e1da88ad 3c865970f8db4e9686800333922246ca 4b0a7223d5964126a2706204802a19a2--3c865970f8db4e9686800333922246ca d3b321b931f84975b10e48bdfaeab634 Y 3c865970f8db4e9686800333922246ca--d3b321b931f84975b10e48bdfaeab634 d3b321b931f84975b10e48bdfaeab634--a590bf668f8f46d389768822e1da88ad
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_35b3f89ddfb440caad9578d943d71cf0 33e63e710f0b4ce2890eafd56757b2b9 0 bdbb34ed714d4210bf90678d4bd55dad 33e63e710f0b4ce2890eafd56757b2b9--bdbb34ed714d4210bf90678d4bd55dad 08f05e1284304b29b0781f96b3c9c3f6 1 2850d4d7ac784f8f93d623be3d67ea39 bdbb34ed714d4210bf90678d4bd55dad--2850d4d7ac784f8f93d623be3d67ea39 b6983d3b115a480287e5f57480c9c4ef 77ac1922140f47ee85cc8a8ddace4c8c AddBlock 08f05e1284304b29b0781f96b3c9c3f6--77ac1922140f47ee85cc8a8ddace4c8c 45026d4c895543c696466119dd172eda 2 77ac1922140f47ee85cc8a8ddace4c8c--b6983d3b115a480287e5f57480c9c4ef 557dd14b6a4047f2b41931fc7c1eeee3 bffbc39078ac44b9a6c1b568ff737f90 45026d4c895543c696466119dd172eda--bffbc39078ac44b9a6c1b568ff737f90 bffbc39078ac44b9a6c1b568ff737f90--557dd14b6a4047f2b41931fc7c1eeee3
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_2ba8b19c522d46d382a939d19c3a28d8 cluster_d859b2dd9b9849bd8fd8469e234ca049 rx dd1a34950c9e444084094843c167bc97 0 23980b3181204cffb9b208cb1423b5da X dd1a34950c9e444084094843c167bc97--23980b3181204cffb9b208cb1423b5da 5dd9540e742e4a45a7c57ba100fa8483 1 275f0cba90e44d39a8aec1cfc581c6f8 23980b3181204cffb9b208cb1423b5da--275f0cba90e44d39a8aec1cfc581c6f8 8c52e1349adf44dda62ec19c613c205a 275f0cba90e44d39a8aec1cfc581c6f8--8c52e1349adf44dda62ec19c613c205a d41950706e894465b090ee0393365d0c 8c52e1349adf44dda62ec19c613c205a--d41950706e894465b090ee0393365d0c 87909c82b5d04a4d9d57f8377a3c3651 bd1f3cda384948e7a955360a4379feaf Y 5dd9540e742e4a45a7c57ba100fa8483--bd1f3cda384948e7a955360a4379feaf 7bef9c2eb66846c2b8cef000cc8ebc95 2 5e953f5ccb404dcda9a655f00a1edab8 bd1f3cda384948e7a955360a4379feaf--5e953f5ccb404dcda9a655f00a1edab8 20e3f8caf4f54d8dba4a911f85607495 HamEvo 5e953f5ccb404dcda9a655f00a1edab8--20e3f8caf4f54d8dba4a911f85607495 20e3f8caf4f54d8dba4a911f85607495--87909c82b5d04a4d9d57f8377a3c3651 ab241241a3a44176a23d9c1fbf0e08d9 db41789e3a784675ac6ef53d4315c818 RX(x) 7bef9c2eb66846c2b8cef000cc8ebc95--db41789e3a784675ac6ef53d4315c818 2fdd1829f0ce4994a1674d66aa3f6ce1 3 1b49226d6c2b4456a098763178600f3e db41789e3a784675ac6ef53d4315c818--1b49226d6c2b4456a098763178600f3e 1a9c33ffa7b64d4fb7496d37a320a33b t = 10 1b49226d6c2b4456a098763178600f3e--1a9c33ffa7b64d4fb7496d37a320a33b 1a9c33ffa7b64d4fb7496d37a320a33b--ab241241a3a44176a23d9c1fbf0e08d9 119ff958373048f0afee57d201a6183d df91b71296584cdc98ab252cd570de6d RX(0.5) 2fdd1829f0ce4994a1674d66aa3f6ce1--df91b71296584cdc98ab252cd570de6d 3a68fd74103c4e15a77cdfed7d470b50 X df91b71296584cdc98ab252cd570de6d--3a68fd74103c4e15a77cdfed7d470b50 3a68fd74103c4e15a77cdfed7d470b50--1b49226d6c2b4456a098763178600f3e 2c2d2c392d3143fe97513848c4f0ceaa 3a68fd74103c4e15a77cdfed7d470b50--2c2d2c392d3143fe97513848c4f0ceaa 2c2d2c392d3143fe97513848c4f0ceaa--119ff958373048f0afee57d201a6183d
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_4543ff074a0a44e7bebe9758c9645fdf HEA cluster_68df27b377fe4250b5cbd32c843e637e Tower Fourier FM 8ce606d0becf4e9abb221588cb17d7d5 0 54000da1f937426c9f57b790ad0e60e7 RX(1.0*phi) 8ce606d0becf4e9abb221588cb17d7d5--54000da1f937426c9f57b790ad0e60e7 cdeaf857b97a44ac9928f3988d0f9070 1 707e0035ffee4bf79d78accb5334fb58 RX(theta₀) 54000da1f937426c9f57b790ad0e60e7--707e0035ffee4bf79d78accb5334fb58 f2568b6badb144f6a3c6d960bc3653bc RY(theta₄) 707e0035ffee4bf79d78accb5334fb58--f2568b6badb144f6a3c6d960bc3653bc 01382d8b42584e3c9e32dc86cb17d419 RX(theta₈) f2568b6badb144f6a3c6d960bc3653bc--01382d8b42584e3c9e32dc86cb17d419 6dc0e46fa7e743bc87ca22c17d5d2224 01382d8b42584e3c9e32dc86cb17d419--6dc0e46fa7e743bc87ca22c17d5d2224 d796fff618384a72bd16b21f20363d98 6dc0e46fa7e743bc87ca22c17d5d2224--d796fff618384a72bd16b21f20363d98 8070cc91381741a6afa5a3ebc71f6915 RX(theta₁₂) d796fff618384a72bd16b21f20363d98--8070cc91381741a6afa5a3ebc71f6915 c548aa7a09a945d8b1c2c28ee89e7645 RY(theta₁₆) 8070cc91381741a6afa5a3ebc71f6915--c548aa7a09a945d8b1c2c28ee89e7645 8e92259c177d4e4c87b19e7d9c0b94c2 RX(theta₂₀) c548aa7a09a945d8b1c2c28ee89e7645--8e92259c177d4e4c87b19e7d9c0b94c2 cb93546e281847318e017459c6b4ba4e 8e92259c177d4e4c87b19e7d9c0b94c2--cb93546e281847318e017459c6b4ba4e 3a35fbd10c7c4b4aab9f94cee4c14333 cb93546e281847318e017459c6b4ba4e--3a35fbd10c7c4b4aab9f94cee4c14333 cfaf6511552a4d5eb15b4f7ab7112d32 3a35fbd10c7c4b4aab9f94cee4c14333--cfaf6511552a4d5eb15b4f7ab7112d32 bf3c597783e4460d8ebefa65d298a5e4 6035b4e8e09b4c718aad6f76fdfe8d4c RX(2.0*phi) cdeaf857b97a44ac9928f3988d0f9070--6035b4e8e09b4c718aad6f76fdfe8d4c f5f13d2f249b43c58cbfcc5071eaf095 2 1145a95d6ad3426c99c18181b43c22fe RX(theta₁) 6035b4e8e09b4c718aad6f76fdfe8d4c--1145a95d6ad3426c99c18181b43c22fe 9a3080f32ab6483091c935b138f23c4a RY(theta₅) 1145a95d6ad3426c99c18181b43c22fe--9a3080f32ab6483091c935b138f23c4a 7da5172ecefe4c1d97494ba9b5e5d119 RX(theta₉) 9a3080f32ab6483091c935b138f23c4a--7da5172ecefe4c1d97494ba9b5e5d119 40cfad3d057542f5ab1eea3bc5bb1a2f X 7da5172ecefe4c1d97494ba9b5e5d119--40cfad3d057542f5ab1eea3bc5bb1a2f 40cfad3d057542f5ab1eea3bc5bb1a2f--6dc0e46fa7e743bc87ca22c17d5d2224 7737e544e4c344d38368a9921806eaf7 40cfad3d057542f5ab1eea3bc5bb1a2f--7737e544e4c344d38368a9921806eaf7 2524bead9e4d4dac8823588761e262c3 RX(theta₁₃) 7737e544e4c344d38368a9921806eaf7--2524bead9e4d4dac8823588761e262c3 f92ef9bba1204a4cbc8459ee2cd979db RY(theta₁₇) 2524bead9e4d4dac8823588761e262c3--f92ef9bba1204a4cbc8459ee2cd979db 76f4be443a3547638bb0437edafa1f82 RX(theta₂₁) f92ef9bba1204a4cbc8459ee2cd979db--76f4be443a3547638bb0437edafa1f82 6d745c16dc334b738074f61b74fae2d9 X 76f4be443a3547638bb0437edafa1f82--6d745c16dc334b738074f61b74fae2d9 6d745c16dc334b738074f61b74fae2d9--cb93546e281847318e017459c6b4ba4e 045e065d58af43359faf12da2525f257 6d745c16dc334b738074f61b74fae2d9--045e065d58af43359faf12da2525f257 045e065d58af43359faf12da2525f257--bf3c597783e4460d8ebefa65d298a5e4 d533b1cb9ff2448a8cb7d50d0a379e9e 771608273cc84952b2e89ca9fe9ceec2 RX(3.0*phi) f5f13d2f249b43c58cbfcc5071eaf095--771608273cc84952b2e89ca9fe9ceec2 55ae5299a1db47dbac8abf52f264b063 3 95d44bfae69248ada10de3d8f7bdad76 RX(theta₂) 771608273cc84952b2e89ca9fe9ceec2--95d44bfae69248ada10de3d8f7bdad76 38a8516c8d7d455b98898b503387b164 RY(theta₆) 95d44bfae69248ada10de3d8f7bdad76--38a8516c8d7d455b98898b503387b164 9d96cf40b2794edfad96befd4e416733 RX(theta₁₀) 38a8516c8d7d455b98898b503387b164--9d96cf40b2794edfad96befd4e416733 6648883fea4d4c85bafb35b1bd2c9c5f 9d96cf40b2794edfad96befd4e416733--6648883fea4d4c85bafb35b1bd2c9c5f ca45beecefb84c7c9295ecc99d1df66c X 6648883fea4d4c85bafb35b1bd2c9c5f--ca45beecefb84c7c9295ecc99d1df66c ca45beecefb84c7c9295ecc99d1df66c--7737e544e4c344d38368a9921806eaf7 504d74bb45df46c99fcd748554d6a17b RX(theta₁₄) ca45beecefb84c7c9295ecc99d1df66c--504d74bb45df46c99fcd748554d6a17b 7869b80ac3eb493cacc07b7c38f86ede RY(theta₁₈) 504d74bb45df46c99fcd748554d6a17b--7869b80ac3eb493cacc07b7c38f86ede 405abfe034724cd19cdac240ed0aa200 RX(theta₂₂) 7869b80ac3eb493cacc07b7c38f86ede--405abfe034724cd19cdac240ed0aa200 9be6893c66ac4df7ac482e0f605ea649 405abfe034724cd19cdac240ed0aa200--9be6893c66ac4df7ac482e0f605ea649 cd229004734948a0a0cd34260fb1401c X 9be6893c66ac4df7ac482e0f605ea649--cd229004734948a0a0cd34260fb1401c cd229004734948a0a0cd34260fb1401c--045e065d58af43359faf12da2525f257 cd229004734948a0a0cd34260fb1401c--d533b1cb9ff2448a8cb7d50d0a379e9e 3353dc2e0b2549898eea41b2c3c50f4b ea5fd07fc8da42eea8c36460e3e72790 RX(4.0*phi) 55ae5299a1db47dbac8abf52f264b063--ea5fd07fc8da42eea8c36460e3e72790 d543d91222934e67bb6064f5c1c934a0 RX(theta₃) ea5fd07fc8da42eea8c36460e3e72790--d543d91222934e67bb6064f5c1c934a0 a64df990cf9244c88fb8c6718e5f15d1 RY(theta₇) d543d91222934e67bb6064f5c1c934a0--a64df990cf9244c88fb8c6718e5f15d1 2887f003d30945b896e4d3d9438a96a0 RX(theta₁₁) a64df990cf9244c88fb8c6718e5f15d1--2887f003d30945b896e4d3d9438a96a0 7783df9e8ac84d12ae0f8fef294164b3 X 2887f003d30945b896e4d3d9438a96a0--7783df9e8ac84d12ae0f8fef294164b3 7783df9e8ac84d12ae0f8fef294164b3--6648883fea4d4c85bafb35b1bd2c9c5f 6f252e702b31437491961660f2827356 7783df9e8ac84d12ae0f8fef294164b3--6f252e702b31437491961660f2827356 a687e7683e9b43afa0775370f453a69b RX(theta₁₅) 6f252e702b31437491961660f2827356--a687e7683e9b43afa0775370f453a69b 1780240e53bd409bb03153b7337a8067 RY(theta₁₉) a687e7683e9b43afa0775370f453a69b--1780240e53bd409bb03153b7337a8067 c5adff865d71413cb4d6817e314f5543 RX(theta₂₃) 1780240e53bd409bb03153b7337a8067--c5adff865d71413cb4d6817e314f5543 d392bd5fb4334ef9b29c9543dcbcea3d X c5adff865d71413cb4d6817e314f5543--d392bd5fb4334ef9b29c9543dcbcea3d d392bd5fb4334ef9b29c9543dcbcea3d--9be6893c66ac4df7ac482e0f605ea649 035ea8f7fd0a459aa6e23ff4570e2924 d392bd5fb4334ef9b29c9543dcbcea3d--035ea8f7fd0a459aa6e23ff4570e2924 035ea8f7fd0a459aa6e23ff4570e2924--3353dc2e0b2549898eea41b2c3c50f4b
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_a34c07a3f5d34988bd3040df3dc5621d Obs. cluster_d9fdb720493448b7bd77937cfc19771d cluster_f57569d028194ebf9c6d6eaf98648c54 HEA e1443824df674e8bb3b99776f753dae7 0 56698b71f92343bc8240ca6874faad28 RX(theta₀) e1443824df674e8bb3b99776f753dae7--56698b71f92343bc8240ca6874faad28 3d569a9fc5ed4835bae7d93efd63fc06 1 fc8ba0a0b9d14d20b3a2412e72a3f59a RY(theta₃) 56698b71f92343bc8240ca6874faad28--fc8ba0a0b9d14d20b3a2412e72a3f59a 784acfc7636d4387813cecf5d5f40402 RX(theta₆) fc8ba0a0b9d14d20b3a2412e72a3f59a--784acfc7636d4387813cecf5d5f40402 b6409f9d38ee4465bf3a52aea651b425 784acfc7636d4387813cecf5d5f40402--b6409f9d38ee4465bf3a52aea651b425 5959ba8ae0184742bed3c5667142b277 b6409f9d38ee4465bf3a52aea651b425--5959ba8ae0184742bed3c5667142b277 fd3dd2e04de344d6a898f00975581b7c RX(theta₉) 5959ba8ae0184742bed3c5667142b277--fd3dd2e04de344d6a898f00975581b7c a7ed16f051164ef691efb007982bb86b RY(theta₁₂) fd3dd2e04de344d6a898f00975581b7c--a7ed16f051164ef691efb007982bb86b 410abc90c3d2446aa5eb91995e650e97 RX(theta₁₅) a7ed16f051164ef691efb007982bb86b--410abc90c3d2446aa5eb91995e650e97 3362c82484ed4c38b2d8f4d2709943d7 410abc90c3d2446aa5eb91995e650e97--3362c82484ed4c38b2d8f4d2709943d7 060a91dfedcc44c8bd13097cc0f2130e 3362c82484ed4c38b2d8f4d2709943d7--060a91dfedcc44c8bd13097cc0f2130e 9d01e7db65e14076ab5e0eeb31c4a2ec 060a91dfedcc44c8bd13097cc0f2130e--9d01e7db65e14076ab5e0eeb31c4a2ec 2175239f6cf3423290cb1640da3fa0da 9d01e7db65e14076ab5e0eeb31c4a2ec--2175239f6cf3423290cb1640da3fa0da 83ea8367785042ff96c0213675f2ce46 dfd9a5cb364e42668f519fd6d1e6bf99 RX(theta₁) 3d569a9fc5ed4835bae7d93efd63fc06--dfd9a5cb364e42668f519fd6d1e6bf99 32eb3e115c5648e4a87d9ee436b01859 2 080f1fe9adaa4778b73cbbae18a35490 RY(theta₄) dfd9a5cb364e42668f519fd6d1e6bf99--080f1fe9adaa4778b73cbbae18a35490 44c9f4c5345b4295823b2f2935c7eb4e RX(theta₇) 080f1fe9adaa4778b73cbbae18a35490--44c9f4c5345b4295823b2f2935c7eb4e 2d5899baa6944f81a4dec910c7de6212 X 44c9f4c5345b4295823b2f2935c7eb4e--2d5899baa6944f81a4dec910c7de6212 2d5899baa6944f81a4dec910c7de6212--b6409f9d38ee4465bf3a52aea651b425 d451ace732fd4085851610457decb548 2d5899baa6944f81a4dec910c7de6212--d451ace732fd4085851610457decb548 6887c1795ebe49b08de4f7bbb6bba0db RX(theta₁₀) d451ace732fd4085851610457decb548--6887c1795ebe49b08de4f7bbb6bba0db d9d52d49a6894022bc567b09f1d3abb3 RY(theta₁₃) 6887c1795ebe49b08de4f7bbb6bba0db--d9d52d49a6894022bc567b09f1d3abb3 9f53d7444337454caf2d5ff24028ea40 RX(theta₁₆) d9d52d49a6894022bc567b09f1d3abb3--9f53d7444337454caf2d5ff24028ea40 2fecd952c9f64a81b06da4e7e07d8128 X 9f53d7444337454caf2d5ff24028ea40--2fecd952c9f64a81b06da4e7e07d8128 2fecd952c9f64a81b06da4e7e07d8128--3362c82484ed4c38b2d8f4d2709943d7 fa6b6882276344b9a9009f3dd6f9a2d1 2fecd952c9f64a81b06da4e7e07d8128--fa6b6882276344b9a9009f3dd6f9a2d1 4a493f557db840d39fda6fbc61d721dc AddBlock fa6b6882276344b9a9009f3dd6f9a2d1--4a493f557db840d39fda6fbc61d721dc 4a493f557db840d39fda6fbc61d721dc--83ea8367785042ff96c0213675f2ce46 aaf6f2ecf21042ff973da6faa0972ed1 4502059a38a543429e531ee5cc0a37ae RX(theta₂) 32eb3e115c5648e4a87d9ee436b01859--4502059a38a543429e531ee5cc0a37ae f87eb025a0f449b3ae58100c6a23711a RY(theta₅) 4502059a38a543429e531ee5cc0a37ae--f87eb025a0f449b3ae58100c6a23711a 5c15e12d985b4e50b01635c7b3c572b1 RX(theta₈) f87eb025a0f449b3ae58100c6a23711a--5c15e12d985b4e50b01635c7b3c572b1 2ba59abe29304829a8097825983892c6 5c15e12d985b4e50b01635c7b3c572b1--2ba59abe29304829a8097825983892c6 18b5651969034937940e57d8fd08d338 X 2ba59abe29304829a8097825983892c6--18b5651969034937940e57d8fd08d338 18b5651969034937940e57d8fd08d338--d451ace732fd4085851610457decb548 4e514677c0de40118cdd501e613b1ccd RX(theta₁₁) 18b5651969034937940e57d8fd08d338--4e514677c0de40118cdd501e613b1ccd 687986dc27a5401ea532d91cdc9b28b9 RY(theta₁₄) 4e514677c0de40118cdd501e613b1ccd--687986dc27a5401ea532d91cdc9b28b9 0fda9d9f96a8441896c0f3764f46b2be RX(theta₁₇) 687986dc27a5401ea532d91cdc9b28b9--0fda9d9f96a8441896c0f3764f46b2be 6fc620b332804889bd1fbc43740223dc 0fda9d9f96a8441896c0f3764f46b2be--6fc620b332804889bd1fbc43740223dc 29697de25ac44912a64d9f166acfb1fd X 6fc620b332804889bd1fbc43740223dc--29697de25ac44912a64d9f166acfb1fd 29697de25ac44912a64d9f166acfb1fd--fa6b6882276344b9a9009f3dd6f9a2d1 849b8f0acb6447c39b8825596c70e77a 29697de25ac44912a64d9f166acfb1fd--849b8f0acb6447c39b8825596c70e77a 849b8f0acb6447c39b8825596c70e77a--aaf6f2ecf21042ff973da6faa0972ed1
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 2bd0ce74ac3840ecbf96360d749f30b0 0 2b8423f8d08d4318a8ece67105b63b9e 2bd0ce74ac3840ecbf96360d749f30b0--2b8423f8d08d4318a8ece67105b63b9e f22d2291947c42ed8e6956a328d202f4 1 a706932902db44dbaaccaf04110fce81 6e976294c8d04a319868fb2ed417580f 2b8423f8d08d4318a8ece67105b63b9e--6e976294c8d04a319868fb2ed417580f e996c438a57444a5909ae3e6b6bf5b45 a706932902db44dbaaccaf04110fce81--e996c438a57444a5909ae3e6b6bf5b45 1da7b538ace44deeb3c8c127ee28420f 9f183427cc304d428ee997b6967d5fcb e996c438a57444a5909ae3e6b6bf5b45--9f183427cc304d428ee997b6967d5fcb c214b1cced26425680e5e5161042a2d7 1da7b538ace44deeb3c8c127ee28420f--c214b1cced26425680e5e5161042a2d7 448f9ba5ce0e44cb95cf41bb5ce27157 56247ece097a47298b397a3258b23227 f22d2291947c42ed8e6956a328d202f4--56247ece097a47298b397a3258b23227 17449406d4dd4fec90f040e42a4d07fb 2 56247ece097a47298b397a3258b23227--a706932902db44dbaaccaf04110fce81 8767ab06dda34e138184073e1e3e707d 6e976294c8d04a319868fb2ed417580f--8767ab06dda34e138184073e1e3e707d 0a3f1642004e4263a6e976b68893d14a 8767ab06dda34e138184073e1e3e707d--0a3f1642004e4263a6e976b68893d14a 0a3f1642004e4263a6e976b68893d14a--448f9ba5ce0e44cb95cf41bb5ce27157 80b7da21d858426aa647cee48ebb5358 e8417bc0602147e09b3474d75f6627e5 17449406d4dd4fec90f040e42a4d07fb--e8417bc0602147e09b3474d75f6627e5 223fe0bd64bb49d6b902208bce3ffb16 3 fb437088f63241cf97443b41b643034d e8417bc0602147e09b3474d75f6627e5--fb437088f63241cf97443b41b643034d 28995d51bc9645d2b70bec0e9ab72858 fb437088f63241cf97443b41b643034d--28995d51bc9645d2b70bec0e9ab72858 5b86833b259f449aa0eafb9973cfdb53 28995d51bc9645d2b70bec0e9ab72858--5b86833b259f449aa0eafb9973cfdb53 5b86833b259f449aa0eafb9973cfdb53--80b7da21d858426aa647cee48ebb5358 70566bbeb17c4c98afa57ebc24e77d6a 175fa278adf84183b96cea0ff4fd7e35 223fe0bd64bb49d6b902208bce3ffb16--175fa278adf84183b96cea0ff4fd7e35 1cee5bc85b284e038cc12abaa44966e6 175fa278adf84183b96cea0ff4fd7e35--1cee5bc85b284e038cc12abaa44966e6 3dfc5339d6d54c08a627ad57a95e9ab7 1cee5bc85b284e038cc12abaa44966e6--3dfc5339d6d54c08a627ad57a95e9ab7 3dfc5339d6d54c08a627ad57a95e9ab7--1da7b538ace44deeb3c8c127ee28420f 9f183427cc304d428ee997b6967d5fcb--70566bbeb17c4c98afa57ebc24e77d6a
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 f22f8b44531a4462b362eb2d79f8bf21 0 737d488132f94f81b91eb63ed377e1ef f22f8b44531a4462b362eb2d79f8bf21--737d488132f94f81b91eb63ed377e1ef 7afbcf8c2d76404daa5bc08cbc72f346 1 904aa6fb67d3466a9114cc86765da220 737d488132f94f81b91eb63ed377e1ef--904aa6fb67d3466a9114cc86765da220 899f4af5385e457bbb50d5b8a61537aa 904aa6fb67d3466a9114cc86765da220--899f4af5385e457bbb50d5b8a61537aa 94de861607a54636949efb2f08e0b5c0 899f4af5385e457bbb50d5b8a61537aa--94de861607a54636949efb2f08e0b5c0 e8f0510c636148499f0e84ae08cfc3c6 1ee577341c30498da40f838c1f640476 PHASE(0.5) 7afbcf8c2d76404daa5bc08cbc72f346--1ee577341c30498da40f838c1f640476 849e2615df984edbabe79c81a38df764 2 1ee577341c30498da40f838c1f640476--737d488132f94f81b91eb63ed377e1ef f48458bb527d4eacb388587cc3e83728 1ee577341c30498da40f838c1f640476--f48458bb527d4eacb388587cc3e83728 801012d66ab941a6af4e85c96b23883b f48458bb527d4eacb388587cc3e83728--801012d66ab941a6af4e85c96b23883b 801012d66ab941a6af4e85c96b23883b--e8f0510c636148499f0e84ae08cfc3c6 fa1e14964936465cb66d6d5e4eb7700b 9a56f4037c6444428f3f6e542a695232 849e2615df984edbabe79c81a38df764--9a56f4037c6444428f3f6e542a695232 727dc3d5c5664b34881d85d54396ea4e 3 396f3547b2a64d20932bbfbdc7f64a78 PHASE(0.5) 9a56f4037c6444428f3f6e542a695232--396f3547b2a64d20932bbfbdc7f64a78 396f3547b2a64d20932bbfbdc7f64a78--904aa6fb67d3466a9114cc86765da220 815b70f6ffc94af48a55be6060fd975e 396f3547b2a64d20932bbfbdc7f64a78--815b70f6ffc94af48a55be6060fd975e 815b70f6ffc94af48a55be6060fd975e--fa1e14964936465cb66d6d5e4eb7700b da5f3e0d7ebb499eb0d666a135a2afd7 eab527d2d50b449dafeef8036a2b3be3 727dc3d5c5664b34881d85d54396ea4e--eab527d2d50b449dafeef8036a2b3be3 00df4a743f03491ba4d7e8937d02cefe eab527d2d50b449dafeef8036a2b3be3--00df4a743f03491ba4d7e8937d02cefe 83fb407a921e4976838334573352c348 PHASE(0.5) 00df4a743f03491ba4d7e8937d02cefe--83fb407a921e4976838334573352c348 83fb407a921e4976838334573352c348--899f4af5385e457bbb50d5b8a61537aa 83fb407a921e4976838334573352c348--da5f3e0d7ebb499eb0d666a135a2afd7

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