zxcalc / pyzx

Python library for quantum circuit rewriting and optimisation using the ZX-calculus
Apache License 2.0
385 stars 116 forks source link

support custom gates with phases #220

Open dlyongemallo opened 6 months ago

dlyongemallo commented 6 months ago

In particular, I'd like to use Qiskit's random_circuit function, but it generates custom gates with phase parameters. For example:

from pyzx.circuit import Circuit
from qiskit.circuit.random import random_circuit
from qiskit.qasm2 import dumps
...
qiskit_circ = random_circuit(qubits, depth)
qasm = dumps(qiskit_circ)
circ = Circuit.from_qasm(qasm)

This generates code such as:

OPENQASM 2.0;
include "qelib1.inc";
gate r(param0,param1) q0 {
    u3(param0,param1 - pi/2,pi/2 - 1.0*param1) q0;
}
qreg q[1];
r(pi/2,pi/4) q[0];
dlyongemallo commented 6 months ago

The above raises a TypeError in this line.