From fac3d01b38ab79bfca0bc4fa0729084c24e3e2d4 Mon Sep 17 00:00:00 2001 From: antalszava Date: Sun, 13 Sep 2020 22:26:45 -0400 Subject: [PATCH] Increment version number to v0.15.1 (#450) * Update RemoteEngine.run signature to have recompile; test * CHANGELOG: tidy & version bump * Version bump * Addition * Formatting --- .github/CHANGELOG.md | 11 +++++---- strawberryfields/_version.py | 2 +- strawberryfields/engine.py | 10 ++++++-- tests/api/test_remote_engine.py | 44 ++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index e081781c1..0260c8d39 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,6 +1,4 @@ -# Release 0.16.0 (development release) - -

New features since last release

+# Release 0.15.1 (current release)

Improvements

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

Documentation

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

Contributors

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

New features since last release

diff --git a/strawberryfields/_version.py b/strawberryfields/_version.py index e51195a5a..aedb2e1a5 100644 --- a/strawberryfields/_version.py +++ b/strawberryfields/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.16.0-dev" +__version__ = "0.15.1" diff --git a/strawberryfields/engine.py b/strawberryfields/engine.py index 140381802..5b570e9ff 100644 --- a/strawberryfields/engine.py +++ b/strawberryfields/engine.py @@ -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 @@ -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 @@ -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() diff --git a/tests/api/test_remote_engine.py b/tests/api/test_remote_engine.py index c1c016ca8..7247dedec 100644 --- a/tests/api/test_remote_engine.py +++ b/tests/api/test_remote_engine.py @@ -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" @@ -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."""