softwareQinc / staq

Full-stack quantum processing toolkit
https://iopscience.iop.org/article/10.1088/2058-9565/ab9359/pdf
MIT License
155 stars 28 forks source link

A minor problem? #33

Closed DevelopDaily closed 3 years ago

DevelopDaily commented 3 years ago

Here is a test file input.qasm:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];

cu1(pi/4) q[0], q[1];
cu1(pi/4) q[0], q[1];
cu1(pi/4) q[0], q[1];
cu1(pi/4) q[0], q[1];

I run this:

./staq -S -O3 -o output.qasm input.qasm

The output will be:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
s q[1];
s q[0];
cx q[1],q[0];
rz((((-(pi/4)/2)+(-(pi/4)/2))+(-(pi/4)/2))+(-(pi/4)/2)) q[0];
cx q[1],q[0];

The argument of the rzgate does not look nice. Its length will grow with the number of the cu1gates. It also happens on other gates. Would it be nice if the staqcould evaluate the arguments of gates? Is it too difficult for the staqto achieve that? Any pros and cons?

By the way, the problem is considered minor because the argument expression is evaluated by the qpp correctly. When the staqAPI is used to traverse the circuit, it also correctly evaluates that to rz(-1.57).

meamy commented 3 years ago

Agreed! The argument of the rz gate is definitely not ideal.

For the purposes of some optimizations in staq it's better to keep the arguments here symbolic rather than to outright evaluate them, but definitely it would be nice and possible to simplify these symbolic expressions. I'll put that on the to do list --- it's been something that we wanted to do for a long time anyway.

525125 commented 3 years ago

@DevelopDaily We've added parameter expression simplification