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 dbc0a05a650344f0980da33ab7c2700c 0 4d3bdde00cd0409185e24892adbd58a8 X dbc0a05a650344f0980da33ab7c2700c--4d3bdde00cd0409185e24892adbd58a8 610dbcebe5e54ceaacc1ad0ee2e0ec41 1 f6b45abd609d4931b14a3c646d9dc823 4d3bdde00cd0409185e24892adbd58a8--f6b45abd609d4931b14a3c646d9dc823 87927b3d54f247948f93b9df0724e66f 633f4a7981e9438fbe174e821207fbf8 Y 610dbcebe5e54ceaacc1ad0ee2e0ec41--633f4a7981e9438fbe174e821207fbf8 633f4a7981e9438fbe174e821207fbf8--87927b3d54f247948f93b9df0724e66f
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 88e577711cd54ea6a29a8513f771e381 0 a551f6d6a62f4310983b2e4b0fa49375 X 88e577711cd54ea6a29a8513f771e381--a551f6d6a62f4310983b2e4b0fa49375 50a1ef00550545a99376ec599b499e17 Y a551f6d6a62f4310983b2e4b0fa49375--50a1ef00550545a99376ec599b499e17 bac6fc7bc8a5488e946b53b39e8f1748 50a1ef00550545a99376ec599b499e17--bac6fc7bc8a5488e946b53b39e8f1748
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 d18f7a509cc84aa5b2cc4cfc13fcdc6c 0 7ab797b96c4542a4b81465bd4b09d460 X d18f7a509cc84aa5b2cc4cfc13fcdc6c--7ab797b96c4542a4b81465bd4b09d460 14d6c21f90424e049262dcb32d030c02 1 e0bb4987c2404dd8b79775dbe3569e24 7ab797b96c4542a4b81465bd4b09d460--e0bb4987c2404dd8b79775dbe3569e24 da01fc07bc6046aa93d03bd1e01262e0 e0bb4987c2404dd8b79775dbe3569e24--da01fc07bc6046aa93d03bd1e01262e0 e83e26ada4094029a36b1867c0de7087 1e26f8f2461041aeadc0dea30f37ef7e 14d6c21f90424e049262dcb32d030c02--1e26f8f2461041aeadc0dea30f37ef7e c39a0f0a9bf5489fb87dc1f5a284f4af Y 1e26f8f2461041aeadc0dea30f37ef7e--c39a0f0a9bf5489fb87dc1f5a284f4af c39a0f0a9bf5489fb87dc1f5a284f4af--e83e26ada4094029a36b1867c0de7087
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_abf1677ad92642a0bdfaef63124b664d 171c630acd3f4ce5a16adaf82986b0af 0 a8d9a9c84d4d496cacbe56bf95b063ca 171c630acd3f4ce5a16adaf82986b0af--a8d9a9c84d4d496cacbe56bf95b063ca c70a140aa32b43fd9c845051f8252533 1 9ff4ef1d19c442cbbd912d36ef1d74e0 a8d9a9c84d4d496cacbe56bf95b063ca--9ff4ef1d19c442cbbd912d36ef1d74e0 3645857142284aa4b96a5a73c37224a4 8c1041e591e947a1bec336c2fb583cdd AddBlock c70a140aa32b43fd9c845051f8252533--8c1041e591e947a1bec336c2fb583cdd a4926589fc7547bdb2af8fcea997f264 2 8c1041e591e947a1bec336c2fb583cdd--3645857142284aa4b96a5a73c37224a4 016fddefdc634207a317f9ac33dbd7e0 2cac47f4cfbe47029335b3dfa3589e81 a4926589fc7547bdb2af8fcea997f264--2cac47f4cfbe47029335b3dfa3589e81 2cac47f4cfbe47029335b3dfa3589e81--016fddefdc634207a317f9ac33dbd7e0
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_bae7ca2e94564dc8bdda02665b55d242 cluster_ff900d4c789c4e1aa4867167e365ce91 rx c27fdbc4949a488fa16870be77e47146 0 7d19773b2ddb4b51b95d61427a72f748 X c27fdbc4949a488fa16870be77e47146--7d19773b2ddb4b51b95d61427a72f748 2bb2f7098e264264822ab055b00ac2fc 1 44f6700b27fb48ff9df10ec1cd85a722 7d19773b2ddb4b51b95d61427a72f748--44f6700b27fb48ff9df10ec1cd85a722 322839682c9241a8bf8831c3beac4a2a 44f6700b27fb48ff9df10ec1cd85a722--322839682c9241a8bf8831c3beac4a2a 184590d280f34fca802e465ecc98be27 322839682c9241a8bf8831c3beac4a2a--184590d280f34fca802e465ecc98be27 d0dc11c61546457bba449a34e64d0a3d e7757f782f8c4742a7c345fa58f5e720 Y 2bb2f7098e264264822ab055b00ac2fc--e7757f782f8c4742a7c345fa58f5e720 9329956f479a4f57a55fe5274b2a057c 2 4768b817d4dd4aef9560b2d9b0d11255 e7757f782f8c4742a7c345fa58f5e720--4768b817d4dd4aef9560b2d9b0d11255 1e37abf365ae41a989f308e7f7be1f3a HamEvo 4768b817d4dd4aef9560b2d9b0d11255--1e37abf365ae41a989f308e7f7be1f3a 1e37abf365ae41a989f308e7f7be1f3a--d0dc11c61546457bba449a34e64d0a3d 8008dbde159a4061b0d09772a4d83af6 9d688dfa47ba47aa8976d2fb5764df73 RX(x) 9329956f479a4f57a55fe5274b2a057c--9d688dfa47ba47aa8976d2fb5764df73 75571718789a4915ad46125373b734b4 3 5374f33d0e214d7384689c9d95f13cd7 9d688dfa47ba47aa8976d2fb5764df73--5374f33d0e214d7384689c9d95f13cd7 da7b0aed0b7b487eb407cb8ee5aaa7e0 t = 10 5374f33d0e214d7384689c9d95f13cd7--da7b0aed0b7b487eb407cb8ee5aaa7e0 da7b0aed0b7b487eb407cb8ee5aaa7e0--8008dbde159a4061b0d09772a4d83af6 038eb82c3aa94989b5aa2c9ae8aa6b58 804f4d55254a4c2b8d5dcaa0c381ab7d RX(0.5) 75571718789a4915ad46125373b734b4--804f4d55254a4c2b8d5dcaa0c381ab7d dec98977ca9d4637a622a35b0e6d6229 X 804f4d55254a4c2b8d5dcaa0c381ab7d--dec98977ca9d4637a622a35b0e6d6229 dec98977ca9d4637a622a35b0e6d6229--5374f33d0e214d7384689c9d95f13cd7 275af91c3e5343be83cedfcaa118fb65 dec98977ca9d4637a622a35b0e6d6229--275af91c3e5343be83cedfcaa118fb65 275af91c3e5343be83cedfcaa118fb65--038eb82c3aa94989b5aa2c9ae8aa6b58
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_1c2032767d164bdeb3d235f1ecc6fa3c HEA cluster_09605a12a11b41148e9d3569dd63516a Tower Fourier FM 3a58aab2dd7645de969a179e49f1f966 0 67219c7916354eae8fab4645cac522cb RX(1.0*phi) 3a58aab2dd7645de969a179e49f1f966--67219c7916354eae8fab4645cac522cb eb7b03aa88814f7faf9e2e6331ef64dc 1 7d6bc35b46b94ed5b02d56e12dac2d8e RX(theta₀) 67219c7916354eae8fab4645cac522cb--7d6bc35b46b94ed5b02d56e12dac2d8e a932d0d58bae4e6794f6c592d861d170 RY(theta₄) 7d6bc35b46b94ed5b02d56e12dac2d8e--a932d0d58bae4e6794f6c592d861d170 b6d237081f1f49e5a55c985f4a72e1fe RX(theta₈) a932d0d58bae4e6794f6c592d861d170--b6d237081f1f49e5a55c985f4a72e1fe 3d4cf5ccda9c4fa08c32557d2dcd64a1 b6d237081f1f49e5a55c985f4a72e1fe--3d4cf5ccda9c4fa08c32557d2dcd64a1 eb00433bcdce4d4e9a75e07cd08c1900 3d4cf5ccda9c4fa08c32557d2dcd64a1--eb00433bcdce4d4e9a75e07cd08c1900 859a4ac5545a45d39cf1b14bdd495cae RX(theta₁₂) eb00433bcdce4d4e9a75e07cd08c1900--859a4ac5545a45d39cf1b14bdd495cae a5a3df54eff34a7c8637c0872a1cf61b RY(theta₁₆) 859a4ac5545a45d39cf1b14bdd495cae--a5a3df54eff34a7c8637c0872a1cf61b 35c3ce120c914405aca08368b5d61b40 RX(theta₂₀) a5a3df54eff34a7c8637c0872a1cf61b--35c3ce120c914405aca08368b5d61b40 b38729df49a744ef8d6e9edc8aab6068 35c3ce120c914405aca08368b5d61b40--b38729df49a744ef8d6e9edc8aab6068 df62418ff2854d058d472fbe28a263fd b38729df49a744ef8d6e9edc8aab6068--df62418ff2854d058d472fbe28a263fd 84ee6cceb483441c8faa57e308cd2cc4 df62418ff2854d058d472fbe28a263fd--84ee6cceb483441c8faa57e308cd2cc4 9dd1636163604248bf9db0ec8d8db8ed 10de51d544a34be7bf4c7f3a72f7f74a RX(2.0*phi) eb7b03aa88814f7faf9e2e6331ef64dc--10de51d544a34be7bf4c7f3a72f7f74a 847b5921e41744a48262477baa0476d6 2 c7c62cfcf8494a98b3934046c91aa21c RX(theta₁) 10de51d544a34be7bf4c7f3a72f7f74a--c7c62cfcf8494a98b3934046c91aa21c bdcfdc1c1c9749ffb395f37175452172 RY(theta₅) c7c62cfcf8494a98b3934046c91aa21c--bdcfdc1c1c9749ffb395f37175452172 efa454bdb5f34160a8f87a352e69f9a2 RX(theta₉) bdcfdc1c1c9749ffb395f37175452172--efa454bdb5f34160a8f87a352e69f9a2 16b3814fb79745a6a3b4a5225060e5cc X efa454bdb5f34160a8f87a352e69f9a2--16b3814fb79745a6a3b4a5225060e5cc 16b3814fb79745a6a3b4a5225060e5cc--3d4cf5ccda9c4fa08c32557d2dcd64a1 477bc688ce2e4364868f959820dd4638 16b3814fb79745a6a3b4a5225060e5cc--477bc688ce2e4364868f959820dd4638 612400595a2741ddbe5cb1ee5dc5bcae RX(theta₁₃) 477bc688ce2e4364868f959820dd4638--612400595a2741ddbe5cb1ee5dc5bcae 8acea4e287a34a23801da63379db03b7 RY(theta₁₇) 612400595a2741ddbe5cb1ee5dc5bcae--8acea4e287a34a23801da63379db03b7 09bd940e818d405198d3f68b2e09bc7c RX(theta₂₁) 8acea4e287a34a23801da63379db03b7--09bd940e818d405198d3f68b2e09bc7c a036adf3434249d7bcd00950a9d344f4 X 09bd940e818d405198d3f68b2e09bc7c--a036adf3434249d7bcd00950a9d344f4 a036adf3434249d7bcd00950a9d344f4--b38729df49a744ef8d6e9edc8aab6068 edd0b8532f7242828411222817a113e6 a036adf3434249d7bcd00950a9d344f4--edd0b8532f7242828411222817a113e6 edd0b8532f7242828411222817a113e6--9dd1636163604248bf9db0ec8d8db8ed 8ff84828fd084e118ac7a047e28f1a97 6cf3621bd7df40b1a2d13d4685026075 RX(3.0*phi) 847b5921e41744a48262477baa0476d6--6cf3621bd7df40b1a2d13d4685026075 6d6fa32b1eec4b95b0b2952626b75326 3 f61c360df2c84debb2562a5409afcf4f RX(theta₂) 6cf3621bd7df40b1a2d13d4685026075--f61c360df2c84debb2562a5409afcf4f 8615ed3f8f1a49d4b4df4d77777fb7fb RY(theta₆) f61c360df2c84debb2562a5409afcf4f--8615ed3f8f1a49d4b4df4d77777fb7fb e4c79767864d42b1a1b32ff5a04d3586 RX(theta₁₀) 8615ed3f8f1a49d4b4df4d77777fb7fb--e4c79767864d42b1a1b32ff5a04d3586 afa14f175a2941609756f7007e9c82f9 e4c79767864d42b1a1b32ff5a04d3586--afa14f175a2941609756f7007e9c82f9 648ff42350624e3fbc981a89637fc23c X afa14f175a2941609756f7007e9c82f9--648ff42350624e3fbc981a89637fc23c 648ff42350624e3fbc981a89637fc23c--477bc688ce2e4364868f959820dd4638 725f77127cad423db51ee06a9e6eaed3 RX(theta₁₄) 648ff42350624e3fbc981a89637fc23c--725f77127cad423db51ee06a9e6eaed3 68b05f41558e47168e8b78992dcc5010 RY(theta₁₈) 725f77127cad423db51ee06a9e6eaed3--68b05f41558e47168e8b78992dcc5010 f682a613a3b1467a95648334d7bfbd8e RX(theta₂₂) 68b05f41558e47168e8b78992dcc5010--f682a613a3b1467a95648334d7bfbd8e 8e876e54f9a04898a29a48714d0206b0 f682a613a3b1467a95648334d7bfbd8e--8e876e54f9a04898a29a48714d0206b0 dc0b77dcd8134ab0aff4e462dc44089c X 8e876e54f9a04898a29a48714d0206b0--dc0b77dcd8134ab0aff4e462dc44089c dc0b77dcd8134ab0aff4e462dc44089c--edd0b8532f7242828411222817a113e6 dc0b77dcd8134ab0aff4e462dc44089c--8ff84828fd084e118ac7a047e28f1a97 cde594c6ab9943188cb3948bca8252af 06a69ca1eb1746c0891e852ba4a8883f RX(4.0*phi) 6d6fa32b1eec4b95b0b2952626b75326--06a69ca1eb1746c0891e852ba4a8883f 56de4459259f4874a391a01c771a8b7b RX(theta₃) 06a69ca1eb1746c0891e852ba4a8883f--56de4459259f4874a391a01c771a8b7b 4c345fbe459a4e97bdf8e1eeac0e330f RY(theta₇) 56de4459259f4874a391a01c771a8b7b--4c345fbe459a4e97bdf8e1eeac0e330f 4c70673e20b34c4ea4355e9649da94c9 RX(theta₁₁) 4c345fbe459a4e97bdf8e1eeac0e330f--4c70673e20b34c4ea4355e9649da94c9 99b9f766568943fcad40aca3d2097083 X 4c70673e20b34c4ea4355e9649da94c9--99b9f766568943fcad40aca3d2097083 99b9f766568943fcad40aca3d2097083--afa14f175a2941609756f7007e9c82f9 b4abd18a1ba64bbc89bd59af4f55b5f7 99b9f766568943fcad40aca3d2097083--b4abd18a1ba64bbc89bd59af4f55b5f7 2d39c55cc1e94ce9bec7efad7de78c4f RX(theta₁₅) b4abd18a1ba64bbc89bd59af4f55b5f7--2d39c55cc1e94ce9bec7efad7de78c4f 25e5c247be28434f8430e584912bee22 RY(theta₁₉) 2d39c55cc1e94ce9bec7efad7de78c4f--25e5c247be28434f8430e584912bee22 4ef87def19234135b9a0c9a6de19b47c RX(theta₂₃) 25e5c247be28434f8430e584912bee22--4ef87def19234135b9a0c9a6de19b47c 8f66e7189f2245afa7d3759fce12734b X 4ef87def19234135b9a0c9a6de19b47c--8f66e7189f2245afa7d3759fce12734b 8f66e7189f2245afa7d3759fce12734b--8e876e54f9a04898a29a48714d0206b0 0046357906c94ba0b51ae4e3a3272a06 8f66e7189f2245afa7d3759fce12734b--0046357906c94ba0b51ae4e3a3272a06 0046357906c94ba0b51ae4e3a3272a06--cde594c6ab9943188cb3948bca8252af
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_fc283b0afa494409b095eb7fd42faec5 Obs. cluster_48ac74e75f0c4bfd8c6d43324434084b cluster_2ff62255c89f4450b7c0d760e1abcf77 HEA e6d165f093594ec18c691fbdb2b56f37 0 9fe6f848702f4124a5acefd92941d67c RX(theta₀) e6d165f093594ec18c691fbdb2b56f37--9fe6f848702f4124a5acefd92941d67c 66144446489e4e47be6cc6e60f2a2aeb 1 a4488784a72a4b6c9199a41e8d2ff9ba RY(theta₃) 9fe6f848702f4124a5acefd92941d67c--a4488784a72a4b6c9199a41e8d2ff9ba a1a97d2c10954cc2a38e137cbf5c9b81 RX(theta₆) a4488784a72a4b6c9199a41e8d2ff9ba--a1a97d2c10954cc2a38e137cbf5c9b81 2af9c60f913b47e180ebd67c20eb0efb a1a97d2c10954cc2a38e137cbf5c9b81--2af9c60f913b47e180ebd67c20eb0efb 87c8d03ad8144e7f8bef7652dbd7fbf8 2af9c60f913b47e180ebd67c20eb0efb--87c8d03ad8144e7f8bef7652dbd7fbf8 45c84584a51e4bf2845b9f751c7c6ee8 RX(theta₉) 87c8d03ad8144e7f8bef7652dbd7fbf8--45c84584a51e4bf2845b9f751c7c6ee8 8c8f474060944a60a132d9273e2a4ad7 RY(theta₁₂) 45c84584a51e4bf2845b9f751c7c6ee8--8c8f474060944a60a132d9273e2a4ad7 99bb00d4eedc4e0a9133cfa41b9bf940 RX(theta₁₅) 8c8f474060944a60a132d9273e2a4ad7--99bb00d4eedc4e0a9133cfa41b9bf940 aca25ee6692f41729b699c709f27bfc9 99bb00d4eedc4e0a9133cfa41b9bf940--aca25ee6692f41729b699c709f27bfc9 2be007a4c03e46299e729edc7c9b58fc aca25ee6692f41729b699c709f27bfc9--2be007a4c03e46299e729edc7c9b58fc 31089fb5455944c3862a7ff69ea887c2 2be007a4c03e46299e729edc7c9b58fc--31089fb5455944c3862a7ff69ea887c2 42122bb501414e3da388a29b1dcd5d7f 31089fb5455944c3862a7ff69ea887c2--42122bb501414e3da388a29b1dcd5d7f bba2d934bdf344f5842a79bd9418bc5a 8ed5a0c17cbb491287e915a9e4921204 RX(theta₁) 66144446489e4e47be6cc6e60f2a2aeb--8ed5a0c17cbb491287e915a9e4921204 c6cac8e61acc4f85bc4b52242ccf3b09 2 01cff552ef914015a6c0fcd6b51f564b RY(theta₄) 8ed5a0c17cbb491287e915a9e4921204--01cff552ef914015a6c0fcd6b51f564b 36b67b677d4743c896b5cdf0c1c7a089 RX(theta₇) 01cff552ef914015a6c0fcd6b51f564b--36b67b677d4743c896b5cdf0c1c7a089 56765e7df3b94fd085d3cd6c9dfab611 X 36b67b677d4743c896b5cdf0c1c7a089--56765e7df3b94fd085d3cd6c9dfab611 56765e7df3b94fd085d3cd6c9dfab611--2af9c60f913b47e180ebd67c20eb0efb d749745ccd234668bf3468c0c5593678 56765e7df3b94fd085d3cd6c9dfab611--d749745ccd234668bf3468c0c5593678 62ce6b934b7441cc91636f590aeca8d5 RX(theta₁₀) d749745ccd234668bf3468c0c5593678--62ce6b934b7441cc91636f590aeca8d5 05b7532d5b08425e92120c4ebc852746 RY(theta₁₃) 62ce6b934b7441cc91636f590aeca8d5--05b7532d5b08425e92120c4ebc852746 a677a155812a40e7b64c37e1cd980325 RX(theta₁₆) 05b7532d5b08425e92120c4ebc852746--a677a155812a40e7b64c37e1cd980325 bf61922d5e8246e6a4b16b3b69f9febe X a677a155812a40e7b64c37e1cd980325--bf61922d5e8246e6a4b16b3b69f9febe bf61922d5e8246e6a4b16b3b69f9febe--aca25ee6692f41729b699c709f27bfc9 8878bf35aac54951bb14a1b25c964cbb bf61922d5e8246e6a4b16b3b69f9febe--8878bf35aac54951bb14a1b25c964cbb af869fa4452042e684f971a997b100fa AddBlock 8878bf35aac54951bb14a1b25c964cbb--af869fa4452042e684f971a997b100fa af869fa4452042e684f971a997b100fa--bba2d934bdf344f5842a79bd9418bc5a 595c4427a2c545a394e1b7b9003f1528 ed9aeb86959449d293f13fce3783d319 RX(theta₂) c6cac8e61acc4f85bc4b52242ccf3b09--ed9aeb86959449d293f13fce3783d319 9a7a049e896e49999de8f04060252c75 RY(theta₅) ed9aeb86959449d293f13fce3783d319--9a7a049e896e49999de8f04060252c75 09e489e348c047cd896a7c479bf87544 RX(theta₈) 9a7a049e896e49999de8f04060252c75--09e489e348c047cd896a7c479bf87544 e2729aede62b45199c8df8f11eb53636 09e489e348c047cd896a7c479bf87544--e2729aede62b45199c8df8f11eb53636 ffe24720e4b0491f93a3d76ebd5270ba X e2729aede62b45199c8df8f11eb53636--ffe24720e4b0491f93a3d76ebd5270ba ffe24720e4b0491f93a3d76ebd5270ba--d749745ccd234668bf3468c0c5593678 9749740a58b14a4aae84868da00b29ba RX(theta₁₁) ffe24720e4b0491f93a3d76ebd5270ba--9749740a58b14a4aae84868da00b29ba 9a88255e07ce4af49f6e71b6782eb8ff RY(theta₁₄) 9749740a58b14a4aae84868da00b29ba--9a88255e07ce4af49f6e71b6782eb8ff 6622070f9344456491e54eee77594d16 RX(theta₁₇) 9a88255e07ce4af49f6e71b6782eb8ff--6622070f9344456491e54eee77594d16 1364de5f7fdf4931833dae9db11446f3 6622070f9344456491e54eee77594d16--1364de5f7fdf4931833dae9db11446f3 c8b7e0f9267e4603a85fe26a3b454c66 X 1364de5f7fdf4931833dae9db11446f3--c8b7e0f9267e4603a85fe26a3b454c66 c8b7e0f9267e4603a85fe26a3b454c66--8878bf35aac54951bb14a1b25c964cbb 2cbfa8d55eae471abdf790300dc1a5b1 c8b7e0f9267e4603a85fe26a3b454c66--2cbfa8d55eae471abdf790300dc1a5b1 2cbfa8d55eae471abdf790300dc1a5b1--595c4427a2c545a394e1b7b9003f1528
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 4147e01468aa4d8baa9cf68ee7379bf8 0 8829f903c3ea4564b5ef2321118069a7 4147e01468aa4d8baa9cf68ee7379bf8--8829f903c3ea4564b5ef2321118069a7 b2b0da1a2f094807bc0223d57c72c47b 1 186655bdcec5423d9f2d43cb5540f073 39801f3767c8426c904c862b2d27b428 8829f903c3ea4564b5ef2321118069a7--39801f3767c8426c904c862b2d27b428 86af36394bba4cd6a72b5cbfcc7d4aaa 186655bdcec5423d9f2d43cb5540f073--86af36394bba4cd6a72b5cbfcc7d4aaa 23d4f6005a9e44b9a189bd8a5830cb57 206972c18ae7496cafbad730086f0250 86af36394bba4cd6a72b5cbfcc7d4aaa--206972c18ae7496cafbad730086f0250 af6044b7bf384a7194e279f6f2e69cef 23d4f6005a9e44b9a189bd8a5830cb57--af6044b7bf384a7194e279f6f2e69cef 472a3253c5284da0b5b19d28e5ba2787 f039df29aa614d6c9835410f2a12eb5c b2b0da1a2f094807bc0223d57c72c47b--f039df29aa614d6c9835410f2a12eb5c 4156a45592ce40bd8a79e5969d1ae85a 2 f039df29aa614d6c9835410f2a12eb5c--186655bdcec5423d9f2d43cb5540f073 3777bb03b0c24ebda80a03b999238be5 39801f3767c8426c904c862b2d27b428--3777bb03b0c24ebda80a03b999238be5 09f4a64c8daf4620b92af0e69809cb15 3777bb03b0c24ebda80a03b999238be5--09f4a64c8daf4620b92af0e69809cb15 09f4a64c8daf4620b92af0e69809cb15--472a3253c5284da0b5b19d28e5ba2787 fe0f36cdcea04162b62f5f9d974c77bd c851197283374cb8a9805e4b44bb98e8 4156a45592ce40bd8a79e5969d1ae85a--c851197283374cb8a9805e4b44bb98e8 7d6197df92c24c4087561b06235b292a 3 20b0196308134f6290722c289bf6c518 c851197283374cb8a9805e4b44bb98e8--20b0196308134f6290722c289bf6c518 7d010dbe2a014e7f82fe5ae386e27f22 20b0196308134f6290722c289bf6c518--7d010dbe2a014e7f82fe5ae386e27f22 c752e8b8cbbc42e090d7b21afad30966 7d010dbe2a014e7f82fe5ae386e27f22--c752e8b8cbbc42e090d7b21afad30966 c752e8b8cbbc42e090d7b21afad30966--fe0f36cdcea04162b62f5f9d974c77bd 442c3747d782445ea3e2904f8626f0a9 9587d38bf16247c395b8d0618d189585 7d6197df92c24c4087561b06235b292a--9587d38bf16247c395b8d0618d189585 2457cb46d8034aa7813ca589c5a380c0 9587d38bf16247c395b8d0618d189585--2457cb46d8034aa7813ca589c5a380c0 e04ee714a6ef4a53830c8e8183b21924 2457cb46d8034aa7813ca589c5a380c0--e04ee714a6ef4a53830c8e8183b21924 e04ee714a6ef4a53830c8e8183b21924--23d4f6005a9e44b9a189bd8a5830cb57 206972c18ae7496cafbad730086f0250--442c3747d782445ea3e2904f8626f0a9
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 ea845a41068a4a94a9b89eafe88c577a 0 a30d88ae708f42f9b949573ba9e5a2dd ea845a41068a4a94a9b89eafe88c577a--a30d88ae708f42f9b949573ba9e5a2dd 2efe2434a7984b1fbd898802e011800f 1 376d4c4f7fc64a789ef0fe168a441311 a30d88ae708f42f9b949573ba9e5a2dd--376d4c4f7fc64a789ef0fe168a441311 071b6d482c2d4fa2b0ad2d21ec1d8682 376d4c4f7fc64a789ef0fe168a441311--071b6d482c2d4fa2b0ad2d21ec1d8682 c842645e23274d60b520e448dc593895 071b6d482c2d4fa2b0ad2d21ec1d8682--c842645e23274d60b520e448dc593895 d646e09fb95841899f0e3e4d175b375f 2e43fe7b04244948a914332f945d3529 PHASE(0.5) 2efe2434a7984b1fbd898802e011800f--2e43fe7b04244948a914332f945d3529 42a4870bae754ae7926f35c0fc5150d6 2 2e43fe7b04244948a914332f945d3529--a30d88ae708f42f9b949573ba9e5a2dd 2d1593ba2d7b4fc187a87541aa64dd86 2e43fe7b04244948a914332f945d3529--2d1593ba2d7b4fc187a87541aa64dd86 a9ef3d360dcc48789a73894cb0da2e5f 2d1593ba2d7b4fc187a87541aa64dd86--a9ef3d360dcc48789a73894cb0da2e5f a9ef3d360dcc48789a73894cb0da2e5f--d646e09fb95841899f0e3e4d175b375f bbc86f093ae24bfb91b8ead8b806c411 635d0ef10a1b4149b9201472b51d5a2e 42a4870bae754ae7926f35c0fc5150d6--635d0ef10a1b4149b9201472b51d5a2e 5241fcb6552745e489d513a5a0a669c0 3 480ef8420c674c70bf804828b31d3843 PHASE(0.5) 635d0ef10a1b4149b9201472b51d5a2e--480ef8420c674c70bf804828b31d3843 480ef8420c674c70bf804828b31d3843--376d4c4f7fc64a789ef0fe168a441311 94d417d5d8dc4729be6e393711fab2b4 480ef8420c674c70bf804828b31d3843--94d417d5d8dc4729be6e393711fab2b4 94d417d5d8dc4729be6e393711fab2b4--bbc86f093ae24bfb91b8ead8b806c411 99dbf0a3396546e6b2b9f7b942f4130c 3508b599e77b42e986e4bb9e946dc829 5241fcb6552745e489d513a5a0a669c0--3508b599e77b42e986e4bb9e946dc829 87abdaf1e9e5414289fe0df0652ed21d 3508b599e77b42e986e4bb9e946dc829--87abdaf1e9e5414289fe0df0652ed21d 4b98478324fe4548b7dfcb31c8c00286 PHASE(0.5) 87abdaf1e9e5414289fe0df0652ed21d--4b98478324fe4548b7dfcb31c8c00286 4b98478324fe4548b7dfcb31c8c00286--071b6d482c2d4fa2b0ad2d21ec1d8682 4b98478324fe4548b7dfcb31c8c00286--99dbf0a3396546e6b2b9f7b942f4130c

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