-
Notifications
You must be signed in to change notification settings - Fork 80
[Costs] Qubit Counts #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Costs] Qubit Counts #969
Conversation
|
|
||
| from ._costing import GeneralizerT, get_cost_value, get_cost_cache, query_costs, CostKey, CostValT | ||
|
|
||
| from ._qubit_counts import QubitCount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it a private module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to force imports of the form
from qualtran.resource_counting import QubitCount
instead of
from qualtran.resource_counting.qubit_counts import QubitCount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the underscore isn't necessary though right? You could still do from .qubit_counts import QubitCount no? Or are you saying you don't want me to import from qubit_counts ever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the latter
fdmalone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll need to play around with it some more to check the chemistry algorithms.
tanujkhattar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question about scalability, do we have any plans to address it? Is it worth discussing the design choices again and whether my_static_costs should be really only overridden for the leaf bloqs?
| try: | ||
| cbloq = bloq.decompose_bloq() | ||
| logger.info("Computing %s for %s from its decomposition", self, bloq) | ||
| return _cbloq_max_width(cbloq._binst_graph, get_callee_cost) | ||
| except (DecomposeNotImplementedError, DecomposeTypeError): | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good example of a cost which doesn't scale for large bloqs, as I had raised a concern for in your previous PR (cc #957)
Do we have a plan to make this scalable? Do we plan to do isinstance based dispatch for special bloqs as you had proposed in #913 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for something like Add or QROM (which is the slow part in hubbard model) you can annotate the static qubit counts statically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. And I think the right way to annotate these static costs is to express the cost as a formula of the cost of its callees. For example - the SelectSwapQROM can express its qubit counts in terms of qubit_count(QROM) and qubit_count(SwapWithZero) bloqs. Similarly, phase estimation can express its cost in terms of qubit_count(U); instead of specifying a constant (which is not even possible for phase estimation since U is unknown and decomposing phase estimation can be costly in general, since you end up with a circuit where the depth is at least 2 ** size(phase_register))
For this to scale, it would be really nice if my_static_costs has access to the cache and can forward it to the get_cost_value method to get the cost of its callees. Since we are designing the API right now, it'll be easier to make this change and be future proof so I'd suggest you to reconsider this proposal.
After many offline discussions it seems its hard to reach a consensus. I'll dismiss my blocking review so we can make progress and potentially revisit later if needed.

This introduces a
CostKeyto count qubits. Part of #899.