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 01fc38c80a844ae0ac60996fad32ece7 0 de943e28373b4a618f1b58cbb1e78404 X 01fc38c80a844ae0ac60996fad32ece7--de943e28373b4a618f1b58cbb1e78404 bedeb2e85c98489287eee53b5355058c 1 464c2c0d28aa4496a2eef80f55138784 de943e28373b4a618f1b58cbb1e78404--464c2c0d28aa4496a2eef80f55138784 3ebc921ee185443bac044502a7dd35b8 2fd33928e55f4b7aa729a9781cf1fad1 Y bedeb2e85c98489287eee53b5355058c--2fd33928e55f4b7aa729a9781cf1fad1 2fd33928e55f4b7aa729a9781cf1fad1--3ebc921ee185443bac044502a7dd35b8
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(0))
%3 11d3d06b32ce4cf0ae6afc300165246c 0 8972657d391740d4872526397221819a X 11d3d06b32ce4cf0ae6afc300165246c--8972657d391740d4872526397221819a e4c7210c38254a43aa45302b85711372 Y 8972657d391740d4872526397221819a--e4c7210c38254a43aa45302b85711372 b48b7c7f24db43a08b9d48eae69e791a e4c7210c38254a43aa45302b85711372--b48b7c7f24db43a08b9d48eae69e791a
from qadence import X, Y, chain
from qadence.draw import display

b = chain(X(0), Y(1))
%3 97daefae79144af0ae76cf4e09c2fc1f 0 81264148c85f48218f6b8be6658c98b3 X 97daefae79144af0ae76cf4e09c2fc1f--81264148c85f48218f6b8be6658c98b3 a822c7e8cf61486a8c22ae45df14e2a5 1 718a42a9a618402782997cc09688a9b8 81264148c85f48218f6b8be6658c98b3--718a42a9a618402782997cc09688a9b8 e98c1d43cfc1400fb64702511f0a84ae 718a42a9a618402782997cc09688a9b8--e98c1d43cfc1400fb64702511f0a84ae 25c91f76df8a47e992eeb9286d36c959 e8fedfa02a9c4f79b42659609af69629 a822c7e8cf61486a8c22ae45df14e2a5--e8fedfa02a9c4f79b42659609af69629 94f1fc984c3b47e78c3aeff51f6db5d3 Y e8fedfa02a9c4f79b42659609af69629--94f1fc984c3b47e78c3aeff51f6db5d3 94f1fc984c3b47e78c3aeff51f6db5d3--25c91f76df8a47e992eeb9286d36c959
from qadence import X, Y, add
from qadence.draw import display

b = add(X(0), Y(1), X(2))
%3 cluster_37852685f0434c428215acf708fbf93e 7f09450e270146daa17af4ad3e94ba44 0 3b916fecf9b049d0aec0bb94b08ed415 7f09450e270146daa17af4ad3e94ba44--3b916fecf9b049d0aec0bb94b08ed415 fb3fbda282444ac9a26976c77f0ca684 1 ad57d74010a24eac9a1c2d9875cb89e2 3b916fecf9b049d0aec0bb94b08ed415--ad57d74010a24eac9a1c2d9875cb89e2 d5a85493d81349298540bf25368ea2a4 75eede5c397f4eec8bb38eba41786a0f AddBlock fb3fbda282444ac9a26976c77f0ca684--75eede5c397f4eec8bb38eba41786a0f ab50b9bd19514962956d810a1ed18504 2 75eede5c397f4eec8bb38eba41786a0f--d5a85493d81349298540bf25368ea2a4 8b022e06a5314303b39a9d29e799b0ab 8990696c13d24625964b766725843ff7 ab50b9bd19514962956d810a1ed18504--8990696c13d24625964b766725843ff7 8990696c13d24625964b766725843ff7--8b022e06a5314303b39a9d29e799b0ab
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_b8921a9493cf453885b0eef1180b8b3a cluster_660cd2e58fc04313ac7cb601390d2753 rx bfdcd243698c4e95a5c7a3c080ce2ecd 0 63b90b3dd82f4bccb4395f9f4794689e X bfdcd243698c4e95a5c7a3c080ce2ecd--63b90b3dd82f4bccb4395f9f4794689e d243e5a2b8ff4bb0885fe3d6c96618ee 1 6e244aac244b4463be115a7437397fc3 63b90b3dd82f4bccb4395f9f4794689e--6e244aac244b4463be115a7437397fc3 8b515f3060114bb8a2b16159dadedb7d 6e244aac244b4463be115a7437397fc3--8b515f3060114bb8a2b16159dadedb7d 2110282ae1ef4c8ab7a382bb6c59ff88 8b515f3060114bb8a2b16159dadedb7d--2110282ae1ef4c8ab7a382bb6c59ff88 5460b4ff04a7460084c217137114cf6f 1fe91fd3d4974fbbbe9b17b54a212bdc Y d243e5a2b8ff4bb0885fe3d6c96618ee--1fe91fd3d4974fbbbe9b17b54a212bdc 0b6d931fdcec4233b7e47694082303b4 2 66c8588701674606a309a0a4fe475900 1fe91fd3d4974fbbbe9b17b54a212bdc--66c8588701674606a309a0a4fe475900 cdf89be2cd77497a8d7e7e751abf560f HamEvo 66c8588701674606a309a0a4fe475900--cdf89be2cd77497a8d7e7e751abf560f cdf89be2cd77497a8d7e7e751abf560f--5460b4ff04a7460084c217137114cf6f 7145a0ef01d2490bbf9c2aa0f0c9b8a6 8908d3eb97ab49cfaf84ac9eb434cb0f RX(x) 0b6d931fdcec4233b7e47694082303b4--8908d3eb97ab49cfaf84ac9eb434cb0f f3e97d9676cd409b94346e5bc0baa375 3 d330c39ce937469fb900a0bb45c9447f 8908d3eb97ab49cfaf84ac9eb434cb0f--d330c39ce937469fb900a0bb45c9447f c856f1ce50a944e3bf01ef4a33d23ea3 t = 10 d330c39ce937469fb900a0bb45c9447f--c856f1ce50a944e3bf01ef4a33d23ea3 c856f1ce50a944e3bf01ef4a33d23ea3--7145a0ef01d2490bbf9c2aa0f0c9b8a6 aa7141fc52954c9faac4c144b8a192c1 588c40d60414496d8335260a5f3b27de RX(0.5) f3e97d9676cd409b94346e5bc0baa375--588c40d60414496d8335260a5f3b27de 51205cf952c64efcbe1efcbadd2bc62d X 588c40d60414496d8335260a5f3b27de--51205cf952c64efcbe1efcbadd2bc62d 51205cf952c64efcbe1efcbadd2bc62d--d330c39ce937469fb900a0bb45c9447f 01eb8f7f5849447ba6a9e94a01e42578 51205cf952c64efcbe1efcbadd2bc62d--01eb8f7f5849447ba6a9e94a01e42578 01eb8f7f5849447ba6a9e94a01e42578--aa7141fc52954c9faac4c144b8a192c1
from qadence import feature_map, hea, chain

block = chain(feature_map(4, reupload_scaling="Tower"), hea(4,2))
%3 cluster_f3555d93adbc4847a32d702aa2789a00 HEA cluster_defa59274d384accb2884ed91dc8ee07 Tower Fourier FM 228e75ebec884819b4a1748bc15f09f7 0 6c5683fa69ad448987d8f56bb394d499 RX(1.0*phi) 228e75ebec884819b4a1748bc15f09f7--6c5683fa69ad448987d8f56bb394d499 178b95032ab04d1dba0818d4a75d920f 1 7adb3d9d52e34faea5559fb9d242895c RX(theta₀) 6c5683fa69ad448987d8f56bb394d499--7adb3d9d52e34faea5559fb9d242895c ce4d4026cd594fa48ff02e5622b52bb3 RY(theta₄) 7adb3d9d52e34faea5559fb9d242895c--ce4d4026cd594fa48ff02e5622b52bb3 2e593e76e91b4486be25f516187dae29 RX(theta₈) ce4d4026cd594fa48ff02e5622b52bb3--2e593e76e91b4486be25f516187dae29 c383020576794a009a5a94be55210904 2e593e76e91b4486be25f516187dae29--c383020576794a009a5a94be55210904 723cb2a18abd42419477f4517f994b10 c383020576794a009a5a94be55210904--723cb2a18abd42419477f4517f994b10 62d13b5c60794d189dbf3a09e0aa5894 RX(theta₁₂) 723cb2a18abd42419477f4517f994b10--62d13b5c60794d189dbf3a09e0aa5894 7f548d7d078b4b92aaed196f99218258 RY(theta₁₆) 62d13b5c60794d189dbf3a09e0aa5894--7f548d7d078b4b92aaed196f99218258 cf4648dd215840a1a2fb2d126cf5773c RX(theta₂₀) 7f548d7d078b4b92aaed196f99218258--cf4648dd215840a1a2fb2d126cf5773c 754a03a2e0b44be4a7116ebf4245c749 cf4648dd215840a1a2fb2d126cf5773c--754a03a2e0b44be4a7116ebf4245c749 0746eb58edd743599563eec568d74d0d 754a03a2e0b44be4a7116ebf4245c749--0746eb58edd743599563eec568d74d0d 9d89612541b24eef86dcc6e0e5d3fb6f 0746eb58edd743599563eec568d74d0d--9d89612541b24eef86dcc6e0e5d3fb6f e4e57b39002a4302b905d63258b9fb9e e0bb893478844ccaa25e50695c4e521c RX(2.0*phi) 178b95032ab04d1dba0818d4a75d920f--e0bb893478844ccaa25e50695c4e521c 2ab1dd4e75f5406f91faf01d4bb7ac91 2 1898d0056a5943f79255f65cbae57aa8 RX(theta₁) e0bb893478844ccaa25e50695c4e521c--1898d0056a5943f79255f65cbae57aa8 76b4f801259748469d880101dcf31812 RY(theta₅) 1898d0056a5943f79255f65cbae57aa8--76b4f801259748469d880101dcf31812 9e9ea69b108e4afea3349aa6584d0411 RX(theta₉) 76b4f801259748469d880101dcf31812--9e9ea69b108e4afea3349aa6584d0411 9ef2c16e764d4e9a952fdf67d50c3e82 X 9e9ea69b108e4afea3349aa6584d0411--9ef2c16e764d4e9a952fdf67d50c3e82 9ef2c16e764d4e9a952fdf67d50c3e82--c383020576794a009a5a94be55210904 2958a3bbc8d142fc8f66cc9070e3c988 9ef2c16e764d4e9a952fdf67d50c3e82--2958a3bbc8d142fc8f66cc9070e3c988 d1011c29d7474ed28976bac683e6f0d5 RX(theta₁₃) 2958a3bbc8d142fc8f66cc9070e3c988--d1011c29d7474ed28976bac683e6f0d5 f9d80ef22aa64576b9fc8ed441123ade RY(theta₁₇) d1011c29d7474ed28976bac683e6f0d5--f9d80ef22aa64576b9fc8ed441123ade 85de18a715b3437cbba744816ce63939 RX(theta₂₁) f9d80ef22aa64576b9fc8ed441123ade--85de18a715b3437cbba744816ce63939 4c19890493f94e8aad8be12c78073d45 X 85de18a715b3437cbba744816ce63939--4c19890493f94e8aad8be12c78073d45 4c19890493f94e8aad8be12c78073d45--754a03a2e0b44be4a7116ebf4245c749 aab78649ec87454781b413025b3f77a1 4c19890493f94e8aad8be12c78073d45--aab78649ec87454781b413025b3f77a1 aab78649ec87454781b413025b3f77a1--e4e57b39002a4302b905d63258b9fb9e 9443796682264c0eb0ff96c9edd0c1e8 94b251ea197142128af33ba39512ad0b RX(3.0*phi) 2ab1dd4e75f5406f91faf01d4bb7ac91--94b251ea197142128af33ba39512ad0b b3c4bfb50a5e41caa52693e00ad1271d 3 14978d6ed3e044ef87d30bfc53868451 RX(theta₂) 94b251ea197142128af33ba39512ad0b--14978d6ed3e044ef87d30bfc53868451 2da54818830b41a58354ac5471700acc RY(theta₆) 14978d6ed3e044ef87d30bfc53868451--2da54818830b41a58354ac5471700acc 725d1599f0894a83b168aa1102e096af RX(theta₁₀) 2da54818830b41a58354ac5471700acc--725d1599f0894a83b168aa1102e096af 88d4e2d0f23747a189b18da644a2959d 725d1599f0894a83b168aa1102e096af--88d4e2d0f23747a189b18da644a2959d 525a77764f194189a570b291bd3e903f X 88d4e2d0f23747a189b18da644a2959d--525a77764f194189a570b291bd3e903f 525a77764f194189a570b291bd3e903f--2958a3bbc8d142fc8f66cc9070e3c988 801d77b134374cc09f7afe352ae6747b RX(theta₁₄) 525a77764f194189a570b291bd3e903f--801d77b134374cc09f7afe352ae6747b 677ba3de21d240309b92c4ee606e4774 RY(theta₁₈) 801d77b134374cc09f7afe352ae6747b--677ba3de21d240309b92c4ee606e4774 237494a36b7c42a1b6e12173b0e4c498 RX(theta₂₂) 677ba3de21d240309b92c4ee606e4774--237494a36b7c42a1b6e12173b0e4c498 a10d54887be4481bbb3c8cb7c06d0094 237494a36b7c42a1b6e12173b0e4c498--a10d54887be4481bbb3c8cb7c06d0094 64780ea2f8394af6b83417c4313b7ba6 X a10d54887be4481bbb3c8cb7c06d0094--64780ea2f8394af6b83417c4313b7ba6 64780ea2f8394af6b83417c4313b7ba6--aab78649ec87454781b413025b3f77a1 64780ea2f8394af6b83417c4313b7ba6--9443796682264c0eb0ff96c9edd0c1e8 77f4ee23ffe6425fabe1ef659f4d4e76 d90c053ac3ea4dc899aefa92fbe6137b RX(4.0*phi) b3c4bfb50a5e41caa52693e00ad1271d--d90c053ac3ea4dc899aefa92fbe6137b 7419dacb9e254f1cb683209c633ef260 RX(theta₃) d90c053ac3ea4dc899aefa92fbe6137b--7419dacb9e254f1cb683209c633ef260 ee7e7c0ba04b4dbaae4c8d15cb1d4c74 RY(theta₇) 7419dacb9e254f1cb683209c633ef260--ee7e7c0ba04b4dbaae4c8d15cb1d4c74 88a83513d1dd4e4d9a9aeb98e7dca63c RX(theta₁₁) ee7e7c0ba04b4dbaae4c8d15cb1d4c74--88a83513d1dd4e4d9a9aeb98e7dca63c 22604773022e4f3998ae281ca3610751 X 88a83513d1dd4e4d9a9aeb98e7dca63c--22604773022e4f3998ae281ca3610751 22604773022e4f3998ae281ca3610751--88d4e2d0f23747a189b18da644a2959d cbde158435344d309fccb0de14434958 22604773022e4f3998ae281ca3610751--cbde158435344d309fccb0de14434958 6720d5daf18346839632aa0ce14aeed4 RX(theta₁₅) cbde158435344d309fccb0de14434958--6720d5daf18346839632aa0ce14aeed4 d6eaa49f21f348dd9e283c7b8c9d0748 RY(theta₁₉) 6720d5daf18346839632aa0ce14aeed4--d6eaa49f21f348dd9e283c7b8c9d0748 60c0d74864f7480bbada84007c603fd7 RX(theta₂₃) d6eaa49f21f348dd9e283c7b8c9d0748--60c0d74864f7480bbada84007c603fd7 5bb84df2b64e49acac7fece1bab404ae X 60c0d74864f7480bbada84007c603fd7--5bb84df2b64e49acac7fece1bab404ae 5bb84df2b64e49acac7fece1bab404ae--a10d54887be4481bbb3c8cb7c06d0094 b26278c42bb54c9aaa3590358b8eb64b 5bb84df2b64e49acac7fece1bab404ae--b26278c42bb54c9aaa3590358b8eb64b b26278c42bb54c9aaa3590358b8eb64b--77f4ee23ffe6425fabe1ef659f4d4e76
from qadence import QuantumModel, QuantumCircuit, total_magnetization, hea

model = QuantumModel(QuantumCircuit(3, hea(3,2)), total_magnetization(3))
%3 cluster_325939d6ec9942fa89bce5473de3cf45 Obs. cluster_496013cd27ab4b19878945d2f0208a02 cluster_a5c0b13df2b7468b822a3ff2d8d6237e HEA e17bbaa9ebe44be783144846424da699 0 5f958cc1d13c411184cb38ac49163734 RX(theta₀) e17bbaa9ebe44be783144846424da699--5f958cc1d13c411184cb38ac49163734 3c2cb227c8754a19a874d832d23c4f90 1 2d3434b3f4a347c99c771859d34f0638 RY(theta₃) 5f958cc1d13c411184cb38ac49163734--2d3434b3f4a347c99c771859d34f0638 8b07aba28989456c85de7508e0df67cc RX(theta₆) 2d3434b3f4a347c99c771859d34f0638--8b07aba28989456c85de7508e0df67cc e0359dbea9fa49e4b93385d018da55e8 8b07aba28989456c85de7508e0df67cc--e0359dbea9fa49e4b93385d018da55e8 bd9afe073dda4091a9c3d44fee1ccff8 e0359dbea9fa49e4b93385d018da55e8--bd9afe073dda4091a9c3d44fee1ccff8 3269c8894b9d46608832c6a1fa60f6a6 RX(theta₉) bd9afe073dda4091a9c3d44fee1ccff8--3269c8894b9d46608832c6a1fa60f6a6 262823841bff40a9943add66ef002508 RY(theta₁₂) 3269c8894b9d46608832c6a1fa60f6a6--262823841bff40a9943add66ef002508 2c824950c32044c6bdd82c9d72313e2f RX(theta₁₅) 262823841bff40a9943add66ef002508--2c824950c32044c6bdd82c9d72313e2f 605fc0376d484cf5983eda862b3cb096 2c824950c32044c6bdd82c9d72313e2f--605fc0376d484cf5983eda862b3cb096 a596689a763d4b068f6cbc5904983c97 605fc0376d484cf5983eda862b3cb096--a596689a763d4b068f6cbc5904983c97 dc851d7ceb5447dfb41af2a211b8bcf8 a596689a763d4b068f6cbc5904983c97--dc851d7ceb5447dfb41af2a211b8bcf8 b856dae200914f92aae624b9683e5e35 dc851d7ceb5447dfb41af2a211b8bcf8--b856dae200914f92aae624b9683e5e35 34a0fc6650a9492b89cccc4b20367255 02c7e65384174a9997d5a06089f2ee65 RX(theta₁) 3c2cb227c8754a19a874d832d23c4f90--02c7e65384174a9997d5a06089f2ee65 e7b5705e910c430a810cbc9f4e22e706 2 492695df318347dc9ca37e0b186a7912 RY(theta₄) 02c7e65384174a9997d5a06089f2ee65--492695df318347dc9ca37e0b186a7912 928f6a92e3f64bc8a03dde288d144575 RX(theta₇) 492695df318347dc9ca37e0b186a7912--928f6a92e3f64bc8a03dde288d144575 0429c5d34d2040c0a12865fd78d9050e X 928f6a92e3f64bc8a03dde288d144575--0429c5d34d2040c0a12865fd78d9050e 0429c5d34d2040c0a12865fd78d9050e--e0359dbea9fa49e4b93385d018da55e8 d0f7f4e2a4c744918a8a225aa3789203 0429c5d34d2040c0a12865fd78d9050e--d0f7f4e2a4c744918a8a225aa3789203 4595e1cfc408421ba38623397764caa4 RX(theta₁₀) d0f7f4e2a4c744918a8a225aa3789203--4595e1cfc408421ba38623397764caa4 a6e26065aa83471d9670137e3bb98608 RY(theta₁₃) 4595e1cfc408421ba38623397764caa4--a6e26065aa83471d9670137e3bb98608 f0d37626117e4729afcb51ab34c6d7c9 RX(theta₁₆) a6e26065aa83471d9670137e3bb98608--f0d37626117e4729afcb51ab34c6d7c9 d45e5c22c9074763ac3011831cd8d445 X f0d37626117e4729afcb51ab34c6d7c9--d45e5c22c9074763ac3011831cd8d445 d45e5c22c9074763ac3011831cd8d445--605fc0376d484cf5983eda862b3cb096 0f8dd4effc75418e90802332023501a6 d45e5c22c9074763ac3011831cd8d445--0f8dd4effc75418e90802332023501a6 f652cc5e6109472eb418c88f0849998a AddBlock 0f8dd4effc75418e90802332023501a6--f652cc5e6109472eb418c88f0849998a f652cc5e6109472eb418c88f0849998a--34a0fc6650a9492b89cccc4b20367255 d5ab75831c1f45499265960c5d32356d f1691e6cd3e844b286ae83d7b1e3bc97 RX(theta₂) e7b5705e910c430a810cbc9f4e22e706--f1691e6cd3e844b286ae83d7b1e3bc97 d95d4d30f8104e97adc7ce70699b1eab RY(theta₅) f1691e6cd3e844b286ae83d7b1e3bc97--d95d4d30f8104e97adc7ce70699b1eab d0f1bdc963164f84bbe5df8fb7438938 RX(theta₈) d95d4d30f8104e97adc7ce70699b1eab--d0f1bdc963164f84bbe5df8fb7438938 b24d71777ab948509593bb0440234441 d0f1bdc963164f84bbe5df8fb7438938--b24d71777ab948509593bb0440234441 4fee870955b141acbb8d846db8d9c541 X b24d71777ab948509593bb0440234441--4fee870955b141acbb8d846db8d9c541 4fee870955b141acbb8d846db8d9c541--d0f7f4e2a4c744918a8a225aa3789203 85bd3b23be2a428d8bcc8ba899742b0a RX(theta₁₁) 4fee870955b141acbb8d846db8d9c541--85bd3b23be2a428d8bcc8ba899742b0a 8458211098354af8b1f83238db7f20dd RY(theta₁₄) 85bd3b23be2a428d8bcc8ba899742b0a--8458211098354af8b1f83238db7f20dd 16d3eafe34784d218a123113322cb981 RX(theta₁₇) 8458211098354af8b1f83238db7f20dd--16d3eafe34784d218a123113322cb981 3038eec5ecdd4a44be3d792fc170af29 16d3eafe34784d218a123113322cb981--3038eec5ecdd4a44be3d792fc170af29 aff454f9b48c41189e6c63ecbfb37f22 X 3038eec5ecdd4a44be3d792fc170af29--aff454f9b48c41189e6c63ecbfb37f22 aff454f9b48c41189e6c63ecbfb37f22--0f8dd4effc75418e90802332023501a6 f8edf3657d6349cfafdfaf40261ed216 aff454f9b48c41189e6c63ecbfb37f22--f8edf3657d6349cfafdfaf40261ed216 f8edf3657d6349cfafdfaf40261ed216--d5ab75831c1f45499265960c5d32356d
from qadence import *

b = chain(SWAP(0,1), SWAP(0,3))
%3 17043d37763a4502ad1d46fa75848124 0 2ed9a3ff9cfc49a88d44936ce500e42a 17043d37763a4502ad1d46fa75848124--2ed9a3ff9cfc49a88d44936ce500e42a de820b940b924b32a67e4038e2c0f530 1 930def6553fd4af0beaf59a6a929c07b 717dd62253d344d7a1b71ce24d4c3622 2ed9a3ff9cfc49a88d44936ce500e42a--717dd62253d344d7a1b71ce24d4c3622 d3fa59cedb2c4ce2b458095b62f14543 930def6553fd4af0beaf59a6a929c07b--d3fa59cedb2c4ce2b458095b62f14543 887b89ac2cb14d8bb2533e127790e05d f9e3a49d8c774c51b79403cbd897faae d3fa59cedb2c4ce2b458095b62f14543--f9e3a49d8c774c51b79403cbd897faae 981aedf0735b4032a0e5c72936f59298 887b89ac2cb14d8bb2533e127790e05d--981aedf0735b4032a0e5c72936f59298 ce523600cab04bfe87179403ac49a632 cf623eea083a465291a14ee8fcc3b2c4 de820b940b924b32a67e4038e2c0f530--cf623eea083a465291a14ee8fcc3b2c4 4ec20a8ea83442519b592fee93f33019 2 cf623eea083a465291a14ee8fcc3b2c4--930def6553fd4af0beaf59a6a929c07b d0c3f6eb397e45618cebe38fef66da72 717dd62253d344d7a1b71ce24d4c3622--d0c3f6eb397e45618cebe38fef66da72 532124a1329249558fea5c428769a3cb d0c3f6eb397e45618cebe38fef66da72--532124a1329249558fea5c428769a3cb 532124a1329249558fea5c428769a3cb--ce523600cab04bfe87179403ac49a632 14f67a401ea74911b69d13401e2fa74c 1c48f0fccc1e4774bdfc081ce164ea98 4ec20a8ea83442519b592fee93f33019--1c48f0fccc1e4774bdfc081ce164ea98 813a21e6a796401aafb4f008d2b6e78f 3 dea82a5f67d2439ebaad4e637a17a2f7 1c48f0fccc1e4774bdfc081ce164ea98--dea82a5f67d2439ebaad4e637a17a2f7 ee433240b2564ee09a9fa8517b76bcc9 dea82a5f67d2439ebaad4e637a17a2f7--ee433240b2564ee09a9fa8517b76bcc9 8681b2d9bf3842c5bf2cc4e105bb97cb ee433240b2564ee09a9fa8517b76bcc9--8681b2d9bf3842c5bf2cc4e105bb97cb 8681b2d9bf3842c5bf2cc4e105bb97cb--14f67a401ea74911b69d13401e2fa74c 930195b930e2410a94a2ae67b43a79ea 8c4bee8ffdd946469c2c3fbaf03e4a2f 813a21e6a796401aafb4f008d2b6e78f--8c4bee8ffdd946469c2c3fbaf03e4a2f 6df7c9b31e884fc5abe04260972589b9 8c4bee8ffdd946469c2c3fbaf03e4a2f--6df7c9b31e884fc5abe04260972589b9 b1205249eccd4c5fb79449eb8b49ab41 6df7c9b31e884fc5abe04260972589b9--b1205249eccd4c5fb79449eb8b49ab41 b1205249eccd4c5fb79449eb8b49ab41--887b89ac2cb14d8bb2533e127790e05d f9e3a49d8c774c51b79403cbd897faae--930195b930e2410a94a2ae67b43a79ea
from qadence import *

b = chain(CPHASE(0, 1, 0.5), CPHASE(0, 2, 0.5), CPHASE(0, 3, 0.5))
%3 63248458428746038e12c9bb4d9f278e 0 413faf9d4dbc46a98819ba939992d5f9 63248458428746038e12c9bb4d9f278e--413faf9d4dbc46a98819ba939992d5f9 b0714ff75cec4f539337754c59737bc9 1 996465e2b5874f13a370798c8ad213f2 413faf9d4dbc46a98819ba939992d5f9--996465e2b5874f13a370798c8ad213f2 1178e210bcb843bbaffefb6ca3e4b8aa 996465e2b5874f13a370798c8ad213f2--1178e210bcb843bbaffefb6ca3e4b8aa 697ba862cc744b0d9af68e283ffaab06 1178e210bcb843bbaffefb6ca3e4b8aa--697ba862cc744b0d9af68e283ffaab06 16004a74114a466894cbd0cb811b6fd6 ea2ab709d49b43859720945397be4337 PHASE(0.5) b0714ff75cec4f539337754c59737bc9--ea2ab709d49b43859720945397be4337 30e1174cd3ed4929be6deeafd73a2e71 2 ea2ab709d49b43859720945397be4337--413faf9d4dbc46a98819ba939992d5f9 9a9981899c21487fa4b1751cd304161b ea2ab709d49b43859720945397be4337--9a9981899c21487fa4b1751cd304161b 29f640cf975f43bb85a3a94c0f04447c 9a9981899c21487fa4b1751cd304161b--29f640cf975f43bb85a3a94c0f04447c 29f640cf975f43bb85a3a94c0f04447c--16004a74114a466894cbd0cb811b6fd6 75d9e7fbd2a747afa763041b594af82a ee676a7a0dbd4dafbfaceab727c08336 30e1174cd3ed4929be6deeafd73a2e71--ee676a7a0dbd4dafbfaceab727c08336 d97461b25c194249a877c5cdf6f75ead 3 5b709b0f55a34a1a8d04ef0ad1a8347f PHASE(0.5) ee676a7a0dbd4dafbfaceab727c08336--5b709b0f55a34a1a8d04ef0ad1a8347f 5b709b0f55a34a1a8d04ef0ad1a8347f--996465e2b5874f13a370798c8ad213f2 c7e2ec0c241d47fb8bf64766885b4e10 5b709b0f55a34a1a8d04ef0ad1a8347f--c7e2ec0c241d47fb8bf64766885b4e10 c7e2ec0c241d47fb8bf64766885b4e10--75d9e7fbd2a747afa763041b594af82a 3a79e40311164a2c8e53daec562c64fa eca7bb81749a49089235286cfdf724cf d97461b25c194249a877c5cdf6f75ead--eca7bb81749a49089235286cfdf724cf 10891e7fdc324611892904060ffc0aa4 eca7bb81749a49089235286cfdf724cf--10891e7fdc324611892904060ffc0aa4 df286ddacd214ca7b11f7a22b24f25bb PHASE(0.5) 10891e7fdc324611892904060ffc0aa4--df286ddacd214ca7b11f7a22b24f25bb df286ddacd214ca7b11f7a22b24f25bb--1178e210bcb843bbaffefb6ca3e4b8aa df286ddacd214ca7b11f7a22b24f25bb--3a79e40311164a2c8e53daec562c64fa

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