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

Fix nonumerics in for-loops #41

Merged
merged 3 commits into from Apr 8, 2021
Merged

Fix nonumerics in for-loops #41

merged 3 commits into from Apr 8, 2021

Conversation

thisac
Copy link
Contributor

@thisac thisac commented Mar 29, 2021

Using bool or string in for loop iterators isn't working properly. Currently, it returns None, instead of the wanted string or bool. This PR fixes the issue, so that e.g. the following works.

name test_name
version 1.0
target fock (num_subsystems=1, cutoff_dim=7, shots=10)

for bool i in [True, False]
    UnaryGate(i, {param}) | 0

@thisac thisac self-assigned this Mar 29, 2021
@thisac thisac requested a review from josh146 March 29, 2021 17:09
@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

Merging #41 (be4f1d3) into master (d847ed9) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   97.16%   97.17%   +0.01%     
==========================================
  Files          12       12              
  Lines        1902     1914      +12     
==========================================
+ Hits         1848     1860      +12     
  Misses         54       54              
Impacted Files Coverage Δ
blackbird_python/blackbird/listener.py 99.59% <100.00%> (+<0.01%) ⬆️
blackbird_python/blackbird/tests/test_listener.py 100.00% <100.00%> (ø)

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 d847ed9...be4f1d3. Read the comment docs.

josh146
josh146 previously approved these changes Apr 5, 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! Only suggestion is to add another test, using the boolean for loop variable within the for loop.

Comment on lines 836 to 852
def test_for_bool(self, parse_input_mocked_metadata):
"""Test that a for-loop over a list containing bools is parsed correctly"""
bb = parse_input_mocked_metadata(
"for bool b in [True, False]\n\tMeasureFock() | 0"
)
assert np.all(
bb._forvar["b"] == np.array([True, False])
)

def test_for_str(self, parse_input_mocked_metadata):
"""Test that a for-loop over a list containing strings is parsed correctly"""
bb = parse_input_mocked_metadata(
'for str s in ["one", "two"]\n\tMeasureFock() | 0'
)
assert np.all(
bb._forvar["s"] == np.array(["one", "two"])
)
Copy link
Member

Choose a reason for hiding this comment

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

Nice tests, although, should they also be testing for the case where the boolean for loop variable is used within the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the test to use the bool inside the loop. Not sure if there's another way of testing it. 🤔

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.

Thanks Theo!

@thisac thisac merged commit 34f7c6f into master Apr 8, 2021
@thisac thisac deleted the nonnumerics-in-for branch April 8, 2021 14:30
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