Qualtran
Qualtran copied to clipboard
Symbolic analysis for bloqs that expect a sequence of objects as inputs but only care about the length of the sequence for symbolic costs
I couldn't find a way to define a sequence (list / tuple) using sympy where the length of the sequence is a symbolic parameter. This is often useful to specify costs of Bloqs which expect sequences as inputs but the call graph really only depends upon the length of this sequence. This is useful for a variety of Bloqs, like
- Bloqs that expect control values - https://github.com/quantumlib/Qualtran/issues/786
-
GQSP
- https://github.com/quantumlib/Qualtran/pull/669#discussion_r1529250665 -
QROM
- The T-cost depends mainly on the iteration length of the data while the clifford cost depends upon the actual values of the data (I'm sure there are more Bloqs that we should append to this list)
Let's figure out a way to support this. One way would be to have a custom wrapper class for sequences that can be instantiated via either just shape
(which can be symbolic) or the actual data (in which case shape
can be derived). Open to other suggestions.
cc @mpharrigan
Yeah, we could have a class that just has a shape and either raises an error if you try to index into it or yields sympy symbols like Shaped(name='x', shape=(3,))[2] = Symbol('x_2')
Do we want to wrap our data or just accept Union[NDArray, Shaped]
. This is consistent with how we generally do n: Union[int, sympy.Expr]
implemented in #867