Closed LeonWubben closed 1 year ago
Hello @LeonWubben, sorry for the late reply. Thanks a lot for pointing those out!
Yes, you are right, the docs are a bit incomplete there. For the arg_value
, indeed it can be a tuple or even a dictionary as long as it is adequately treated when creating the corresponding unitary. Something similar to qc.add_gate("r_gate", targets=q, args={"theta": np.pi, "phi": 0}
is already used in a few places in qutip-qip
.
You are very welcome to open a PR if you have time. Otherwise, I'll deal with it in a few days.
Currently the parameters for
QubitCircuit.add_gate
require:1. is fine, however just integers work as in the method it's straight up put in a
Gate
object which does accept both integers and lists. In one of your examples inScheduler.schedule
the targets and controls are also inputted as plain ints, which some IDEs will mark as errors or for example mypy just straight up gives it an error in CI/CD if you run a type checker. So my suggestion is to update the type hint inadd_gate
to also include integers inline with theGate
object.My main issue is with 2.
arg_value
is an object that is put raw in a (potentially) user defined method for the gate. Two issues with that:For example if you have a gate that implements a general single qubit you need two angles to define that:
def r_gate(theta: float, phi: float) -> Qobj
. However at most one parameter is allowedSo for now I have done something like
qc.add_gate("r_gate", targets=[q], arg_values=(np.pi, 0))
, (which gives a type error because(np.pi, 0)
is a tuple, not a float). And then in the method I need to addtheta, phi = args
.Whereas ideally I can just do
qc.add_gate("r_gate", targets=q, theta=np.pi, phi=0)
orqc.add_gate("r_gate", targets=q, args={"theta": np.pi, "phi": 0}
. So I request to change thearg_value
with a proper**args
that are directly inputted into the gate function as arguments. Or at least change the type ofarg_value
to from float Any