Quandela / Perceval

An open source framework for programming photonic quantum computers
https://perceval.quandela.net
Other
145 stars 66 forks source link

Beautify display of circuits #205

Closed jsenellart closed 1 year ago

jsenellart commented 1 year ago

Describe the Feature Request Renderer of processor produces non aesthetic circuits, where components are not nicely aligned as a human would do. See the attached pictures. The reason is coming from automatic placement of the components that do not take into account global symmetry/semantic of the circuit

To Reproduce Steps to reproduce the behavior: In a notebook, or editor with support of matplotlib renderer:

import perceval as pcvl
import numpy as np
import random
bs = pcvl.Circuit.generic_interferometer(4,
                                         lambda idx : pcvl.BS(theta=pcvl.P("theta_%d"%idx))//(0, pcvl.PS(phi=np.pi*2*random.random())),
                                         shape="rectangle",
                                         depth = 2*4,
                                         phase_shifter_fun_gen=lambda idx: pcvl.PS(phi=np.pi*2*random.random()))
pcvl.pdisplay(bs)

Expected behavior In such interferemoter, we expect some alignement of the beamsplitters that cannot naturally be achieved because of the intermediate phaseshifters

image

When defining a circuit, we should have a way to give horizontal grid position (x_grid in the code below)

Circuit(3).add(0, pcvl.BS(), x_grid=1).add(0, pcvl.PS(1), x_grid=2).add(2, pcvl.PS(1), x_grid=2)

3) the x_grid would be an incremental index not mapping to a specific position but with the following semantic:

Additional context

In notebook, a svg renderer is used (perceval/rendering/canvas/svg_canvas.py), in editor, matplotlib renderer is used (perceval/rendering/canvas/mplot_canvas.py)

FDGod99 commented 1 year ago

Hello, I would like to work on this issue. Any tips/suggestions to get started?