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 9547b3d67cdc464c880fb3bec5126b58 0 ff6ea963a6b041cebfb6195cec9f446d X 9547b3d67cdc464c880fb3bec5126b58--ff6ea963a6b041cebfb6195cec9f446d 23b8fe7bb3ee40b8b642677c5f0522c9 1 5e69ac9d998a44ffb2d2b2c039e35010 ff6ea963a6b041cebfb6195cec9f446d--5e69ac9d998a44ffb2d2b2c039e35010 ec31b411b3cc4fbb88d706bf80b3c18f 55825301b56f47029840ff938712f730 Y 23b8fe7bb3ee40b8b642677c5f0522c9--55825301b56f47029840ff938712f730 55825301b56f47029840ff938712f730--ec31b411b3cc4fbb88d706bf80b3c18f
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 5e43d6b8dc81432da3434739431e4d7e 0 01e3dde744b54ad892ab7050a5297e5d X 5e43d6b8dc81432da3434739431e4d7e--01e3dde744b54ad892ab7050a5297e5d 634bf81240454a32815bd327b2749ba6 Y 01e3dde744b54ad892ab7050a5297e5d--634bf81240454a32815bd327b2749ba6 7a81b961e445405485dd88c0f5e52459 634bf81240454a32815bd327b2749ba6--7a81b961e445405485dd88c0f5e52459
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 e1a38e7b263f4157ba1c2a2c159198e3 0 0921ff4095a146299b0e1720f1a63645 X e1a38e7b263f4157ba1c2a2c159198e3--0921ff4095a146299b0e1720f1a63645 83560b9a67de49a8a410ac9196f8818e 1 e5f04ad7f3a545eb833b55a331911850 0921ff4095a146299b0e1720f1a63645--e5f04ad7f3a545eb833b55a331911850 0c319cf5a5414fda8544aa741e130f18 e5f04ad7f3a545eb833b55a331911850--0c319cf5a5414fda8544aa741e130f18 aa748b6cb3084338a41a85cb157e919c dcd228dfc8d04e2db8ed582fc9b77612 83560b9a67de49a8a410ac9196f8818e--dcd228dfc8d04e2db8ed582fc9b77612 ebbe2b4227684679af97e40f2cbbee96 Y dcd228dfc8d04e2db8ed582fc9b77612--ebbe2b4227684679af97e40f2cbbee96 ebbe2b4227684679af97e40f2cbbee96--aa748b6cb3084338a41a85cb157e919c
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_aaa1dedbf1b344529afe8caf9ac9ef9a e6005033e1c144c7ac765a7716847cdf 0 fd7fbc52815440e2a72c322ca24b39e6 e6005033e1c144c7ac765a7716847cdf--fd7fbc52815440e2a72c322ca24b39e6 36430bfcf58b43eaab28d5721a671c2f 1 67f6e98e80b84dee8df875a6f40811a5 fd7fbc52815440e2a72c322ca24b39e6--67f6e98e80b84dee8df875a6f40811a5 c89d419e8d944db0ae1dfefc52d43e57 6712b317daea4109856cac68725b015c AddBlock 36430bfcf58b43eaab28d5721a671c2f--6712b317daea4109856cac68725b015c 7ac28d1756ee4664b5a63357ef8cfd4f 2 6712b317daea4109856cac68725b015c--c89d419e8d944db0ae1dfefc52d43e57 f88454639f6c40ec85b1cce15e3f1bf0 c5ceb036dca343f4857b513f9353032d 7ac28d1756ee4664b5a63357ef8cfd4f--c5ceb036dca343f4857b513f9353032d c5ceb036dca343f4857b513f9353032d--f88454639f6c40ec85b1cce15e3f1bf0
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_880852b9810d4edd8ce01724dabba2b9 cluster_853695e53d5d4e4284e26c10f3215120 rx b708e50b900440d0bc9cc5ef927a00b9 0 a2f90b7d590a4514bf12c3fa5a1f56af X b708e50b900440d0bc9cc5ef927a00b9--a2f90b7d590a4514bf12c3fa5a1f56af 4bbaf83d767947c9bd4b346d0817c24e 1 47446e057c5e4aa196d8ed79f27f878a a2f90b7d590a4514bf12c3fa5a1f56af--47446e057c5e4aa196d8ed79f27f878a 0dd7ac7ec67b4e51a6d90da77864d2fa 47446e057c5e4aa196d8ed79f27f878a--0dd7ac7ec67b4e51a6d90da77864d2fa f91358025ef6421dad25829daa27f180 0dd7ac7ec67b4e51a6d90da77864d2fa--f91358025ef6421dad25829daa27f180 461f2894e4c0491a9fded29d08d45ca6 56deca0f32cc46c6b6be630f5f7c06e6 Y 4bbaf83d767947c9bd4b346d0817c24e--56deca0f32cc46c6b6be630f5f7c06e6 cac4ebeda78b4d22868b010bd6195f0c 2 59b51590167c45d3b313b0ef982d285d 56deca0f32cc46c6b6be630f5f7c06e6--59b51590167c45d3b313b0ef982d285d 89a7c0dddf7a4308980f9d1cd5527aab HamEvo 59b51590167c45d3b313b0ef982d285d--89a7c0dddf7a4308980f9d1cd5527aab 89a7c0dddf7a4308980f9d1cd5527aab--461f2894e4c0491a9fded29d08d45ca6 32ab43ef565d46918dd90fa2d6ac2ee6 897268f56eca4c3f9162da8a4b45f284 RX(x) cac4ebeda78b4d22868b010bd6195f0c--897268f56eca4c3f9162da8a4b45f284 a0268ad0625245229e79b02f52f97157 3 8073f54f22cc4e72b53c2e9ee2e1b10c 897268f56eca4c3f9162da8a4b45f284--8073f54f22cc4e72b53c2e9ee2e1b10c d7c11192dc624226856952148b1aab55 t = 10 8073f54f22cc4e72b53c2e9ee2e1b10c--d7c11192dc624226856952148b1aab55 d7c11192dc624226856952148b1aab55--32ab43ef565d46918dd90fa2d6ac2ee6 62d4e84aea114b68b66f317ebcc49edd aab38b2c42cd4fcbb3681246fbaa18e7 RX(0.5) a0268ad0625245229e79b02f52f97157--aab38b2c42cd4fcbb3681246fbaa18e7 e7139e29dab947ed97144963cb03d3dd X aab38b2c42cd4fcbb3681246fbaa18e7--e7139e29dab947ed97144963cb03d3dd e7139e29dab947ed97144963cb03d3dd--8073f54f22cc4e72b53c2e9ee2e1b10c 44e4c1f6be6d4e3da7e854879479bc77 e7139e29dab947ed97144963cb03d3dd--44e4c1f6be6d4e3da7e854879479bc77 44e4c1f6be6d4e3da7e854879479bc77--62d4e84aea114b68b66f317ebcc49edd
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_c61b665ddcda40c6ae994a79303193a5 HEA cluster_9d6bd0f505b94863b6e5e4b90af07af5 Tower Fourier FM a1d9b6ee514a428f8a76c5d967e8a082 0 ec61227792e046e5b39bff204796e897 RX(1.0*phi) a1d9b6ee514a428f8a76c5d967e8a082--ec61227792e046e5b39bff204796e897 709399eff62c450e912901830e5a6e65 1 aa137530de704941acb7f054291f7381 RX(theta₀) ec61227792e046e5b39bff204796e897--aa137530de704941acb7f054291f7381 3728db5e516645a3bcb8fe6b2528b3f9 RY(theta₄) aa137530de704941acb7f054291f7381--3728db5e516645a3bcb8fe6b2528b3f9 da245a0705f34221bba3e057b6b99ae7 RX(theta₈) 3728db5e516645a3bcb8fe6b2528b3f9--da245a0705f34221bba3e057b6b99ae7 77b02bc4b74f4a0384b686044d7413fc da245a0705f34221bba3e057b6b99ae7--77b02bc4b74f4a0384b686044d7413fc 2fab474a698246dda1513e6944bdb5ef 77b02bc4b74f4a0384b686044d7413fc--2fab474a698246dda1513e6944bdb5ef f65496e0ed3f487c8c32658171e0539d RX(theta₁₂) 2fab474a698246dda1513e6944bdb5ef--f65496e0ed3f487c8c32658171e0539d f02ea4419937456ca4840e121d0f3cf2 RY(theta₁₆) f65496e0ed3f487c8c32658171e0539d--f02ea4419937456ca4840e121d0f3cf2 4faa7361b77444be91ce0a1522597f3a RX(theta₂₀) f02ea4419937456ca4840e121d0f3cf2--4faa7361b77444be91ce0a1522597f3a 1f08ba450ea948d7941aad034c51b5e0 4faa7361b77444be91ce0a1522597f3a--1f08ba450ea948d7941aad034c51b5e0 e84162ce39c048da863d16a09a4b7740 1f08ba450ea948d7941aad034c51b5e0--e84162ce39c048da863d16a09a4b7740 17ccff24486a4f6ab3121121090c5931 e84162ce39c048da863d16a09a4b7740--17ccff24486a4f6ab3121121090c5931 53897fdd692b4922a2920f99905ed7f3 f4dd4c0ca05c488889f5ba056de0b977 RX(2.0*phi) 709399eff62c450e912901830e5a6e65--f4dd4c0ca05c488889f5ba056de0b977 d6b089e856884c7d8b42507fbc0fc69f 2 130894e160fb4ca2b942a500e29e0973 RX(theta₁) f4dd4c0ca05c488889f5ba056de0b977--130894e160fb4ca2b942a500e29e0973 7629a48c5fa74ae1ada5d9935b7ced86 RY(theta₅) 130894e160fb4ca2b942a500e29e0973--7629a48c5fa74ae1ada5d9935b7ced86 4debb679b5194ce6944f6e73a486fee7 RX(theta₉) 7629a48c5fa74ae1ada5d9935b7ced86--4debb679b5194ce6944f6e73a486fee7 304d56d5438545e1b74e1003280f6e46 X 4debb679b5194ce6944f6e73a486fee7--304d56d5438545e1b74e1003280f6e46 304d56d5438545e1b74e1003280f6e46--77b02bc4b74f4a0384b686044d7413fc 83dccc015581445390018fcdc546a06a 304d56d5438545e1b74e1003280f6e46--83dccc015581445390018fcdc546a06a 9fa79309da9548d5999a756f99be4c3e RX(theta₁₃) 83dccc015581445390018fcdc546a06a--9fa79309da9548d5999a756f99be4c3e 52aaa371317d45008b945e993f6fadf8 RY(theta₁₇) 9fa79309da9548d5999a756f99be4c3e--52aaa371317d45008b945e993f6fadf8 4b69d23ccb8549fdb46db438286ff5d9 RX(theta₂₁) 52aaa371317d45008b945e993f6fadf8--4b69d23ccb8549fdb46db438286ff5d9 2d4795c7afd24c31af868b9164f18d20 X 4b69d23ccb8549fdb46db438286ff5d9--2d4795c7afd24c31af868b9164f18d20 2d4795c7afd24c31af868b9164f18d20--1f08ba450ea948d7941aad034c51b5e0 fac05da6fba347bfa2479c7c2f16b1c3 2d4795c7afd24c31af868b9164f18d20--fac05da6fba347bfa2479c7c2f16b1c3 fac05da6fba347bfa2479c7c2f16b1c3--53897fdd692b4922a2920f99905ed7f3 d9acdc7c06824c8d9743d70676686572 966783a297d64019b0c56dbf9b3d3753 RX(3.0*phi) d6b089e856884c7d8b42507fbc0fc69f--966783a297d64019b0c56dbf9b3d3753 abacc6645a3b41bf924dff50cbd17031 3 475aa64910dd4e2e87807e444769d3d4 RX(theta₂) 966783a297d64019b0c56dbf9b3d3753--475aa64910dd4e2e87807e444769d3d4 287b7d3bb0c64e9bb0ee93b371669b51 RY(theta₆) 475aa64910dd4e2e87807e444769d3d4--287b7d3bb0c64e9bb0ee93b371669b51 f3524821a6d249f2bac819ec30e8b270 RX(theta₁₀) 287b7d3bb0c64e9bb0ee93b371669b51--f3524821a6d249f2bac819ec30e8b270 795432af375b49298819fe257860ad27 f3524821a6d249f2bac819ec30e8b270--795432af375b49298819fe257860ad27 3de27bfcd7684134af0ede14783307ed X 795432af375b49298819fe257860ad27--3de27bfcd7684134af0ede14783307ed 3de27bfcd7684134af0ede14783307ed--83dccc015581445390018fcdc546a06a 0c1a5768c9164f8e84b376d2949dde2b RX(theta₁₄) 3de27bfcd7684134af0ede14783307ed--0c1a5768c9164f8e84b376d2949dde2b 1849aa24d632410687c95d6731f8707c RY(theta₁₈) 0c1a5768c9164f8e84b376d2949dde2b--1849aa24d632410687c95d6731f8707c 364e7e1050b941f9b74796f744aa51e5 RX(theta₂₂) 1849aa24d632410687c95d6731f8707c--364e7e1050b941f9b74796f744aa51e5 e03e3ee9fa3d470282bc5ef2fec94784 364e7e1050b941f9b74796f744aa51e5--e03e3ee9fa3d470282bc5ef2fec94784 6913c7ed3d1347d69da0cbb63c835ffa X e03e3ee9fa3d470282bc5ef2fec94784--6913c7ed3d1347d69da0cbb63c835ffa 6913c7ed3d1347d69da0cbb63c835ffa--fac05da6fba347bfa2479c7c2f16b1c3 6913c7ed3d1347d69da0cbb63c835ffa--d9acdc7c06824c8d9743d70676686572 f06a518f5dd7427aa8730e870585850d cf50368e52cb48fe8d7bc64864fe013c RX(4.0*phi) abacc6645a3b41bf924dff50cbd17031--cf50368e52cb48fe8d7bc64864fe013c 75b85fed9dcf4469af504445a8e4b118 RX(theta₃) cf50368e52cb48fe8d7bc64864fe013c--75b85fed9dcf4469af504445a8e4b118 666c8371fe7b497cbf58bc46dccbb68e RY(theta₇) 75b85fed9dcf4469af504445a8e4b118--666c8371fe7b497cbf58bc46dccbb68e f6bde508dbf44b688b462c9f7141054c RX(theta₁₁) 666c8371fe7b497cbf58bc46dccbb68e--f6bde508dbf44b688b462c9f7141054c 402bf3cd322641fdb290b02216bd6143 X f6bde508dbf44b688b462c9f7141054c--402bf3cd322641fdb290b02216bd6143 402bf3cd322641fdb290b02216bd6143--795432af375b49298819fe257860ad27 19bd9e9029d242d780b37c9ccc646d8a 402bf3cd322641fdb290b02216bd6143--19bd9e9029d242d780b37c9ccc646d8a 90865261be8a48809ee23718b455867b RX(theta₁₅) 19bd9e9029d242d780b37c9ccc646d8a--90865261be8a48809ee23718b455867b 3a1f081428634d0e94cf339924b83c74 RY(theta₁₉) 90865261be8a48809ee23718b455867b--3a1f081428634d0e94cf339924b83c74 fa0526fa15e44967b723eb6dd03c4c6f RX(theta₂₃) 3a1f081428634d0e94cf339924b83c74--fa0526fa15e44967b723eb6dd03c4c6f b1a512bc3ed4417f869cd628f5bf4a42 X fa0526fa15e44967b723eb6dd03c4c6f--b1a512bc3ed4417f869cd628f5bf4a42 b1a512bc3ed4417f869cd628f5bf4a42--e03e3ee9fa3d470282bc5ef2fec94784 78193d6ec699406b92d388181ae44eca b1a512bc3ed4417f869cd628f5bf4a42--78193d6ec699406b92d388181ae44eca 78193d6ec699406b92d388181ae44eca--f06a518f5dd7427aa8730e870585850d
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_a58aed7c866b4c6b8e3cc0f02617d24f Obs. cluster_a877c1a9d2cc4a5c9b84d91609e4bc01 cluster_7da10dbfc27d40dd951d3dc1774bc80d HEA c4ecce42172d461095ebcd453612ff57 0 a635599b714144fd8b677e19105be24e RX(theta₀) c4ecce42172d461095ebcd453612ff57--a635599b714144fd8b677e19105be24e aa36bb1418124cb8994b2ea4a5b1dd6e 1 1938fd784ea44e8c97aaeb6a1db1e382 RY(theta₃) a635599b714144fd8b677e19105be24e--1938fd784ea44e8c97aaeb6a1db1e382 0b8f6706cd4e4bebaf9e7dfbd77213cf RX(theta₆) 1938fd784ea44e8c97aaeb6a1db1e382--0b8f6706cd4e4bebaf9e7dfbd77213cf 84a4b0077874452492997493c73de329 0b8f6706cd4e4bebaf9e7dfbd77213cf--84a4b0077874452492997493c73de329 d961f3f298984e2db13a7c0345e716ff 84a4b0077874452492997493c73de329--d961f3f298984e2db13a7c0345e716ff 53a171722d874394ad8819c1d1890b73 RX(theta₉) d961f3f298984e2db13a7c0345e716ff--53a171722d874394ad8819c1d1890b73 9369dd5e0c5043429049c532522d7717 RY(theta₁₂) 53a171722d874394ad8819c1d1890b73--9369dd5e0c5043429049c532522d7717 97961e7152624696bbe12f7309d32207 RX(theta₁₅) 9369dd5e0c5043429049c532522d7717--97961e7152624696bbe12f7309d32207 0e8f1dae7f1a4959818ed41558d7d294 97961e7152624696bbe12f7309d32207--0e8f1dae7f1a4959818ed41558d7d294 74f66bd77257458986fbf196b0cace19 0e8f1dae7f1a4959818ed41558d7d294--74f66bd77257458986fbf196b0cace19 63ed8949466e4f8e9ebf3ae9ba17e507 74f66bd77257458986fbf196b0cace19--63ed8949466e4f8e9ebf3ae9ba17e507 9e2f501804ec4ffbaf621b37dfd05716 63ed8949466e4f8e9ebf3ae9ba17e507--9e2f501804ec4ffbaf621b37dfd05716 ea35419429a44919968bb270056e85f7 813da99bc03c490c84d88989f2045d62 RX(theta₁) aa36bb1418124cb8994b2ea4a5b1dd6e--813da99bc03c490c84d88989f2045d62 fa83881dfac5478696fc04e9fbed0104 2 0a94f86b4b1c4fb9b2740ddee6962ba0 RY(theta₄) 813da99bc03c490c84d88989f2045d62--0a94f86b4b1c4fb9b2740ddee6962ba0 b4daf66223a84f02a1b6542c2449da92 RX(theta₇) 0a94f86b4b1c4fb9b2740ddee6962ba0--b4daf66223a84f02a1b6542c2449da92 a55d6ec3c86041b6bd3e82928e35238d X b4daf66223a84f02a1b6542c2449da92--a55d6ec3c86041b6bd3e82928e35238d a55d6ec3c86041b6bd3e82928e35238d--84a4b0077874452492997493c73de329 0df722092b1041488321eb2446ef1771 a55d6ec3c86041b6bd3e82928e35238d--0df722092b1041488321eb2446ef1771 2599b9cdfb7f48fa82a4f19134fa803b RX(theta₁₀) 0df722092b1041488321eb2446ef1771--2599b9cdfb7f48fa82a4f19134fa803b bcb62bb872ce485f91bff511cd7cfd56 RY(theta₁₃) 2599b9cdfb7f48fa82a4f19134fa803b--bcb62bb872ce485f91bff511cd7cfd56 3486f84304bc4ef99302a3387d2cc3e5 RX(theta₁₆) bcb62bb872ce485f91bff511cd7cfd56--3486f84304bc4ef99302a3387d2cc3e5 05de5f6890394e2ba2912950222a4d94 X 3486f84304bc4ef99302a3387d2cc3e5--05de5f6890394e2ba2912950222a4d94 05de5f6890394e2ba2912950222a4d94--0e8f1dae7f1a4959818ed41558d7d294 9b9eb7362a024338a8a2b06ba120fa25 05de5f6890394e2ba2912950222a4d94--9b9eb7362a024338a8a2b06ba120fa25 feb6fd61d74845feb10906c9b34346fc AddBlock 9b9eb7362a024338a8a2b06ba120fa25--feb6fd61d74845feb10906c9b34346fc feb6fd61d74845feb10906c9b34346fc--ea35419429a44919968bb270056e85f7 23779cec1e3843f5ae079547d5b6d76e 54ff218a3f1f491db6a07e8def6e1fe3 RX(theta₂) fa83881dfac5478696fc04e9fbed0104--54ff218a3f1f491db6a07e8def6e1fe3 fd873e1fc39f4260b7b3a8dcb7e31321 RY(theta₅) 54ff218a3f1f491db6a07e8def6e1fe3--fd873e1fc39f4260b7b3a8dcb7e31321 6dca96c103244183aa9bf095809ea6c3 RX(theta₈) fd873e1fc39f4260b7b3a8dcb7e31321--6dca96c103244183aa9bf095809ea6c3 6100ca49a66d4dceafd32c9c2eb1b514 6dca96c103244183aa9bf095809ea6c3--6100ca49a66d4dceafd32c9c2eb1b514 984c2626db1341fabd12503077c633b8 X 6100ca49a66d4dceafd32c9c2eb1b514--984c2626db1341fabd12503077c633b8 984c2626db1341fabd12503077c633b8--0df722092b1041488321eb2446ef1771 773ceb8916a442e1b32a06f1d4d48dac RX(theta₁₁) 984c2626db1341fabd12503077c633b8--773ceb8916a442e1b32a06f1d4d48dac cfd6c8d457a44938bec0091f60bcc0ee RY(theta₁₄) 773ceb8916a442e1b32a06f1d4d48dac--cfd6c8d457a44938bec0091f60bcc0ee 0768e992ff524ac788a40a10a5acc6db RX(theta₁₇) cfd6c8d457a44938bec0091f60bcc0ee--0768e992ff524ac788a40a10a5acc6db 68096b28887e466a98e6b4484b3844aa 0768e992ff524ac788a40a10a5acc6db--68096b28887e466a98e6b4484b3844aa 29ed080f65d74f08a2de44304f1ec5ce X 68096b28887e466a98e6b4484b3844aa--29ed080f65d74f08a2de44304f1ec5ce 29ed080f65d74f08a2de44304f1ec5ce--9b9eb7362a024338a8a2b06ba120fa25 aadcf03f9ccb4df5be8c405ae1821f54 29ed080f65d74f08a2de44304f1ec5ce--aadcf03f9ccb4df5be8c405ae1821f54 aadcf03f9ccb4df5be8c405ae1821f54--23779cec1e3843f5ae079547d5b6d76e
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 6ccab5ebde584b6691e04ca182c0b0e6 0 9aeb070e1e444d3789fdd6f583afda14 6ccab5ebde584b6691e04ca182c0b0e6--9aeb070e1e444d3789fdd6f583afda14 cb88163f206945c2b91485ccf870b8fb 1 fc1e8d90db8746f28af9aebd21f0f84a 3893e582c9e3459897a8ce75c7151710 9aeb070e1e444d3789fdd6f583afda14--3893e582c9e3459897a8ce75c7151710 c7a3d52247dc4f32844aa1851650ce9c fc1e8d90db8746f28af9aebd21f0f84a--c7a3d52247dc4f32844aa1851650ce9c 42c311b5b0e045778248533b0435a4a0 a5c2793a09964c6eb7da210540aa2eae c7a3d52247dc4f32844aa1851650ce9c--a5c2793a09964c6eb7da210540aa2eae a9257dae9d7748b4913b3bc720169eb0 42c311b5b0e045778248533b0435a4a0--a9257dae9d7748b4913b3bc720169eb0 aa7ee42f427e40b7bc08108a9ce45349 37d31325ed114ddd86c6137dd058e2f0 cb88163f206945c2b91485ccf870b8fb--37d31325ed114ddd86c6137dd058e2f0 6b2e8d8cd74344b388361ae3e4b56a6f 2 37d31325ed114ddd86c6137dd058e2f0--fc1e8d90db8746f28af9aebd21f0f84a 8b2ef80af7574812a1eeaf2828320832 3893e582c9e3459897a8ce75c7151710--8b2ef80af7574812a1eeaf2828320832 79281b48150c4fac9be634d4de7a7c2d 8b2ef80af7574812a1eeaf2828320832--79281b48150c4fac9be634d4de7a7c2d 79281b48150c4fac9be634d4de7a7c2d--aa7ee42f427e40b7bc08108a9ce45349 67016df33d4947d0ac5babdd28338b1a ac05bfbcaafe4075b078fc901a6637d6 6b2e8d8cd74344b388361ae3e4b56a6f--ac05bfbcaafe4075b078fc901a6637d6 579392832961439ea756a2cc49c084e1 3 b73ebd32fec54ad4b5b7fbc639c31c8e ac05bfbcaafe4075b078fc901a6637d6--b73ebd32fec54ad4b5b7fbc639c31c8e 753a101ea2f9465e824f3f39ccbc65ec b73ebd32fec54ad4b5b7fbc639c31c8e--753a101ea2f9465e824f3f39ccbc65ec 1a26e0549a764a05a7725b7264558f39 753a101ea2f9465e824f3f39ccbc65ec--1a26e0549a764a05a7725b7264558f39 1a26e0549a764a05a7725b7264558f39--67016df33d4947d0ac5babdd28338b1a e18b11945e814e1086ace405104f28ef de2b48264bf44cabaaede470ac95a02b 579392832961439ea756a2cc49c084e1--de2b48264bf44cabaaede470ac95a02b 60491c4caee94b3793a5515465da8b9f de2b48264bf44cabaaede470ac95a02b--60491c4caee94b3793a5515465da8b9f 518186896f3a4ccc84b192ed357b5182 60491c4caee94b3793a5515465da8b9f--518186896f3a4ccc84b192ed357b5182 518186896f3a4ccc84b192ed357b5182--42c311b5b0e045778248533b0435a4a0 a5c2793a09964c6eb7da210540aa2eae--e18b11945e814e1086ace405104f28ef
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 e202fdd79be44c35a441a0e7fc9e197c 0 ff12a9607f1a434687c29e78a5b4339f e202fdd79be44c35a441a0e7fc9e197c--ff12a9607f1a434687c29e78a5b4339f af5238ee39a44675a857310878eaf8fa 1 efb319192c6646ada12dbb5d0790ac7d ff12a9607f1a434687c29e78a5b4339f--efb319192c6646ada12dbb5d0790ac7d 333cbbcbf2984c5e8a5de9bb6615a05b efb319192c6646ada12dbb5d0790ac7d--333cbbcbf2984c5e8a5de9bb6615a05b 170497ed0ddb4678a7ee1ccecf7cdc92 333cbbcbf2984c5e8a5de9bb6615a05b--170497ed0ddb4678a7ee1ccecf7cdc92 eaac59c398194ca1ac984802fce62d58 3d4bc2b8adaf40b998b99386a07211e1 PHASE(0.5) af5238ee39a44675a857310878eaf8fa--3d4bc2b8adaf40b998b99386a07211e1 384174350d634b89ab4749a059975582 2 3d4bc2b8adaf40b998b99386a07211e1--ff12a9607f1a434687c29e78a5b4339f 77bbc68827d5457690dd9f13e3a59139 3d4bc2b8adaf40b998b99386a07211e1--77bbc68827d5457690dd9f13e3a59139 75899458ef0940f78ff23d26fbdf69c5 77bbc68827d5457690dd9f13e3a59139--75899458ef0940f78ff23d26fbdf69c5 75899458ef0940f78ff23d26fbdf69c5--eaac59c398194ca1ac984802fce62d58 6736ac2d70ea4e188263320e402b4528 f532a013b23441daadffe3b61a876869 384174350d634b89ab4749a059975582--f532a013b23441daadffe3b61a876869 e390a3546bd9419593680b9c7048095f 3 68f922ce09274900ae20fad13c697e6a PHASE(0.5) f532a013b23441daadffe3b61a876869--68f922ce09274900ae20fad13c697e6a 68f922ce09274900ae20fad13c697e6a--efb319192c6646ada12dbb5d0790ac7d f62ddd399a924c0690afbf6fd97b61bb 68f922ce09274900ae20fad13c697e6a--f62ddd399a924c0690afbf6fd97b61bb f62ddd399a924c0690afbf6fd97b61bb--6736ac2d70ea4e188263320e402b4528 a633875560d04dc0a3c1a65a2eed96bf d0b75f18311c470b8d96da293cda622d e390a3546bd9419593680b9c7048095f--d0b75f18311c470b8d96da293cda622d de8928e4f5bc4fdd8dab1c25a773c9f2 d0b75f18311c470b8d96da293cda622d--de8928e4f5bc4fdd8dab1c25a773c9f2 4d180db72c8e420eb41fb5b68c4ec6ab PHASE(0.5) de8928e4f5bc4fdd8dab1c25a773c9f2--4d180db72c8e420eb41fb5b68c4ec6ab 4d180db72c8e420eb41fb5b68c4ec6ab--333cbbcbf2984c5e8a5de9bb6615a05b 4d180db72c8e420eb41fb5b68c4ec6ab--a633875560d04dc0a3c1a65a2eed96bf

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