-
Notifications
You must be signed in to change notification settings - Fork 121
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
Implement braket.ahs.AnalogHamiltonianSimulation.from_ir()
#983
Conversation
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.
Very precise work, thank you for contributing this PR. I highlighted few changes that would make this ready for approval.
def test_from_ir(ir): | ||
ahs = AnalogHamiltonianSimulation.from_ir(ir) | ||
problem = ahs.to_ir() | ||
assert Program.parse_raw(problem.json()) == problem |
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.
Instead of comparing the returned value of program
with Program.parse_raw(program.json())
, which tests the functionality of parse_raw
and .json
, it will be more reliable to compare AnalogHamiltonianSimulation.from_ir(ir).to_ir()
with ir
.
) | ||
) | ||
problem = ahs.to_ir() | ||
assert Program.parse_raw(problem.json()) == problem |
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.
Instead of comparing the returned value of program
with Program.parse_raw(program.json())
, which tests the functionality of parse_raw
and .json
, it will be more reliable to compare AnalogHamiltonianSimulation.from_ir(ir).to_ir()
with ir
.
hamiltonian = Hamiltonian() | ||
for term in source.hamiltonian.drivingFields: | ||
amplitude = ( | ||
Field( |
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 logic to construct this Field
is repeated four times. It looks like there is a good need for adding a factory method to Field
. Please create that, and use it here to make the code more maintainable.
@peterkomar-aws Thank you for reviewing! I made the change based on your review. |
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.
Only one minor suggestions. Looks good to me. Thanks for the quick turnaround. Great work!
src/braket/ahs/field.py
Outdated
|
||
time_series = TimeSeries.from_lists(times=times, values=values) | ||
|
||
drive = Field(time_series=time_series, pattern=Pattern(pattern)) |
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.
Let's name the variable field
instead of drive
to be more descriptive.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #983 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 135 135
Lines 8919 8941 +22
Branches 2002 2008 +6
=========================================
+ Hits 8919 8941 +22 ☔ View full report in Codecov by Sentry. |
Hi @king-p3nguin , all tests are passing, there is only a minor test coverage degradation (see the coverage report). Can you add a test that covers L110 of the analog_hamiltonian_simulation module? |
@peterkomar-aws Thank you for reporting. It seems like the |
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.
Nice work. Thanks for the contribution.
Issue #, if available:
Description of changes:
braket.ahs.AnalogHamiltonianSimulation.from_ir()
was implemented.Testing done:
Input:
Output:
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.