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

Symbolic Shaped #867

Merged
merged 5 commits into from
Apr 26, 2024
Merged

Conversation

anurudhp
Copy link
Contributor

@anurudhp anurudhp commented Apr 11, 2024

Discussion: #801

@anurudhp anurudhp marked this pull request as draft April 11, 2024 16:27
@anurudhp anurudhp force-pushed the 2024-04-symbolic-shaped branch 3 times, most recently from 10fe6aa to 7ff633e Compare April 11, 2024 22:21
@anurudhp anurudhp marked this pull request as ready for review April 14, 2024 17:58
@anurudhp
Copy link
Contributor Author

@mpharrigan @tanujkhattar could you take a look at this?

Comment on lines 29 to 41
class Shaped:
shape: tuple[SymbolicInt, ...] = field(validator=validators.instance_of(tuple))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you write a motivating docstring? This is a qualtran-specific concept that needs to be thoroughly documented: what it is, why we need it, how you might use it

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 attempted to explain it a bit, could you check how it looks?

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.

very cool. Some polish things in the comments

@mpharrigan mpharrigan changed the title Prototype: support for symbolic Shaped Symbolic Shaped Apr 15, 2024
@anurudhp anurudhp force-pushed the 2024-04-symbolic-shaped branch 5 times, most recently from 7dd5aa0 to 2342b88 Compare April 24, 2024 11:43
fix expression for Jacobi-Anger degree

add test using 1d ising walk op, fix call graph

fix test

fix hamsim nb

`slen`, docstrings, generalize `is_symbolic` (to remove dep. on cirq)

test shape with symbolic entries

docstring refs: remove extra indent

skip serialize test for symbolic hamsim
@anurudhp anurudhp force-pushed the 2024-04-symbolic-shaped branch from 2342b88 to 17d6fa7 Compare April 25, 2024 22:35
@anurudhp anurudhp force-pushed the 2024-04-symbolic-shaped branch from ca44e0b to 653ae04 Compare April 25, 2024 22:51
@@ -180,18 +172,6 @@ def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: 'SoquetT') -> Dict[str

return soqs

def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happened to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need a specialization anymore, it works automatically through GeneralizedQSP's call graph.

Before this, there was no way to build GQSP without the exact polynomial, so I had to override it here.

if len(args) != 1:
return any(is_symbolic(arg) for arg in args)

(arg,) = args
Copy link
Collaborator

Choose a reason for hiding this comment

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

handle len(args)==0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to my surprise, it seems any(...) for an empty generator returns False, so line 56 automatically handles this case

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah got it, thanks

return any(is_symbolic(arg) for arg in args)

(arg,) = args
if isinstance(arg, sympy.Basic):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should be checking isinstance(arg, sympy.Expr), right?

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'm not sure actually, I just copied it from the existing code.

It seems boolean expressions are instances of sympy.Basic but not sympy.Expr (https://docs.sympy.org/latest/explanation/glossary.html#term-Expr), which we may want to use for symbolic controls?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. Interesting reading. Happy keeping this as Basic for now

@anurudhp anurudhp requested a review from mpharrigan April 26, 2024 14:18
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.

Very useful contribution for more symbolic costings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants