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 d551bacba8f34231b4fd4541abb51a9f 0 34e7404367df43578b0673e6eb648815 X d551bacba8f34231b4fd4541abb51a9f--34e7404367df43578b0673e6eb648815 5a9daba60c164140bd0010667cc5040c 1 0f4b889be96e4069a141dc5982c17bea 34e7404367df43578b0673e6eb648815--0f4b889be96e4069a141dc5982c17bea 72fdf8c85b5c493382be19824b09acef 6606e769716b4b58ae3016914d76b3ca Y 5a9daba60c164140bd0010667cc5040c--6606e769716b4b58ae3016914d76b3ca 6606e769716b4b58ae3016914d76b3ca--72fdf8c85b5c493382be19824b09acef
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 7b58a1057998461db63679e2cd2f4a42 0 c86a80c66515418a9a5b9c7c1d51ac10 X 7b58a1057998461db63679e2cd2f4a42--c86a80c66515418a9a5b9c7c1d51ac10 d617ba7f1bf24034af2fee5383d65e5e Y c86a80c66515418a9a5b9c7c1d51ac10--d617ba7f1bf24034af2fee5383d65e5e 0748ebc8fe7641eeacb78875ad61c6d1 d617ba7f1bf24034af2fee5383d65e5e--0748ebc8fe7641eeacb78875ad61c6d1
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 4084382688f548d78151fbb4b0fbef0f 0 29e385bb58694281a7ac8bd9b33e1ff2 X 4084382688f548d78151fbb4b0fbef0f--29e385bb58694281a7ac8bd9b33e1ff2 82a4a8d690304868988429856306ac94 1 4b36229b2bac41788ada9ca2f54ad0c2 29e385bb58694281a7ac8bd9b33e1ff2--4b36229b2bac41788ada9ca2f54ad0c2 936416a595144ca184565e15122b4a2b 4b36229b2bac41788ada9ca2f54ad0c2--936416a595144ca184565e15122b4a2b 0e508667279d47cab98dc875d1398df9 93f950f9b58c461faf82c553964e107e 82a4a8d690304868988429856306ac94--93f950f9b58c461faf82c553964e107e 96aeb7b70ada481ab777665310b5e8bc Y 93f950f9b58c461faf82c553964e107e--96aeb7b70ada481ab777665310b5e8bc 96aeb7b70ada481ab777665310b5e8bc--0e508667279d47cab98dc875d1398df9
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_020043c79bc34c6ca4dad9429bc0c9ed 30a30aeb6a3d47d492be448448ecb76b 0 0f6dff580d1f45b582f1a979251a6f89 30a30aeb6a3d47d492be448448ecb76b--0f6dff580d1f45b582f1a979251a6f89 6bc303415c1f4d73a330637527f7230a 1 f21e651dc93244bb8082395c26cb6e48 0f6dff580d1f45b582f1a979251a6f89--f21e651dc93244bb8082395c26cb6e48 0d7dc06a1eef40d9b4760aeb9ad36829 f2345787544c4f678d8ba666f7e684f1 AddBlock 6bc303415c1f4d73a330637527f7230a--f2345787544c4f678d8ba666f7e684f1 92f431b874934a0d9cc7b8508d5b2144 2 f2345787544c4f678d8ba666f7e684f1--0d7dc06a1eef40d9b4760aeb9ad36829 4b80a2b2191845ca86ee4921283aaa4a ff4ec75c2c124d1bb8310bad40d44b9d 92f431b874934a0d9cc7b8508d5b2144--ff4ec75c2c124d1bb8310bad40d44b9d ff4ec75c2c124d1bb8310bad40d44b9d--4b80a2b2191845ca86ee4921283aaa4a
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_4f1fa866d8e040c0a8d6d4d7c55a31e2 cluster_c14aa0723dec4550b92502a9fe6977a6 rx 91fb4fef05d647649ae8ce67f499719d 0 4db454c5765b4e3faf94aa7e68788ee2 X 91fb4fef05d647649ae8ce67f499719d--4db454c5765b4e3faf94aa7e68788ee2 cae940c25b6a40e68509d1ea4b442dd3 1 44d6167c9a84424ebb7b2eb0268b992e 4db454c5765b4e3faf94aa7e68788ee2--44d6167c9a84424ebb7b2eb0268b992e d420dfdb61af4d3da10dd06f20730b17 44d6167c9a84424ebb7b2eb0268b992e--d420dfdb61af4d3da10dd06f20730b17 b246bfbd39d045b8baa62e96a91f4afa d420dfdb61af4d3da10dd06f20730b17--b246bfbd39d045b8baa62e96a91f4afa 0f9b776343c84d01be5937ff3a9a0da6 97565d9d204746a292a4c3253c8aae8b Y cae940c25b6a40e68509d1ea4b442dd3--97565d9d204746a292a4c3253c8aae8b acf4eb92245047aaa091d82fa4570eae 2 2c343c7d657d40a28d8f381b43a49608 97565d9d204746a292a4c3253c8aae8b--2c343c7d657d40a28d8f381b43a49608 11cf033b7e6b45fcb030e4d466eef341 HamEvo 2c343c7d657d40a28d8f381b43a49608--11cf033b7e6b45fcb030e4d466eef341 11cf033b7e6b45fcb030e4d466eef341--0f9b776343c84d01be5937ff3a9a0da6 d533f7cde6e54c50994518023f50c4c0 2a2f122e348d496cbeeaf5585680afd6 RX(x) acf4eb92245047aaa091d82fa4570eae--2a2f122e348d496cbeeaf5585680afd6 ebf2f5f466094a0f8b69056aa4fcb73d 3 33f3c1ed7c754053a87d2a02e7f6b6cb 2a2f122e348d496cbeeaf5585680afd6--33f3c1ed7c754053a87d2a02e7f6b6cb 6231d5f8e5804574bf3b1e7dccdd8eb8 t = 10 33f3c1ed7c754053a87d2a02e7f6b6cb--6231d5f8e5804574bf3b1e7dccdd8eb8 6231d5f8e5804574bf3b1e7dccdd8eb8--d533f7cde6e54c50994518023f50c4c0 076d9ee502ec4b04b22fd03a8405d8a1 dedf391ded014ea2acc9e5646a70258e RX(0.5) ebf2f5f466094a0f8b69056aa4fcb73d--dedf391ded014ea2acc9e5646a70258e 79933635bd3c4d01af44b272628d6504 X dedf391ded014ea2acc9e5646a70258e--79933635bd3c4d01af44b272628d6504 79933635bd3c4d01af44b272628d6504--33f3c1ed7c754053a87d2a02e7f6b6cb 1b33bdbaa9c44f879023389f144ef4dd 79933635bd3c4d01af44b272628d6504--1b33bdbaa9c44f879023389f144ef4dd 1b33bdbaa9c44f879023389f144ef4dd--076d9ee502ec4b04b22fd03a8405d8a1
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_0be7d9346b9e4c76b98fa5f0a19f35e9 HEA cluster_ea93a113606241c5b3d1c71b8ade7cac Tower Fourier FM 09a11b2aee22479db33e7355f67e0554 0 41743d79b9c543059893e2e50ec5567b RX(1.0*phi) 09a11b2aee22479db33e7355f67e0554--41743d79b9c543059893e2e50ec5567b f8bc274cdd3d46ef80ac32ad35962315 1 4bbb843b0b63454a8b7d18d9e11a3fa1 RX(theta₀) 41743d79b9c543059893e2e50ec5567b--4bbb843b0b63454a8b7d18d9e11a3fa1 4e68907bb7dc47cd8dc711482e6af87b RY(theta₄) 4bbb843b0b63454a8b7d18d9e11a3fa1--4e68907bb7dc47cd8dc711482e6af87b 956e63890a5d4d359682bb8a73189d88 RX(theta₈) 4e68907bb7dc47cd8dc711482e6af87b--956e63890a5d4d359682bb8a73189d88 437963ea8ac54be3a9d570155e474aee 956e63890a5d4d359682bb8a73189d88--437963ea8ac54be3a9d570155e474aee 26eda2a0af094f9ebb63478642ed4af1 437963ea8ac54be3a9d570155e474aee--26eda2a0af094f9ebb63478642ed4af1 d5c27d04e88b433c936e6127aa5afc82 RX(theta₁₂) 26eda2a0af094f9ebb63478642ed4af1--d5c27d04e88b433c936e6127aa5afc82 490f8cee4c5243abb8b60abd9e5b5118 RY(theta₁₆) d5c27d04e88b433c936e6127aa5afc82--490f8cee4c5243abb8b60abd9e5b5118 876e4addc4034bd18eb87229e8dfa38e RX(theta₂₀) 490f8cee4c5243abb8b60abd9e5b5118--876e4addc4034bd18eb87229e8dfa38e 8d68aac0aafe4d03bbc0cede9eb5972c 876e4addc4034bd18eb87229e8dfa38e--8d68aac0aafe4d03bbc0cede9eb5972c 08541c66764d4be3b74ce1b48b610b2a 8d68aac0aafe4d03bbc0cede9eb5972c--08541c66764d4be3b74ce1b48b610b2a 313ae437aaa146c7a46cff1919681f82 08541c66764d4be3b74ce1b48b610b2a--313ae437aaa146c7a46cff1919681f82 351eeeda1d5249f08aeb21a2e7c53cc1 fbe96af6937146d5a8499313d4477498 RX(2.0*phi) f8bc274cdd3d46ef80ac32ad35962315--fbe96af6937146d5a8499313d4477498 2cda6c04c6d045289b04cfa74fce61a2 2 96f1753efef44528b1624099eca90df0 RX(theta₁) fbe96af6937146d5a8499313d4477498--96f1753efef44528b1624099eca90df0 eb6efd5516d14b628b0d010ef194794b RY(theta₅) 96f1753efef44528b1624099eca90df0--eb6efd5516d14b628b0d010ef194794b 89e6e51bb9e9490c80939baf113d0864 RX(theta₉) eb6efd5516d14b628b0d010ef194794b--89e6e51bb9e9490c80939baf113d0864 8164055b2a63400b91428bf709c98536 X 89e6e51bb9e9490c80939baf113d0864--8164055b2a63400b91428bf709c98536 8164055b2a63400b91428bf709c98536--437963ea8ac54be3a9d570155e474aee c4a9d42d9d7e408cbf43c4789d562178 8164055b2a63400b91428bf709c98536--c4a9d42d9d7e408cbf43c4789d562178 df32b494dd784a93854bf4155ad3c831 RX(theta₁₃) c4a9d42d9d7e408cbf43c4789d562178--df32b494dd784a93854bf4155ad3c831 b3f318c323d44af9a2b982bd87b93ad0 RY(theta₁₇) df32b494dd784a93854bf4155ad3c831--b3f318c323d44af9a2b982bd87b93ad0 da4870016d57441480106670ec9821db RX(theta₂₁) b3f318c323d44af9a2b982bd87b93ad0--da4870016d57441480106670ec9821db ee8c673bbe054958a1232fa4a2ea63e3 X da4870016d57441480106670ec9821db--ee8c673bbe054958a1232fa4a2ea63e3 ee8c673bbe054958a1232fa4a2ea63e3--8d68aac0aafe4d03bbc0cede9eb5972c dab17ef48c4445f48fcf7c0849aa8fa1 ee8c673bbe054958a1232fa4a2ea63e3--dab17ef48c4445f48fcf7c0849aa8fa1 dab17ef48c4445f48fcf7c0849aa8fa1--351eeeda1d5249f08aeb21a2e7c53cc1 04ba09b38f884ebfbed36985f4f2c51a d84c4b1a37d44def8ca99721d78e5f6f RX(3.0*phi) 2cda6c04c6d045289b04cfa74fce61a2--d84c4b1a37d44def8ca99721d78e5f6f bf243b3765794085a6db98d26b8f474d 3 99aa07d95a1546e59371706c7c8d58e3 RX(theta₂) d84c4b1a37d44def8ca99721d78e5f6f--99aa07d95a1546e59371706c7c8d58e3 9be1c34b978544dd9f4ebd7bd159d613 RY(theta₆) 99aa07d95a1546e59371706c7c8d58e3--9be1c34b978544dd9f4ebd7bd159d613 50ffaf3353f44d2eb7004d571a8895e5 RX(theta₁₀) 9be1c34b978544dd9f4ebd7bd159d613--50ffaf3353f44d2eb7004d571a8895e5 e19dfdf999eb4b1babc645feb41992a9 50ffaf3353f44d2eb7004d571a8895e5--e19dfdf999eb4b1babc645feb41992a9 a9917a6e32d24887a127fb89965db427 X e19dfdf999eb4b1babc645feb41992a9--a9917a6e32d24887a127fb89965db427 a9917a6e32d24887a127fb89965db427--c4a9d42d9d7e408cbf43c4789d562178 e3b63b0683eb41ff89e92ab55a556175 RX(theta₁₄) a9917a6e32d24887a127fb89965db427--e3b63b0683eb41ff89e92ab55a556175 4f3801c65954461b94043708e93a63c0 RY(theta₁₈) e3b63b0683eb41ff89e92ab55a556175--4f3801c65954461b94043708e93a63c0 81c5ec45f1054287bc4acee699780f2a RX(theta₂₂) 4f3801c65954461b94043708e93a63c0--81c5ec45f1054287bc4acee699780f2a 15c93ba43bec454a9f28d9f454079b01 81c5ec45f1054287bc4acee699780f2a--15c93ba43bec454a9f28d9f454079b01 bd5273d085ec4847ab3768bde1fbc40b X 15c93ba43bec454a9f28d9f454079b01--bd5273d085ec4847ab3768bde1fbc40b bd5273d085ec4847ab3768bde1fbc40b--dab17ef48c4445f48fcf7c0849aa8fa1 bd5273d085ec4847ab3768bde1fbc40b--04ba09b38f884ebfbed36985f4f2c51a 8bb3838ba7604e5ebb4ace0ceaa92991 b45e2e1fb3fd4b7984a88fa1eed972f0 RX(4.0*phi) bf243b3765794085a6db98d26b8f474d--b45e2e1fb3fd4b7984a88fa1eed972f0 3dcc979d711648b89d5632aa65cd8288 RX(theta₃) b45e2e1fb3fd4b7984a88fa1eed972f0--3dcc979d711648b89d5632aa65cd8288 e2ef6eebf50a4ea4bf9519c190d79503 RY(theta₇) 3dcc979d711648b89d5632aa65cd8288--e2ef6eebf50a4ea4bf9519c190d79503 aed91037bded46b3a34c8ea8a7c14df0 RX(theta₁₁) e2ef6eebf50a4ea4bf9519c190d79503--aed91037bded46b3a34c8ea8a7c14df0 3618854534254fb1975f387bca4c14c8 X aed91037bded46b3a34c8ea8a7c14df0--3618854534254fb1975f387bca4c14c8 3618854534254fb1975f387bca4c14c8--e19dfdf999eb4b1babc645feb41992a9 5c96c61fd5f3443fafba860ad582beae 3618854534254fb1975f387bca4c14c8--5c96c61fd5f3443fafba860ad582beae d6d46e996707499abc8e83fb92044c71 RX(theta₁₅) 5c96c61fd5f3443fafba860ad582beae--d6d46e996707499abc8e83fb92044c71 a5838cf660bd45ad93725977f3f33ab2 RY(theta₁₉) d6d46e996707499abc8e83fb92044c71--a5838cf660bd45ad93725977f3f33ab2 4a69204a70bd4a298c429096da3116b9 RX(theta₂₃) a5838cf660bd45ad93725977f3f33ab2--4a69204a70bd4a298c429096da3116b9 5d2dd210ff94421eba70fa8e4ffa9d26 X 4a69204a70bd4a298c429096da3116b9--5d2dd210ff94421eba70fa8e4ffa9d26 5d2dd210ff94421eba70fa8e4ffa9d26--15c93ba43bec454a9f28d9f454079b01 ff78379d15394666b59a30e7a07a555a 5d2dd210ff94421eba70fa8e4ffa9d26--ff78379d15394666b59a30e7a07a555a ff78379d15394666b59a30e7a07a555a--8bb3838ba7604e5ebb4ace0ceaa92991
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_e62da7c6332944a1ac0384516439472a Obs. cluster_2464ef7c3e5148bab91f3741c8092971 cluster_0019e25365e647c69648e2b31c13d5c8 HEA 13f530747364492183eb27d2a37b82a3 0 eb1c68d820fc4be4b79d95e6db6b41cf RX(theta₀) 13f530747364492183eb27d2a37b82a3--eb1c68d820fc4be4b79d95e6db6b41cf b76a2e7d6f4c406ea5d1bf35c486fe19 1 544b7a0c025240c69af364c54ee12ba4 RY(theta₃) eb1c68d820fc4be4b79d95e6db6b41cf--544b7a0c025240c69af364c54ee12ba4 437b9928113b4c698d8ee7f3f19e986b RX(theta₆) 544b7a0c025240c69af364c54ee12ba4--437b9928113b4c698d8ee7f3f19e986b 8090fe235c214cd48c6ae8e24ca8f373 437b9928113b4c698d8ee7f3f19e986b--8090fe235c214cd48c6ae8e24ca8f373 a83ee54c0d90448098cb1de3d334eb09 8090fe235c214cd48c6ae8e24ca8f373--a83ee54c0d90448098cb1de3d334eb09 3f636b3424af49ab963a2ecc0123dc1a RX(theta₉) a83ee54c0d90448098cb1de3d334eb09--3f636b3424af49ab963a2ecc0123dc1a 3ddb0108f03a41728c9766a01d2d704b RY(theta₁₂) 3f636b3424af49ab963a2ecc0123dc1a--3ddb0108f03a41728c9766a01d2d704b f8abba3307ed47bdb8ae768bb96d903f RX(theta₁₅) 3ddb0108f03a41728c9766a01d2d704b--f8abba3307ed47bdb8ae768bb96d903f ae4381f1d82045229b095fddaf97e863 f8abba3307ed47bdb8ae768bb96d903f--ae4381f1d82045229b095fddaf97e863 cadb6963660d408bb50b070a92fa9670 ae4381f1d82045229b095fddaf97e863--cadb6963660d408bb50b070a92fa9670 2485b916c0924da396ebc3d73277f2db cadb6963660d408bb50b070a92fa9670--2485b916c0924da396ebc3d73277f2db 84bc6bfcf6fe4c3fbe4a6bde29f06b34 2485b916c0924da396ebc3d73277f2db--84bc6bfcf6fe4c3fbe4a6bde29f06b34 24226d447ba244f5ba3721aad96d5372 4a717c81e4be434d99f9b158f27fd025 RX(theta₁) b76a2e7d6f4c406ea5d1bf35c486fe19--4a717c81e4be434d99f9b158f27fd025 eb51801949884bb086e2ba9147469e89 2 940dee7b1c77488286423af1804c6747 RY(theta₄) 4a717c81e4be434d99f9b158f27fd025--940dee7b1c77488286423af1804c6747 efe9185aef9d48658215bc9d54312db7 RX(theta₇) 940dee7b1c77488286423af1804c6747--efe9185aef9d48658215bc9d54312db7 eae77fe883d7487198b3ec96593e5a6f X efe9185aef9d48658215bc9d54312db7--eae77fe883d7487198b3ec96593e5a6f eae77fe883d7487198b3ec96593e5a6f--8090fe235c214cd48c6ae8e24ca8f373 ebb3d88c0b734062aa5d92d1e8a97834 eae77fe883d7487198b3ec96593e5a6f--ebb3d88c0b734062aa5d92d1e8a97834 260ab2f9cff14332891f096ab62071a8 RX(theta₁₀) ebb3d88c0b734062aa5d92d1e8a97834--260ab2f9cff14332891f096ab62071a8 5d4affeaa6344ae1a6b62beae5ad2de0 RY(theta₁₃) 260ab2f9cff14332891f096ab62071a8--5d4affeaa6344ae1a6b62beae5ad2de0 e7910ef194cf4a6ca354e1eb96344672 RX(theta₁₆) 5d4affeaa6344ae1a6b62beae5ad2de0--e7910ef194cf4a6ca354e1eb96344672 d3d73b30d8ae40c6ab44ee019e918f5c X e7910ef194cf4a6ca354e1eb96344672--d3d73b30d8ae40c6ab44ee019e918f5c d3d73b30d8ae40c6ab44ee019e918f5c--ae4381f1d82045229b095fddaf97e863 8b82472853604a9ab5004da4adfc4cda d3d73b30d8ae40c6ab44ee019e918f5c--8b82472853604a9ab5004da4adfc4cda cf09b9cb07284683827caba357333d07 AddBlock 8b82472853604a9ab5004da4adfc4cda--cf09b9cb07284683827caba357333d07 cf09b9cb07284683827caba357333d07--24226d447ba244f5ba3721aad96d5372 e0e8299530c84ee8bd93c08787c7bb27 36a2d57bc73f412e91a5858075fa156c RX(theta₂) eb51801949884bb086e2ba9147469e89--36a2d57bc73f412e91a5858075fa156c 72468be7173544bc836850ecacaa9eaa RY(theta₅) 36a2d57bc73f412e91a5858075fa156c--72468be7173544bc836850ecacaa9eaa b6e237d852ba4cfeb505bce486a7e471 RX(theta₈) 72468be7173544bc836850ecacaa9eaa--b6e237d852ba4cfeb505bce486a7e471 c5c23846ff4d437e8b2103533a973ec6 b6e237d852ba4cfeb505bce486a7e471--c5c23846ff4d437e8b2103533a973ec6 2138608a4abc4cd4bccf2307d47c62d0 X c5c23846ff4d437e8b2103533a973ec6--2138608a4abc4cd4bccf2307d47c62d0 2138608a4abc4cd4bccf2307d47c62d0--ebb3d88c0b734062aa5d92d1e8a97834 ee976c1c135147689b0d59fba5f38247 RX(theta₁₁) 2138608a4abc4cd4bccf2307d47c62d0--ee976c1c135147689b0d59fba5f38247 f3cb804872784d86a96eae5598ffc110 RY(theta₁₄) ee976c1c135147689b0d59fba5f38247--f3cb804872784d86a96eae5598ffc110 2e3738606c5c4013bf4c411ace02ebe9 RX(theta₁₇) f3cb804872784d86a96eae5598ffc110--2e3738606c5c4013bf4c411ace02ebe9 a6f026ce8272425694708986d9d0116a 2e3738606c5c4013bf4c411ace02ebe9--a6f026ce8272425694708986d9d0116a 1504b0814b224912bfb58ed2b7d70344 X a6f026ce8272425694708986d9d0116a--1504b0814b224912bfb58ed2b7d70344 1504b0814b224912bfb58ed2b7d70344--8b82472853604a9ab5004da4adfc4cda d26f23ae7a9e4b169f9c7835a3bcdfc7 1504b0814b224912bfb58ed2b7d70344--d26f23ae7a9e4b169f9c7835a3bcdfc7 d26f23ae7a9e4b169f9c7835a3bcdfc7--e0e8299530c84ee8bd93c08787c7bb27
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 cba42f64bfb7418094291bfd643a5f2b 0 44ce5f27c187461a902c22ba8444db94 cba42f64bfb7418094291bfd643a5f2b--44ce5f27c187461a902c22ba8444db94 d255c6c198404d15b2b7013339126446 1 a6c02aa347864754a7cd999045698563 f0bd4cd1df604fd1bbf051771af3bd04 44ce5f27c187461a902c22ba8444db94--f0bd4cd1df604fd1bbf051771af3bd04 5752703830ef47e1a254c9fec2a9243d a6c02aa347864754a7cd999045698563--5752703830ef47e1a254c9fec2a9243d c771a636be75469291fb2a9d192f4e8d fd2ee80336ef49cb9741e7276957bc6f 5752703830ef47e1a254c9fec2a9243d--fd2ee80336ef49cb9741e7276957bc6f fee001da5caa49329b1a0f34b9126e5a c771a636be75469291fb2a9d192f4e8d--fee001da5caa49329b1a0f34b9126e5a 9840ee065bc147189c0f300acd440dc3 615ad2bbf86e409a998ae2dc5480f7de d255c6c198404d15b2b7013339126446--615ad2bbf86e409a998ae2dc5480f7de 03cc4de955104dc28461544fac032e93 2 615ad2bbf86e409a998ae2dc5480f7de--a6c02aa347864754a7cd999045698563 1dfe9953ccb94078a3dac59542796bfb f0bd4cd1df604fd1bbf051771af3bd04--1dfe9953ccb94078a3dac59542796bfb 0031f3a1d29f4e2d98bc42b3989bfdba 1dfe9953ccb94078a3dac59542796bfb--0031f3a1d29f4e2d98bc42b3989bfdba 0031f3a1d29f4e2d98bc42b3989bfdba--9840ee065bc147189c0f300acd440dc3 2629cab2a1c449dba6b1bdd7a64ac266 4c6cffba857246feb7abaddf06190523 03cc4de955104dc28461544fac032e93--4c6cffba857246feb7abaddf06190523 56062e09cc9c442196e2c06d259e918d 3 0a91e4e5d2b945f9ad16424095423752 4c6cffba857246feb7abaddf06190523--0a91e4e5d2b945f9ad16424095423752 05682327d51b45efa1cdd0b25adbd1e4 0a91e4e5d2b945f9ad16424095423752--05682327d51b45efa1cdd0b25adbd1e4 f19fb638c6414ca3a4e7c372e4f9bc5b 05682327d51b45efa1cdd0b25adbd1e4--f19fb638c6414ca3a4e7c372e4f9bc5b f19fb638c6414ca3a4e7c372e4f9bc5b--2629cab2a1c449dba6b1bdd7a64ac266 02595b621df54c0c804a5d91bc84ef24 2fd8be7fe9f54f6591b732ff3f23b18a 56062e09cc9c442196e2c06d259e918d--2fd8be7fe9f54f6591b732ff3f23b18a 26c3cda71e3942f6972259bbe8d9c009 2fd8be7fe9f54f6591b732ff3f23b18a--26c3cda71e3942f6972259bbe8d9c009 2d9cac3a879846a588518522dae23175 26c3cda71e3942f6972259bbe8d9c009--2d9cac3a879846a588518522dae23175 2d9cac3a879846a588518522dae23175--c771a636be75469291fb2a9d192f4e8d fd2ee80336ef49cb9741e7276957bc6f--02595b621df54c0c804a5d91bc84ef24
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 bf1fb3854369411c83ccdaba0e5bd84a 0 72cc4b778d924b9b8a335f0bf21d8b40 bf1fb3854369411c83ccdaba0e5bd84a--72cc4b778d924b9b8a335f0bf21d8b40 97c7628997554cd18df63dda24faec2f 1 f944ae93f02f4ef5a8f4734c6fe81581 72cc4b778d924b9b8a335f0bf21d8b40--f944ae93f02f4ef5a8f4734c6fe81581 81ec73108d8c43208a83f3293e8f76b1 f944ae93f02f4ef5a8f4734c6fe81581--81ec73108d8c43208a83f3293e8f76b1 ea76e25b8eaa46d9b98d18198bb0fdf7 81ec73108d8c43208a83f3293e8f76b1--ea76e25b8eaa46d9b98d18198bb0fdf7 2f610ab244c842bfb1e1b692245e5077 c872c524942e41c2b3011f02e712c827 PHASE(0.5) 97c7628997554cd18df63dda24faec2f--c872c524942e41c2b3011f02e712c827 16c4674c72124ead9b9c032e1af48b65 2 c872c524942e41c2b3011f02e712c827--72cc4b778d924b9b8a335f0bf21d8b40 35d875111afc4828a06fb7bfbce98ab5 c872c524942e41c2b3011f02e712c827--35d875111afc4828a06fb7bfbce98ab5 09b1b7e9e143429a9ff921ea12eb0962 35d875111afc4828a06fb7bfbce98ab5--09b1b7e9e143429a9ff921ea12eb0962 09b1b7e9e143429a9ff921ea12eb0962--2f610ab244c842bfb1e1b692245e5077 f3487606dc9c4e36a11995c458b6cc80 3ec959b1eac6428e8e1535cb6a5163c0 16c4674c72124ead9b9c032e1af48b65--3ec959b1eac6428e8e1535cb6a5163c0 c8bb73916f5b40bba57d1c39176a3710 3 de056b4c83be4838b8adbf79f41f04a9 PHASE(0.5) 3ec959b1eac6428e8e1535cb6a5163c0--de056b4c83be4838b8adbf79f41f04a9 de056b4c83be4838b8adbf79f41f04a9--f944ae93f02f4ef5a8f4734c6fe81581 54f86d47b98b4e6282ca4f63e48aeae4 de056b4c83be4838b8adbf79f41f04a9--54f86d47b98b4e6282ca4f63e48aeae4 54f86d47b98b4e6282ca4f63e48aeae4--f3487606dc9c4e36a11995c458b6cc80 83617cc051284c6d9f712a5d56c67e64 b06a27c0c81c485fb25017574ac0a4b2 c8bb73916f5b40bba57d1c39176a3710--b06a27c0c81c485fb25017574ac0a4b2 dd58b0ce764e43538f2cc2a6a1ec8a02 b06a27c0c81c485fb25017574ac0a4b2--dd58b0ce764e43538f2cc2a6a1ec8a02 058543c93f58487d948b109dc80324d2 PHASE(0.5) dd58b0ce764e43538f2cc2a6a1ec8a02--058543c93f58487d948b109dc80324d2 058543c93f58487d948b109dc80324d2--81ec73108d8c43208a83f3293e8f76b1 058543c93f58487d948b109dc80324d2--83617cc051284c6d9f712a5d56c67e64

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