Closed dabacon closed 5 years ago
I did the same thing while decomposing a gate into e.g. [X**(gate_param+0.5), ...]. This would be useful.
It turns out that many gate's _circuit_diagram_info_
crash if the gate parameter is a formula.
@dabacon Am I missing any features not in the referencing PRs?
I think this is great! The one thing I don't see in the ParamFlattener is the case where teh formula is the same and a small helper to do this all in one pass.
What do you mean by "the case where the formula is the same"?
The case where Symbol('a') + 1
appears in multiple gates.
Yes. That is already handled in #1963.
I just found that this doesn't work as expected when two gates have a+1
and a+1.0
(#1997).
Quite accidentally I ran an optimization pass which ended up working correctly but changing a parameter to a formula in sympy, like Symbol('a') + 1.23.
It occurred to me that if we allow this, then we could support a flow where you a) do compilations that support formulas in parameters b) create parameter sweeps c) unwind the sweeps and then calculate the values of the formulas in the parameters. I think this could have a problem where you have different formulas for the same parameter or parameters entering multiple times, but I don't see a fundamental problem with this. d) now you have some parameters and some parameterized circuits which you can send off to a simulator or a quantum computer!