Skip to content

Commit

Permalink
Increment version number to v0.15.1 (#450)
Browse files Browse the repository at this point in the history
* Update RemoteEngine.run signature to have recompile; test

* CHANGELOG: tidy & version bump

* Version bump

* Addition

* Formatting
  • Loading branch information
antalszava authored Sep 14, 2020
1 parent 656866b commit fac3d01
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
11 changes: 6 additions & 5 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Release 0.16.0 (development release)

<h3>New features since last release</h3>
# Release 0.15.1 (current release)

<h3>Improvements</h3>

Expand All @@ -23,13 +21,16 @@

<h3>Documentation</h3>

* Updates the `README.rst` file and hardware access links.
[(#448)](https://github.com/XanaduAI/strawberryfields/pull/448)

<h3>Contributors</h3>

This release contains contributions from (in alphabetical order):

Josh Izaac, Nicolás Quesada, Antal Száva
Theodor Isacsson, Josh Izaac, Nathan Killoran, Nicolás Quesada, Antal Száva

# Release 0.15.0 (current release)
# Release 0.15.0

<h3>New features since last release</h3>

Expand Down
2 changes: 1 addition & 1 deletion strawberryfields/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.16.0-dev"
__version__ = "0.15.1"
10 changes: 8 additions & 2 deletions strawberryfields/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,9 @@ def device_spec(self):
self._spec = self._connection.get_device_spec(self.target)
return self._spec

def run(self, program: Program, *, compile_options=None, **kwargs) -> Optional[Result]:
def run(
self, program: Program, *, compile_options=None, recompile=False, **kwargs
) -> Optional[Result]:
"""Runs a blocking job.
In the blocking mode, the engine blocks until the job is completed, failed, or
Expand All @@ -560,6 +562,8 @@ def run(self, program: Program, *, compile_options=None, **kwargs) -> Optional[R
Args:
program (strawberryfields.Program): the quantum circuit
compile_options (None, Dict[str, Any]): keyword arguments for :meth:`.Program.compile`
recompile (bool): Specifies if ``program`` should be recompiled
using ``compile_options``, or if not provided, the default compilation options.
Keyword Args:
shots (Optional[int]): The number of shots for which to run the job. If this
Expand All @@ -569,7 +573,9 @@ def run(self, program: Program, *, compile_options=None, **kwargs) -> Optional[R
[strawberryfields.api.Result, None]: the job result if successful, and
``None`` otherwise
"""
job = self.run_async(program, compile_options=compile_options, **kwargs)
job = self.run_async(
program, compile_options=compile_options, recompile=recompile, **kwargs
)
try:
while True:
job.refresh()
Expand Down
44 changes: 43 additions & 1 deletion tests/api/test_remote_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_compile(self, prog, monkeypatch, caplog):
assert isinstance(program, self.MockProgram)
assert caplog.records[-1].message == "Compiling program for device X8_01 using compiler Xunitary."

def test_recompilation(self, prog, monkeypatch, caplog):
def test_recompilation_run_async(self, prog, monkeypatch, caplog):
"""Test that recompilation happens when the recompile keyword argument
was set to True."""
compiler = "Xunitary"
Expand Down Expand Up @@ -315,6 +315,48 @@ def test_recompilation_precompiled(self, prog, monkeypatch, caplog):
assert isinstance(program, self.MockProgram)
assert caplog.records[-1].message == "Recompiling program for device X8_01 using compiler Xunitary."

def test_recompilation_run(self, prog, monkeypatch, caplog):
"""Test that recompilation happens when the recompile keyword argument
was set to True and engine.run was called."""
compiler = "Xunitary"

caplog.set_level(logging.INFO)
test_device_dict = mock_device_dict.copy()
test_device_dict["compiler"] = compiler

monkeypatch.setattr(Connection, "create_job", lambda self, target, program, run_options: MockJob(program))
monkeypatch.setattr(Connection, "_get_device_dict", lambda *args: test_device_dict)

class MockJob:
"""Mock job that acts like a job, but also stores a program."""

def __init__(self, prog):

# Store the program as result
self.result = prog
self.status = "complete"
self.id = 0

def refresh(self):
pass

compile_options = {"compiler": compiler}

engine = sf.RemoteEngine("X8")

device = engine.device_spec

# Setting compile_info
prog._compile_info = (device, device.compiler)

program = engine.run(prog, shots=10, compile_options=compile_options, recompile=True)

# No recompilation, original Program
assert caplog.records[-1].message == ("The remote job 0 has been completed.")
assert caplog.records[-2].message == (f"Recompiling program for device "
f"{device.target} using the specified compiler options: "
f"{compile_options}.")

def test_validation(self, prog, monkeypatch, caplog):
"""Test that validation happens (no recompilation) when the target
device and device spec match."""
Expand Down

0 comments on commit fac3d01

Please sign in to comment.