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

Access p-type variables #47

Merged
merged 8 commits into from Sep 8, 2021
Merged

Access p-type variables #47

merged 8 commits into from Sep 8, 2021

Conversation

thisac
Copy link
Contributor

@thisac thisac commented Aug 30, 2021

  • Adds a public method to retrieve Blackbird program variables via prog.variables
  • Improves match_template to automatically return matched parameters with their array values, rather than their array names (p0, p1, etc.)
  • Removes p-type parameters from prog.parameters since they're only needed there internally and are otherwise stored in prog.variables. This also changes TDM programs to not be templates (prog.is_template now returns False).

@codecov
Copy link

codecov bot commented Aug 30, 2021

Codecov Report

Merging #47 (f3dfb4a) into master (14182f2) will increase coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   97.18%   97.30%   +0.12%     
==========================================
  Files          12       12              
  Lines        1915     1929      +14     
==========================================
+ Hits         1861     1877      +16     
+ Misses         54       52       -2     
Impacted Files Coverage Δ
blackbird_python/blackbird/listener.py 100.00% <100.00%> (+0.40%) ⬆️
blackbird_python/blackbird/program.py 99.50% <100.00%> (+<0.01%) ⬆️
blackbird_python/blackbird/tests/test_program.py 100.00% <100.00%> (ø)
blackbird_python/blackbird/tests/test_utils.py 100.00% <100.00%> (ø)
blackbird_python/blackbird/utils.py 100.00% <100.00%> (ø)
blackbird_python/blackbird/auxiliary.py 100.00% <0.00%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14182f2...f3dfb4a. Read the comment docs.

@thisac thisac marked this pull request as ready for review September 1, 2021 22:45
@thisac thisac changed the title [WIP] Access p-type variables Access p-type variables Sep 1, 2021
@thisac thisac requested a review from josh146 September 1, 2021 22:50
@thisac thisac self-assigned this Sep 1, 2021
josh146
josh146 previously approved these changes Sep 3, 2021
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Nice update, looks good from my end @thisac!

Comment on lines +32 to +33
are otherwise stored in `prog.variables`. This also changes TDM programs to not be templates
(`prog.is_template` now returns `False`).
Copy link
Member

Choose a reason for hiding this comment

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

Just out of curiosity - is there a consequence of TDM programs not being templates any more?

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 don't think so, no. As far as I know this is just a consequence of how we decided to implement these p-type parameters internally. It only blocks the use of the match_template function for all TDM programs (this fixes that).

@@ -561,7 +561,8 @@ def exitProgram(self, ctx: blackbirdParser.ProgramContext):
self._program._var.update(_VAR)
_VAR.clear()

self._program._parameters.extend(_PARAMS)
is_ptype = lambda p: str(p)[0] == "p" and str(p)[1:].isdigit()
Copy link
Member

Choose a reason for hiding this comment

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

Very minor suggestion, but you could define this function at the module level, since it doesn't seem to depend on closure :)

josh146
josh146 previously approved these changes Sep 8, 2021
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Looks good from my end @thisac!

.github/CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines +85 to +87
def is_ptype(p):
"""Checks whether a parameter is in the form `p0`, `p1`, etc."""
return str(p)[0] == "p" and str(p)[1:].isdigit()
Copy link
Member

Choose a reason for hiding this comment

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

Feels much cleaner this way :)

Co-authored-by: Josh Izaac <josh146@gmail.com>
@thisac thisac merged commit 700af3b into master Sep 8, 2021
@thisac thisac deleted the access-p-vars branch September 8, 2021 14:04
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.

None yet

2 participants