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 af40f084c7134d78bfa73d13b2570610 0 7426481cca3c4756978af615045eeba4 X af40f084c7134d78bfa73d13b2570610--7426481cca3c4756978af615045eeba4 d9a7d875941d4597805d6b18c154c46e 1 450d88cb083b4b6f849b09283561305f 7426481cca3c4756978af615045eeba4--450d88cb083b4b6f849b09283561305f 57b3eebd2032478fbc422a5454a3e5f3 b2c0d0ae55e0495da529ddf6b7522da1 Y d9a7d875941d4597805d6b18c154c46e--b2c0d0ae55e0495da529ddf6b7522da1 b2c0d0ae55e0495da529ddf6b7522da1--57b3eebd2032478fbc422a5454a3e5f3
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 e1d16482ed1d4728b5565769ff4a4370 0 b59890886b4f43d59a4217033c4370a2 X e1d16482ed1d4728b5565769ff4a4370--b59890886b4f43d59a4217033c4370a2 483e02112ef64d55bd0a808a6ec87410 Y b59890886b4f43d59a4217033c4370a2--483e02112ef64d55bd0a808a6ec87410 0dc6987b41a34639ae4386ca5c938edd 483e02112ef64d55bd0a808a6ec87410--0dc6987b41a34639ae4386ca5c938edd
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 95595cd501e04ab1a51e4a4c2e4bcb99 0 977ff982042e44c28fb9c01388280f55 X 95595cd501e04ab1a51e4a4c2e4bcb99--977ff982042e44c28fb9c01388280f55 a3424b6b29e84e1d9713481af23c849a 1 91ddf4377df942b3a5b8a4b35d8d4a92 977ff982042e44c28fb9c01388280f55--91ddf4377df942b3a5b8a4b35d8d4a92 3c1faf5e886940cf920ae69c146e5305 91ddf4377df942b3a5b8a4b35d8d4a92--3c1faf5e886940cf920ae69c146e5305 863a7c0af1e649fbadaa40c75b3469e5 63eef9b9b2c44421bb11e2dde3c26f8c a3424b6b29e84e1d9713481af23c849a--63eef9b9b2c44421bb11e2dde3c26f8c bb303eda6e0849e3ac39bb9fbfbed87e Y 63eef9b9b2c44421bb11e2dde3c26f8c--bb303eda6e0849e3ac39bb9fbfbed87e bb303eda6e0849e3ac39bb9fbfbed87e--863a7c0af1e649fbadaa40c75b3469e5
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_d6c57a5ddb044de9b339203c51337b7e afae128a1e2b4e2a96373fa0552bc7d7 0 e2fbcfb0f8b74019851cf8ebd42c41d7 afae128a1e2b4e2a96373fa0552bc7d7--e2fbcfb0f8b74019851cf8ebd42c41d7 a905211af02e453a9c219015b4f8ff83 1 4edd9cadac0b43c7901fc3e813aa639e e2fbcfb0f8b74019851cf8ebd42c41d7--4edd9cadac0b43c7901fc3e813aa639e e9a5d1bb678a436f86bb795181d3a1d5 f54e4983a21e4a9ca369f7e2d7b78775 AddBlock a905211af02e453a9c219015b4f8ff83--f54e4983a21e4a9ca369f7e2d7b78775 56aff43abdd1431e809f1ff600dacd0a 2 f54e4983a21e4a9ca369f7e2d7b78775--e9a5d1bb678a436f86bb795181d3a1d5 8697921fa94f4810a1454163d5dc8690 a916797e5d594401b178cd9ffce981e7 56aff43abdd1431e809f1ff600dacd0a--a916797e5d594401b178cd9ffce981e7 a916797e5d594401b178cd9ffce981e7--8697921fa94f4810a1454163d5dc8690
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_00d077d94e6e492bb8975b61cbd85ef7 cluster_785d85ee84854fcc82d4dec14f218f06 rx 9aff68d4c93947e39442f02477860cb9 0 fc6931b7186342fca280086787344f5f X 9aff68d4c93947e39442f02477860cb9--fc6931b7186342fca280086787344f5f 30b849535ded4266af42131c1c090761 1 7c2bd291a4644a8492b1df461bd0ab36 fc6931b7186342fca280086787344f5f--7c2bd291a4644a8492b1df461bd0ab36 f318d1517d704f75b6582a900117329a 7c2bd291a4644a8492b1df461bd0ab36--f318d1517d704f75b6582a900117329a d53de34151c14d85ad6e05236a7bf296 f318d1517d704f75b6582a900117329a--d53de34151c14d85ad6e05236a7bf296 c9836e39e6394791875697e9180ee934 e600c6266e064623b8d66772f9c040bf Y 30b849535ded4266af42131c1c090761--e600c6266e064623b8d66772f9c040bf 4e872d5818ad4e6393a68c1449aba181 2 1ff88556d36940ac8a734124bf750d73 e600c6266e064623b8d66772f9c040bf--1ff88556d36940ac8a734124bf750d73 f30d6ab94c2c4e4a9ca66024985cc0e7 HamEvo 1ff88556d36940ac8a734124bf750d73--f30d6ab94c2c4e4a9ca66024985cc0e7 f30d6ab94c2c4e4a9ca66024985cc0e7--c9836e39e6394791875697e9180ee934 bfab29746db9480aa543c1601eb3ef18 2c93294aa33d4e5192aaa2144b8acdc5 RX(x) 4e872d5818ad4e6393a68c1449aba181--2c93294aa33d4e5192aaa2144b8acdc5 e0ffafb21c2c4e8e8220aba7f36cb4b1 3 8631266d5f614565b0032d0fc4867441 2c93294aa33d4e5192aaa2144b8acdc5--8631266d5f614565b0032d0fc4867441 277ce76ec19d49e0bb32a1392ca3f5e3 t = 10 8631266d5f614565b0032d0fc4867441--277ce76ec19d49e0bb32a1392ca3f5e3 277ce76ec19d49e0bb32a1392ca3f5e3--bfab29746db9480aa543c1601eb3ef18 936c53f206764f82a7a124f9eb0ce66a bc7a01d02c254cc1be87604874a1f45a RX(0.5) e0ffafb21c2c4e8e8220aba7f36cb4b1--bc7a01d02c254cc1be87604874a1f45a 7c792f38c9db4feda13a0972d8f1f578 X bc7a01d02c254cc1be87604874a1f45a--7c792f38c9db4feda13a0972d8f1f578 7c792f38c9db4feda13a0972d8f1f578--8631266d5f614565b0032d0fc4867441 3f2ec259b2254711bfbad38edb0cf92a 7c792f38c9db4feda13a0972d8f1f578--3f2ec259b2254711bfbad38edb0cf92a 3f2ec259b2254711bfbad38edb0cf92a--936c53f206764f82a7a124f9eb0ce66a
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_0bf9e37453194870b088f0185108653d HEA cluster_3a36799d36994ce2b8063c39220600ca Tower Fourier FM 7bc135ff1dbf4e5b85b98f3c10a38571 0 183594c4934c47df8af32dddd5b697ab RX(1.0*phi) 7bc135ff1dbf4e5b85b98f3c10a38571--183594c4934c47df8af32dddd5b697ab 5ac559c2dd874be4a01ce59ed83479be 1 e2846bac6c0848d1a69e3f5de21d4781 RX(theta₀) 183594c4934c47df8af32dddd5b697ab--e2846bac6c0848d1a69e3f5de21d4781 6bdb7fd914f64bcd95b2ce811162ced3 RY(theta₄) e2846bac6c0848d1a69e3f5de21d4781--6bdb7fd914f64bcd95b2ce811162ced3 d6213ba8aaa24398b8190e0deb966344 RX(theta₈) 6bdb7fd914f64bcd95b2ce811162ced3--d6213ba8aaa24398b8190e0deb966344 bc8d48d7b44342bcb3f9fccb55539d40 d6213ba8aaa24398b8190e0deb966344--bc8d48d7b44342bcb3f9fccb55539d40 3df33415ec2b49c8a4217b909d7ac59f bc8d48d7b44342bcb3f9fccb55539d40--3df33415ec2b49c8a4217b909d7ac59f da8ae65687724debb76cb522da0f87c6 RX(theta₁₂) 3df33415ec2b49c8a4217b909d7ac59f--da8ae65687724debb76cb522da0f87c6 122417f9206b4e51ab46e14f863639ba RY(theta₁₆) da8ae65687724debb76cb522da0f87c6--122417f9206b4e51ab46e14f863639ba f24017504e1e4f888a073b5188a7d72d RX(theta₂₀) 122417f9206b4e51ab46e14f863639ba--f24017504e1e4f888a073b5188a7d72d 964e72011d36461b83b19ca8af775dd2 f24017504e1e4f888a073b5188a7d72d--964e72011d36461b83b19ca8af775dd2 9fd7768405cb4f828f8ea9dbfee69b02 964e72011d36461b83b19ca8af775dd2--9fd7768405cb4f828f8ea9dbfee69b02 27ab6d70eb9246e5aede5db8b8426ccb 9fd7768405cb4f828f8ea9dbfee69b02--27ab6d70eb9246e5aede5db8b8426ccb 33d6282ff85844b0a8685fd998adc678 a0c4c4a9c2db4e839a4c7ed090df6c1e RX(2.0*phi) 5ac559c2dd874be4a01ce59ed83479be--a0c4c4a9c2db4e839a4c7ed090df6c1e 4d0d586815e04476963971f91f7d4706 2 cbc4b34f4ee94c20872b296e537c784a RX(theta₁) a0c4c4a9c2db4e839a4c7ed090df6c1e--cbc4b34f4ee94c20872b296e537c784a c5600f93b9fc4409a61a3d538b562415 RY(theta₅) cbc4b34f4ee94c20872b296e537c784a--c5600f93b9fc4409a61a3d538b562415 e7117cbd685e479597730520fbe1683b RX(theta₉) c5600f93b9fc4409a61a3d538b562415--e7117cbd685e479597730520fbe1683b f8ed2d17ff1148b8aea7fff5395f5d35 X e7117cbd685e479597730520fbe1683b--f8ed2d17ff1148b8aea7fff5395f5d35 f8ed2d17ff1148b8aea7fff5395f5d35--bc8d48d7b44342bcb3f9fccb55539d40 352b034b858e40898e5a9ab5e9a3090e f8ed2d17ff1148b8aea7fff5395f5d35--352b034b858e40898e5a9ab5e9a3090e 01b70e84db5245f68a0d8d2a2e7728ad RX(theta₁₃) 352b034b858e40898e5a9ab5e9a3090e--01b70e84db5245f68a0d8d2a2e7728ad aec0aadbd9a740e2b8d9151ae2473d82 RY(theta₁₇) 01b70e84db5245f68a0d8d2a2e7728ad--aec0aadbd9a740e2b8d9151ae2473d82 b924f383989d4d6a92698552e331a464 RX(theta₂₁) aec0aadbd9a740e2b8d9151ae2473d82--b924f383989d4d6a92698552e331a464 0f5d47bfadff4aab93437a22ab93d217 X b924f383989d4d6a92698552e331a464--0f5d47bfadff4aab93437a22ab93d217 0f5d47bfadff4aab93437a22ab93d217--964e72011d36461b83b19ca8af775dd2 34e3ed0bb2a9477391f4871606b72cc6 0f5d47bfadff4aab93437a22ab93d217--34e3ed0bb2a9477391f4871606b72cc6 34e3ed0bb2a9477391f4871606b72cc6--33d6282ff85844b0a8685fd998adc678 ff531eb9757748808e3a38cc8cc995d8 a0453c7beb5643c78b798181941702f9 RX(3.0*phi) 4d0d586815e04476963971f91f7d4706--a0453c7beb5643c78b798181941702f9 61f4fdcfff024abd9438d9618f3614f1 3 518ce26733664d74ad7c21834ac7cd40 RX(theta₂) a0453c7beb5643c78b798181941702f9--518ce26733664d74ad7c21834ac7cd40 deec5f1fac1f4845bf77ab217f131624 RY(theta₆) 518ce26733664d74ad7c21834ac7cd40--deec5f1fac1f4845bf77ab217f131624 8f473c29f313483892a4a00bdbe32699 RX(theta₁₀) deec5f1fac1f4845bf77ab217f131624--8f473c29f313483892a4a00bdbe32699 feca9ede64d2486c891d0f4da84aaeb8 8f473c29f313483892a4a00bdbe32699--feca9ede64d2486c891d0f4da84aaeb8 67a0f2e82d174617b92b7f081ca9e617 X feca9ede64d2486c891d0f4da84aaeb8--67a0f2e82d174617b92b7f081ca9e617 67a0f2e82d174617b92b7f081ca9e617--352b034b858e40898e5a9ab5e9a3090e f4ea4527153e415c8174a70b1d1c6ee9 RX(theta₁₄) 67a0f2e82d174617b92b7f081ca9e617--f4ea4527153e415c8174a70b1d1c6ee9 702e74eb08914f35be1989a228e42b4e RY(theta₁₈) f4ea4527153e415c8174a70b1d1c6ee9--702e74eb08914f35be1989a228e42b4e 61e5d554432147389242395b254880e8 RX(theta₂₂) 702e74eb08914f35be1989a228e42b4e--61e5d554432147389242395b254880e8 21a8b9a5989547dc9e71a4918fb1964a 61e5d554432147389242395b254880e8--21a8b9a5989547dc9e71a4918fb1964a b0a8a5f53aff44d7ac4886ddcc609f91 X 21a8b9a5989547dc9e71a4918fb1964a--b0a8a5f53aff44d7ac4886ddcc609f91 b0a8a5f53aff44d7ac4886ddcc609f91--34e3ed0bb2a9477391f4871606b72cc6 b0a8a5f53aff44d7ac4886ddcc609f91--ff531eb9757748808e3a38cc8cc995d8 8ba14986b938474882a5c27daa4dc01a b035c77acde244029c40e887a724dc45 RX(4.0*phi) 61f4fdcfff024abd9438d9618f3614f1--b035c77acde244029c40e887a724dc45 7cd37fef016f43a5ae9eaeb7cf1fc191 RX(theta₃) b035c77acde244029c40e887a724dc45--7cd37fef016f43a5ae9eaeb7cf1fc191 a2795b670a794fadba6274c92bf45573 RY(theta₇) 7cd37fef016f43a5ae9eaeb7cf1fc191--a2795b670a794fadba6274c92bf45573 ff01d33e0e674b6796032659a196633e RX(theta₁₁) a2795b670a794fadba6274c92bf45573--ff01d33e0e674b6796032659a196633e 0b5c4e6e19ff4f72aca7c800548d3ce8 X ff01d33e0e674b6796032659a196633e--0b5c4e6e19ff4f72aca7c800548d3ce8 0b5c4e6e19ff4f72aca7c800548d3ce8--feca9ede64d2486c891d0f4da84aaeb8 15ec39e27f2c4555a3580070782280db 0b5c4e6e19ff4f72aca7c800548d3ce8--15ec39e27f2c4555a3580070782280db 0b2a325b5b08433eafc6094c853e919e RX(theta₁₅) 15ec39e27f2c4555a3580070782280db--0b2a325b5b08433eafc6094c853e919e 638886f1b6b540baab0585adbe98a642 RY(theta₁₉) 0b2a325b5b08433eafc6094c853e919e--638886f1b6b540baab0585adbe98a642 d8c54859ebe54795abaa1ce6b0cac739 RX(theta₂₃) 638886f1b6b540baab0585adbe98a642--d8c54859ebe54795abaa1ce6b0cac739 cccbc1be799c4e979379c41f0a984912 X d8c54859ebe54795abaa1ce6b0cac739--cccbc1be799c4e979379c41f0a984912 cccbc1be799c4e979379c41f0a984912--21a8b9a5989547dc9e71a4918fb1964a 93abf92aa437418d9856afb213b58901 cccbc1be799c4e979379c41f0a984912--93abf92aa437418d9856afb213b58901 93abf92aa437418d9856afb213b58901--8ba14986b938474882a5c27daa4dc01a
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_25f230b665024a319bc28768ad9b4836 Obs. cluster_778a405d44174e1fb67e28541973bf51 cluster_618567b8e755437f91a09cc0ac305d0e HEA 99c1717892b946ecb289ba9e6403a866 0 d3379e4831404e0e8b9b595c44d43d54 RX(theta₀) 99c1717892b946ecb289ba9e6403a866--d3379e4831404e0e8b9b595c44d43d54 42942d78765d4fbb942a343ca99ec368 1 297243e6cad743b68d37387c3544ca93 RY(theta₃) d3379e4831404e0e8b9b595c44d43d54--297243e6cad743b68d37387c3544ca93 83e8a3c28d364afc8418ebd8ec1f8dd5 RX(theta₆) 297243e6cad743b68d37387c3544ca93--83e8a3c28d364afc8418ebd8ec1f8dd5 2c6eee33c25442adb5641e1287e3f104 83e8a3c28d364afc8418ebd8ec1f8dd5--2c6eee33c25442adb5641e1287e3f104 af95f953b30944938c2e3978b922cca1 2c6eee33c25442adb5641e1287e3f104--af95f953b30944938c2e3978b922cca1 aad2bb3cbcd543f2b2032ef13a21a67d RX(theta₉) af95f953b30944938c2e3978b922cca1--aad2bb3cbcd543f2b2032ef13a21a67d 27fdcc2b0d2f4a00ade46b70f80d9c14 RY(theta₁₂) aad2bb3cbcd543f2b2032ef13a21a67d--27fdcc2b0d2f4a00ade46b70f80d9c14 11fce5c6d6ae445db713cc32ef37247b RX(theta₁₅) 27fdcc2b0d2f4a00ade46b70f80d9c14--11fce5c6d6ae445db713cc32ef37247b fd2532b596e94d519e1a63a88a00c1a4 11fce5c6d6ae445db713cc32ef37247b--fd2532b596e94d519e1a63a88a00c1a4 e8809a74e2e843e1abbac88f09be600f fd2532b596e94d519e1a63a88a00c1a4--e8809a74e2e843e1abbac88f09be600f 5ab2bbff13294ba4ad4e3c21aa4bb876 e8809a74e2e843e1abbac88f09be600f--5ab2bbff13294ba4ad4e3c21aa4bb876 7e2395a0e8ef43a698f54eea71a5177f 5ab2bbff13294ba4ad4e3c21aa4bb876--7e2395a0e8ef43a698f54eea71a5177f da7728392d174fb281b4971abe0223f5 7466342ced924337b05d17c7b2e0c791 RX(theta₁) 42942d78765d4fbb942a343ca99ec368--7466342ced924337b05d17c7b2e0c791 b8ef3d17c7fa4399afc895dcdb3d9dab 2 01094432ce8b41bea998908ff9554295 RY(theta₄) 7466342ced924337b05d17c7b2e0c791--01094432ce8b41bea998908ff9554295 f47c6303a7d34bdc9dd5c0024887fa55 RX(theta₇) 01094432ce8b41bea998908ff9554295--f47c6303a7d34bdc9dd5c0024887fa55 424dd85a0c6e4a4b8953298230c1250e X f47c6303a7d34bdc9dd5c0024887fa55--424dd85a0c6e4a4b8953298230c1250e 424dd85a0c6e4a4b8953298230c1250e--2c6eee33c25442adb5641e1287e3f104 e30d845d007d4bcabcb3a6efffb89458 424dd85a0c6e4a4b8953298230c1250e--e30d845d007d4bcabcb3a6efffb89458 4206770e4a8b4869bb0be269cf277d5b RX(theta₁₀) e30d845d007d4bcabcb3a6efffb89458--4206770e4a8b4869bb0be269cf277d5b 6dbca8b525f449df8372cd6b835a7c5c RY(theta₁₃) 4206770e4a8b4869bb0be269cf277d5b--6dbca8b525f449df8372cd6b835a7c5c 041d537cfbfd4bbb87f32e8e9bf25893 RX(theta₁₆) 6dbca8b525f449df8372cd6b835a7c5c--041d537cfbfd4bbb87f32e8e9bf25893 ee2cf7b727b84bdb9621c886f2519cba X 041d537cfbfd4bbb87f32e8e9bf25893--ee2cf7b727b84bdb9621c886f2519cba ee2cf7b727b84bdb9621c886f2519cba--fd2532b596e94d519e1a63a88a00c1a4 2fc211876df24303a900f2820fc4264d ee2cf7b727b84bdb9621c886f2519cba--2fc211876df24303a900f2820fc4264d e98ddbd61aa44161af6a3f349da3df6f AddBlock 2fc211876df24303a900f2820fc4264d--e98ddbd61aa44161af6a3f349da3df6f e98ddbd61aa44161af6a3f349da3df6f--da7728392d174fb281b4971abe0223f5 6fdaf9bbd1704b97aedc7a7ccd1bc9f3 9a3667c524154f22abe724fd497242d9 RX(theta₂) b8ef3d17c7fa4399afc895dcdb3d9dab--9a3667c524154f22abe724fd497242d9 b2e3dd9bf2914dc9a685227d6a3a6a51 RY(theta₅) 9a3667c524154f22abe724fd497242d9--b2e3dd9bf2914dc9a685227d6a3a6a51 d41a9ebb2aa44635be0c089445b9d304 RX(theta₈) b2e3dd9bf2914dc9a685227d6a3a6a51--d41a9ebb2aa44635be0c089445b9d304 f22c6859aba946948d17d261ae0d8a02 d41a9ebb2aa44635be0c089445b9d304--f22c6859aba946948d17d261ae0d8a02 e21a5a4d70bb4da3a6a9144cef40a71f X f22c6859aba946948d17d261ae0d8a02--e21a5a4d70bb4da3a6a9144cef40a71f e21a5a4d70bb4da3a6a9144cef40a71f--e30d845d007d4bcabcb3a6efffb89458 ed24d2c229914a2e839220fc8ee8d717 RX(theta₁₁) e21a5a4d70bb4da3a6a9144cef40a71f--ed24d2c229914a2e839220fc8ee8d717 ec9deae35d4a43819cd6c75d9b7e008c RY(theta₁₄) ed24d2c229914a2e839220fc8ee8d717--ec9deae35d4a43819cd6c75d9b7e008c df67843934c7428d83188c58df89ad84 RX(theta₁₇) ec9deae35d4a43819cd6c75d9b7e008c--df67843934c7428d83188c58df89ad84 4662cfd1c543436aa1ce15cedb293128 df67843934c7428d83188c58df89ad84--4662cfd1c543436aa1ce15cedb293128 cf3201364ae84f639aa52771d1509982 X 4662cfd1c543436aa1ce15cedb293128--cf3201364ae84f639aa52771d1509982 cf3201364ae84f639aa52771d1509982--2fc211876df24303a900f2820fc4264d d60a5b923be6426e9fc40a8cbc09b677 cf3201364ae84f639aa52771d1509982--d60a5b923be6426e9fc40a8cbc09b677 d60a5b923be6426e9fc40a8cbc09b677--6fdaf9bbd1704b97aedc7a7ccd1bc9f3
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 1b808a821bc1481aa9b9fcbdef6632c9 0 79a7c9d142694f36954f6466264d9d5a 1b808a821bc1481aa9b9fcbdef6632c9--79a7c9d142694f36954f6466264d9d5a 3199980778e2480080e671c400e061f8 1 66ce214100154c8db3dcb15a962040b5 75bb0ddd369246dfae1f9e7943517c0d 79a7c9d142694f36954f6466264d9d5a--75bb0ddd369246dfae1f9e7943517c0d ef0f461491f54933aedc38bfd1e0c50b 66ce214100154c8db3dcb15a962040b5--ef0f461491f54933aedc38bfd1e0c50b adbdea77178243bfae37939b76688ec3 e16e18f7c50142278d1c1987d877c43d ef0f461491f54933aedc38bfd1e0c50b--e16e18f7c50142278d1c1987d877c43d da087d550f4b4714891e0a2e18fcdc4d adbdea77178243bfae37939b76688ec3--da087d550f4b4714891e0a2e18fcdc4d 0c92df18bc7149c0af8cc0f37dac6da0 64927c0e48b04d2ebbd95f92938b52cc 3199980778e2480080e671c400e061f8--64927c0e48b04d2ebbd95f92938b52cc 8db69c5936e9410fae5415b1ef814e81 2 64927c0e48b04d2ebbd95f92938b52cc--66ce214100154c8db3dcb15a962040b5 98ae427ff79c465c8fa73365c2198e9e 75bb0ddd369246dfae1f9e7943517c0d--98ae427ff79c465c8fa73365c2198e9e 4d88b5480a20468cb3738660d20dd567 98ae427ff79c465c8fa73365c2198e9e--4d88b5480a20468cb3738660d20dd567 4d88b5480a20468cb3738660d20dd567--0c92df18bc7149c0af8cc0f37dac6da0 9464a413032a44f3952f73405f529cdd 0504cf811c5c47c1b02ae0ddd28c5c3d 8db69c5936e9410fae5415b1ef814e81--0504cf811c5c47c1b02ae0ddd28c5c3d 712438c29a1a423bb9c6b649f97ff550 3 5b5a169cf1a54a69ada5f47ea683e369 0504cf811c5c47c1b02ae0ddd28c5c3d--5b5a169cf1a54a69ada5f47ea683e369 581a2ded2ad74744a7293dfd3db143db 5b5a169cf1a54a69ada5f47ea683e369--581a2ded2ad74744a7293dfd3db143db 1e10f04b5d8a482b96566bdf139d29b6 581a2ded2ad74744a7293dfd3db143db--1e10f04b5d8a482b96566bdf139d29b6 1e10f04b5d8a482b96566bdf139d29b6--9464a413032a44f3952f73405f529cdd e55d87e0b2654ab7b6de492524398f0e 97da479bdc6e45f2950ef60125857a61 712438c29a1a423bb9c6b649f97ff550--97da479bdc6e45f2950ef60125857a61 27f480d40e39400f958dc8132d5c83f6 97da479bdc6e45f2950ef60125857a61--27f480d40e39400f958dc8132d5c83f6 399b8288763f493280648d62472bf345 27f480d40e39400f958dc8132d5c83f6--399b8288763f493280648d62472bf345 399b8288763f493280648d62472bf345--adbdea77178243bfae37939b76688ec3 e16e18f7c50142278d1c1987d877c43d--e55d87e0b2654ab7b6de492524398f0e
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 cb9beb620a46440095610c0a47cf186e 0 c9314566f1574d91bd4fd95ef29c7e79 cb9beb620a46440095610c0a47cf186e--c9314566f1574d91bd4fd95ef29c7e79 991688411fa54c369a509219a4d6bea8 1 fffabb972d4b43f88fa4f31ba2e21143 c9314566f1574d91bd4fd95ef29c7e79--fffabb972d4b43f88fa4f31ba2e21143 cb5942735f4545ceaec63519e1001279 fffabb972d4b43f88fa4f31ba2e21143--cb5942735f4545ceaec63519e1001279 f15a997b71ef426ab40dca1474920a3c cb5942735f4545ceaec63519e1001279--f15a997b71ef426ab40dca1474920a3c c2b14513fa244c109fc345ab949a8998 c5071f679b384637831be9f773d53b3d PHASE(0.5) 991688411fa54c369a509219a4d6bea8--c5071f679b384637831be9f773d53b3d 1694e5f96d7c4850a8b8114260507bfd 2 c5071f679b384637831be9f773d53b3d--c9314566f1574d91bd4fd95ef29c7e79 f06ab09c5bec4796812226d5fecc2bf5 c5071f679b384637831be9f773d53b3d--f06ab09c5bec4796812226d5fecc2bf5 bb59776c0a954589aa4016d449697923 f06ab09c5bec4796812226d5fecc2bf5--bb59776c0a954589aa4016d449697923 bb59776c0a954589aa4016d449697923--c2b14513fa244c109fc345ab949a8998 517a08baefb2439abe59673da7a890ed 53cad556fce94f06a0d309c28ac5e892 1694e5f96d7c4850a8b8114260507bfd--53cad556fce94f06a0d309c28ac5e892 88f7f9a01269432f8fe89cb6e37ed4dd 3 97064cbeabaa42748c35ddc4826e92ed PHASE(0.5) 53cad556fce94f06a0d309c28ac5e892--97064cbeabaa42748c35ddc4826e92ed 97064cbeabaa42748c35ddc4826e92ed--fffabb972d4b43f88fa4f31ba2e21143 7a55a9903ac145d08f78940a59f2f3be 97064cbeabaa42748c35ddc4826e92ed--7a55a9903ac145d08f78940a59f2f3be 7a55a9903ac145d08f78940a59f2f3be--517a08baefb2439abe59673da7a890ed aad32974bcd34c9b8fcc068da108ecd8 ac6fe5f3451947b7b7f2c995e175fac2 88f7f9a01269432f8fe89cb6e37ed4dd--ac6fe5f3451947b7b7f2c995e175fac2 c541beb90f104e50ae8db3d41f4aab7c ac6fe5f3451947b7b7f2c995e175fac2--c541beb90f104e50ae8db3d41f4aab7c 462cb3898fbc43d3a29813f6da551113 PHASE(0.5) c541beb90f104e50ae8db3d41f4aab7c--462cb3898fbc43d3a29813f6da551113 462cb3898fbc43d3a29813f6da551113--cb5942735f4545ceaec63519e1001279 462cb3898fbc43d3a29813f6da551113--aad32974bcd34c9b8fcc068da108ecd8

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