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

Field canonicalization #661

Merged
merged 13 commits into from
Oct 4, 2023
Merged

Field canonicalization #661

merged 13 commits into from
Oct 4, 2023

Conversation

weinbe58
Copy link
Member

@weinbe58 weinbe58 commented Oct 2, 2023

  • Making waveform IR nodes frozen and therefore hashable.
    • This involve having to hack the casting by using object.__set_attr__ in the __post_init__ which isn't idea. Another option for this would be to overload constructor methods that use arbitrary inputs and dispatch those to the default pydantic constructor after casting to scalar values.
  • Merging Scaled locations together if they share the same waveform.
  • Adding create function for PythonFn node so that Code gen doesn't need to use hacky object.__set_attr__ to do variable assignment.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

PR Preview Action v1.4.4
Preview removed because the pull request was closed.
2023-10-04 15:37 UTC

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Merging #661 (af4c1b9) into main (cdd2bfe) will increase coverage by 0.11%.
The diff coverage is 97.61%.

@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   84.91%   85.02%   +0.11%     
==========================================
  Files          89       89              
  Lines        7419     7427       +8     
==========================================
+ Hits         6300     6315      +15     
+ Misses       1119     1112       -7     
Files Coverage Δ
src/bloqade/builder/waveform.py 98.41% <100.00%> (ø)
src/bloqade/ir/control/field.py 87.00% <100.00%> (+3.00%) ⬆️
src/bloqade/ir/tree_print.py 93.82% <100.00%> (+0.03%) ⬆️
src/bloqade/codegen/common/assign_variables.py 86.12% <87.50%> (-0.19%) ⬇️
src/bloqade/ir/control/waveform.py 89.08% <97.59%> (+0.99%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Roger-luo
Copy link
Member

I forgot the exact reason, but IIRC there was a reason why we removed the frozen=True from the IR objects back in May. Do you remember why was that? I think it was causing trouble for something.

@weinbe58
Copy link
Member Author

weinbe58 commented Oct 2, 2023

@Roger-luo Its because Python doesn't have casting. so if you make a dataclass with a Scalar field there is no way to tell the interpreter how to cast other types to that specific type.

@Roger-luo
Copy link
Member

I'm confused, how does casting effect mutability here?

@weinbe58
Copy link
Member Author

weinbe58 commented Oct 3, 2023

Take the Constant node, it takes two arguments value and duration if I do not overload the constructor and try to do self.value = cast(value) I get an error because that field is not mutable.

@Roger-luo
Copy link
Member

Ah yes, because dataclass cannot invoke a type conversion method, that's dumb. I think we should define our own metaclass or custom field initializer using @dataclass_transform at some point. But yeah I'm convinced with the motivation of this PR now

@Roger-luo
Copy link
Member

A reference implementation can be found here https://github.com/patrick-kidger/equinox/blob/main/equinox/_module.py#L46

@weinbe58 weinbe58 mentioned this pull request Oct 3, 2023
@weinbe58 weinbe58 requested a review from Roger-luo October 4, 2023 01:01
@weinbe58 weinbe58 merged commit 3659e3d into main Oct 4, 2023
8 checks passed
@weinbe58 weinbe58 deleted the field-canonicalization branch October 4, 2023 15:35
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.

2 participants