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

Foundational support for implementing Program with qcs-sdk-python #1518

Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0614884
tear out members, start replacing with rust API (WIP)
MarquessV Dec 30, 2022
9abba20
first pass as integrating with qcs_sdk.quil
MarquessV Jan 12, 2023
636e8a9
fix low hanging fruit, introduce snapshot testing for passing tests,
MarquessV Jan 31, 2023
73557e8
update poetry.lock
MarquessV Jan 31, 2023
bb6e673
more test annotations, fixes, snapshots
MarquessV Jan 31, 2023
684fcdd
deprecation warnings and cleanup
MarquessV Feb 1, 2023
d49521a
Gate tests and snapshots, pre-replacement with quil-rs
MarquessV Feb 1, 2023
f7f2a41
add test for FORKED gate
MarquessV Feb 1, 2023
f3041ac
back Gate with RSGate
MarquessV Feb 7, 2023
2e7aedf
fix deprecated notice
MarquessV Feb 7, 2023
5d382e7
test improvements
MarquessV Feb 7, 2023
3b44448
more cleanup
MarquessV Feb 7, 2023
7739442
various cleanups
MarquessV Feb 8, 2023
a6e6a82
add more snaps
MarquessV Feb 8, 2023
ca5b0ac
clean up program per feedback
MarquessV Feb 16, 2023
10f2a1f
feat!: The `calibrations` method on `Program` now only returns `DefCa…
MarquessV Feb 16, 2023
e8a0042
update instruction handling logic
MarquessV Feb 17, 2023
8d31abc
deprecate valid protoquil/quilt methods
MarquessV Feb 22, 2023
cf97df0
add compatibility layer by overriding quil_rs.Gate superclass methods
MarquessV Feb 23, 2023
1c54abc
remove gate __init__ method
MarquessV Feb 23, 2023
6e53133
remove old comments
MarquessV Feb 23, 2023
0056b2a
revert defcal changes
MarquessV Feb 23, 2023
5f6e8e5
safer type checking on conversion methods
MarquessV Feb 24, 2023
8b11da8
simplify ParameterDesignator Type
MarquessV Feb 24, 2023
c1eaab4
forbidden metaclass shenanigans
MarquessV Feb 24, 2023
4097264
Update pyquil/quil.py
MarquessV Feb 25, 2023
c293105
use deprecated decorator
MarquessV Mar 6, 2023
e7106d3
update qcs-sdk-python dependency spec
MarquessV Mar 7, 2023
b093b14
merge feature branch
MarquessV Mar 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,328 changes: 1,145 additions & 183 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lark = "^0.11.1"
rpcq = "^3.10.0"
networkx = "^2.5"
importlib-metadata = { version = ">=3.7.3,<5", python = "<3.8" }
qcs-sdk-python = "0.4.1"
qcs-sdk-python = "0.4.2"
qcs-api-client = ">=0.21.0,<0.22.0"
retry = "^0.9.2"
types-python-dateutil = "^2.8.19"
Expand All @@ -40,6 +40,7 @@ Sphinx = { version = "^4.0.2", optional = true }
sphinx-rtd-theme = { version = "^0.5.2", optional = true }
nbsphinx = { version = "^0.8.6", optional = true }
recommonmark = { version = "^0.7.1", optional = true }
deprecation = "^2.1.0"

[tool.poetry.dev-dependencies]
black = "^22.8.0"
Expand All @@ -55,6 +56,7 @@ pytest-freezegun = "^0.4.2"
respx = "^0.20"
nest-asyncio = "^1.5.6"
mock = { version = "^4.0", python = "<3.8" }
syrupy = "^3.0.6"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

syrupy is a snapshot testing plugin for pytest. I've leveraged this in two ways so far:

  1. To help get an accurate "before and after quil-rs" for Gate. See test_quilbase.py

  2. Any other test that was passing and making assertions against a string chock full of escape sequences and white space was replaced with a snapshot test. Planning to do this for most tests, once they pass.


[tool.poetry.extras]
latex = ["ipython"]
Expand Down
21 changes: 5 additions & 16 deletions pyquil/api/_abstract_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,19 @@ def quil_to_native_quil(self, program: Program, *, protoquil: Optional[bool] = N
"""
Convert a Quil program into native Quil, which is supported for execution on a QPU.
"""

# This is a work-around needed because calling `qcs_sdk.compile` happens _before_
# the event loop is available. Wrapping it in a Python async function ensures that
# the event loop is available. This is a limitation of pyo3:
# https://pyo3.rs/v0.17.1/ecosystem/async-await.html#a-note-about-asynciorun
async def _compile(*args, **kwargs) -> str: # type: ignore
return await qcs_sdk.compile(*args, **kwargs)

# TODO This ISA isn't always going to be available. Specifically, if the quantum processor is
# a QVM-type processor, then `quantum_processor` will have a CompilerISA, not a QCSISA.
# This will have to be addressed as part of this issue: https://github.com/rigetti/pyquil/issues/1496
target_device = compiler_isa_to_target_quantum_processor(self.quantum_processor.to_compiler_isa())
native_quil = self._event_loop.run_until_complete(
_compile(
program.out(calibrations=False),
json.dumps(target_device.asdict(), indent=2), # type: ignore
timeout=self._compiler_client.timeout,
)

native_quil = qcs_sdk.compile(
program.out(calibrations=False),
json.dumps(target_device.asdict(), indent=2), # type: ignore
timeout=self._compiler_client.timeout,
)

native_program = Program(native_quil)
native_program.num_shots = program.num_shots
native_program._calibrations = program._calibrations
native_program._waveforms = program._waveforms
native_program._memory = program._memory.copy()

return native_program
Expand Down
17 changes: 4 additions & 13 deletions pyquil/api/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,10 @@ def native_quil_to_executable(self, nq_program: Program) -> QuantumExecutable:
"""
rewrite_response = qcs_sdk.rewrite_arithmetic(nq_program.out())

# This is a work-around needed because calling `qcs_sdk.translate` happens _before_
# the event loop is available. Wrapping it in a Python async function ensures that
# the event loop is available. This is a limitation of pyo3:
# https://pyo3.rs/v0.17.1/ecosystem/async-await.html#a-note-about-asynciorun
async def _translate(*args):
return await qcs_sdk.translate(*args)

translated_program = self._event_loop.run_until_complete(
_translate(
rewrite_response["program"],
nq_program.num_shots,
self.quantum_processor_id,
)
translated_program = qcs_sdk.translate(
rewrite_response["program"],
nq_program.num_shots,
self.quantum_processor_id,
)

return EncryptedProgram(
Expand Down
5 changes: 1 addition & 4 deletions pyquil/api/_compiler_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,7 @@ def get_version(self) -> str:
Get version info for compiler server.
"""

async def _get_quilc_version() -> str:
return await qcs_sdk.get_quilc_version()

return self._event_loop.run_until_complete(_get_quilc_version())
return qcs_sdk.get_quilc_version()

def compile_to_native_quil(self, request: CompileToNativeQuilRequest) -> CompileToNativeQuilResponse:
"""
Expand Down
Loading