Quantomatic / zxlive

A graphical tool for the ZX calculus
Apache License 2.0
44 stars 14 forks source link

Support basic expressions for parameterised spiders #232

Open wlcsm opened 3 months ago

wlcsm commented 3 months ago

Parameterised spiders currently support fractions of pi e.g. "\pi/2", but not more complex expressions such as (k + l) * \pi where k and l are parameters. This should be achievable by storing the phase as a sympy expression.

Steps to reproduce.

  1. Double click on a spider and input the phase (k + l) * \pi

Currently ZXLive will produce an error with stating the input is invalid

RazinShaikh commented 3 months ago

We already support this as all parametric angles are taken to be multiples of pi

RazinShaikh commented 3 months ago

We do not use sympy expression as we built the symbolic module in PyZX, which has some advantages over sympy

wlcsm commented 3 months ago

I can understand that requiring the phases to be a multiple of pi is a design decision. Though it It seems like we cannot implement phrases such as (k + l) * pi or (a + 1) * \pi. Though it is possible to create two spiders, one with phase l * \pi and the other with phase k * \pi and fuse them together to obtain (k + l) * \pi.

So it seems like expressions are supported, but inputting them directly isn't. So it may just be a problem with the input validation. What are the advantages of the symbolic module over sympy?

RazinShaikh commented 3 months ago

Yeah, the input parsing needs to be updated. The benefit of the symbolic module is that it allows for more integrated custom behavior. For example, we can have specific rewrites based on the type of the variable (boolean or parametric), perform automatic substitutions from custom rewrites, etc.

dlyongemallo commented 3 months ago

Double click on a spider and input the phase (k + l) * \pi

But this works without the "*pi", doesn't it? I was able to do this:

arithmetic_phase

RazinShaikh commented 3 months ago

Yes, but it would be nice to allow the input to be more flexible. In fact, for symbolic values, it doesn't even make sense to ask for inputs in units of pi (unless the type of the variable is Boolean).