Qualtran
Qualtran copied to clipboard
`CtrlSpec` add support for symbolic `Shaped` control values
Useful when we know the number of controls, e.g. https://github.com/quantumlib/Qualtran/pull/1155#discussion_r1684923203
Related #786
What is missing?
Requires some fixes to how shapes and num_qubits are computed to work with symbolics, and updated type hints. Didn't want to over-complicate #1155, so this can be done in a follow-up.
@anurudhp @mpharrigan I am finding that MultiControlX(symbolic n).controlled() is causing issues. This issue was linked in the build_call_graph function for MultiControlX with symbolic cvs - what's required to fix this?
Code to reproduce:
n = sympy.symbols('n', integer=True) bloq = MultiControlX(cvs=HasLength(n)).controlled(ctrl_spec=CtrlSpec(cvs=0)) cost = get_cost_value(bloq, QECGatesCost()).total_t_and_ccz_count()
@fpapa250 this will be fixed by #1492 (which removes the call graph override and uses the default from ControlledViaAnd). I tested the code snippet against that branch and it prints {'n_t': 0, 'n_ccz': n}
Awesome! That will unblock https://github.com/quantumlib/Qualtran/pull/1489. Equals.controlled breaks down to that case and is causing issues with the symbolic cost unit test.