Skip to content

Commit

Permalink
Switch measurements kwargs to args in io.to_blackbird (#622)
Browse files Browse the repository at this point in the history
* switch measurements kwargs to args

* Update tests/frontend/test_io.py

Co-authored-by: Luke Helt <31250931+heltluke@users.noreply.github.com>

* update changelog

Co-authored-by: Luke Helt <31250931+heltluke@users.noreply.github.com>
  • Loading branch information
thisac and heltluke committed Sep 2, 2021
1 parent a5e5f44 commit 724b0a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

* `measure_threshold` in the `gaussian` backend now supports displaced Gaussian states.
[(#615)](https://github.com/XanaduAI/strawberryfields/pull/615)

* Speed improvements to ``gaussian_unitary`` compiler
[(#603)](https://github.com/XanaduAI/strawberryfields/pull/603)

Expand All @@ -167,6 +167,10 @@
`timebins % concurrent_modes != 0`.
[(#611)](https://github.com/XanaduAI/strawberryfields/pull/611)

* Measurement arguments are now stored as non-keyword arguments, instead of keyword arguments, in
the resulting Blackbird program when using the `io.to_blackbird()` converter function.
[(#622)](https://github.com/XanaduAI/strawberryfields/pull/622)

<h3>Documentation</h3>

* References to the ``simulon`` simulator target have been rewritten to
Expand Down
2 changes: 1 addition & 1 deletion strawberryfields/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def to_blackbird(prog, version="1.0"):

if cmd.op.p:
# argument is quadrature phase
op["kwargs"]["phi"] = cmd.op.p[0]
op["args"] = cmd.op.p

if op["op"] == "MeasureFock":
# special case to take into account 'dark_counts' keyword argument
Expand Down
16 changes: 8 additions & 8 deletions tests/frontend/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def prog():
Dgate(0.735934779718964, 0.7469555733762603) | 1
S2gate(0.543, -0.12) | [0, 3]
Interferometer(A0) | [0, 1, 2, 3]
MeasureHomodyne(phi=0) | 0
MeasureHomodyne(select=0.32, phi=0.43) | 2
MeasureHomodyne(select=0.32, phi=0.43) | 2
MeasureHomodyne(0) | 0
MeasureHomodyne(0.43, select=0.32) | 2
MeasureHomodyne(0.43, select=0.32) | 2
"""


Expand Down Expand Up @@ -280,8 +280,8 @@ def test_measure_arg(self):
expected = {
"op": "MeasureHomodyne",
"modes": [0],
"args": [],
"kwargs": {"phi": 0.43},
"args": [0.43],
"kwargs": {},
}

assert bb.operations[0] == expected
Expand All @@ -298,8 +298,8 @@ def test_measure_arg_postselect(self):
expected = {
"op": "MeasureHomodyne",
"modes": [0],
"args": [],
"kwargs": {"phi": 0.43, "select": 0.543},
"args": [0.43],
"kwargs": {"select": 0.543},
}

assert bb.operations[0] == expected
Expand Down Expand Up @@ -358,7 +358,7 @@ def test_tdm_program(self):
assert bb.operations[0] == {'kwargs': {}, 'args': [0.7, 0], 'op': 'Sgate', 'modes': [1]}
assert bb.operations[1] == {'kwargs': {}, 'args': ['p0', 0.0], 'op': 'BSgate', 'modes': [0, 1]}
assert bb.operations[2] == {'kwargs': {}, 'args': ['p1'], 'op': 'Rgate', 'modes': [1]}
assert bb.operations[3] == {'kwargs': {'phi': 'p2'}, 'args': [], 'op': 'MeasureHomodyne', 'modes': [0]}
assert bb.operations[3] == {'kwargs': {}, 'args': ['p2'], 'op': 'MeasureHomodyne', 'modes': [0]}

assert bb.programtype == {'name': 'tdm', 'options': {'temporal_modes': 2}}
assert list(bb._var.keys()) == ["p0", "p1", "p2"]
Expand Down

0 comments on commit 724b0a7

Please sign in to comment.