Skip to content
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

Change return type of build_call_graph to set | dict #1356

Merged
merged 16 commits into from
Sep 5, 2024

Conversation

dstrain115
Copy link
Contributor

  • Changes build_call_graph to return a Union of Dict[Bloq, Union[int, Expr]] and Set[BloqCountT]
  • Adds checks in main call sites to check both cases.

- Changes build_call_graph to return a Union of
Dict[Bloq, Union[int, Expr]] and Set[BloqCountT]
- Adds checks in main call sites to check both cases.
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is generally what I'm looking for 👍

qualtran/_infra/controlled.py Outdated Show resolved Hide resolved
qualtran/resource_counting/_call_graph.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using Counter, and remove the print statements; but after that lgtm


import networkx as nx
import sympy

from qualtran import Bloq, CompositeBloq, DecomposeNotImplementedError, DecomposeTypeError

BloqCountT = Tuple[Bloq, Union[int, sympy.Expr]]
BloqCountDictT = Dict[Bloq, Union[int, sympy.Expr]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could perhaps use Mapping here instead of dict? As build_call_graph is an internal function, would make it easier for bloq authors to return any mapping (eg. Counter instead of casting to dict for mypy).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

@dstrain115 dstrain115 requested a review from anurudhp August 30, 2024 13:30
counts[bloq.adjoint()] += n
return counts
else:
return {bloq.adjoint(): n for bloq, n in sub_cg.items()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be worried about a situation where different bloqs return the same adjoint()? I think it should never happen, but am not so sure. (same concern for bloq.controlled()).

@mpharrigan @tanujkhattar?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an interesting corner case to consider; and the type of thing we need to be concerned about now that we are being strict about having only unique bloqs in the callees. I don't think it should happen. I defer to @dstrain115 on whether he thinks it's worth defending against that vs blocking progress on the overall migration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the Counter for both sets and dicts, which should alleviate the concern. Will push tomorrow unless there are any further issues.

Copy link
Contributor

@anurudhp anurudhp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor concern about uniqueness of adjoints/controlleds, otherwise lgtm!

@dstrain115 dstrain115 merged commit 76fdc9d into quantumlib:main Sep 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants