Skip to content

Commit adbfaa2

Browse files
fix!: convert all pyo3 async functions to sync, use python name casing (#252)
* fix!: convert all async function to sync * Update crates/python/src/lib.rs Co-authored-by: Michael Bryant <[email protected]> * chore: initial mr changes * chore: implement sync/async for all python wrappers * chore: remove comments * Apply suggestions from code review Co-authored-by: Michael Bryant <[email protected]> * fix: macro cleanup * chore: add test async * fix: simplify macro * chore: add type hinting and exports for async functions * chore: mr fixes * Apply suggestions from code review Co-authored-by: Michael Bryant <[email protected]> * chore: mr review fixes * chore: untest the comment system * chore: use hygeinic references in py_sync macros * fix: pythonize initialisms * chore: fix acronym naming * chore: fix docs --------- Co-authored-by: Michael Bryant <[email protected]>
1 parent 41c5b01 commit adbfaa2

24 files changed

+764
-340
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ qcs-api/docs
2525

2626
# Python artifacts
2727
**/__pycache__
28+
crates/python/.hypothesis
2829
crates/python/qcs_sdk/*.so

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lib/examples/delayed_job_retrieval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ MEASURE 0 ro[0]
1212
async fn main() {
1313
let mut exe = Executable::from_quil(PROGRAM);
1414
let job_handle = exe
15-
.submit_to_qpu("Aspen-11")
15+
.submit_to_qpu("Aspen-M-3")
1616
.await
17-
.expect("Program should be sucessfully submitted for execution");
17+
.expect("Program should be successfully submitted for execution");
1818
// Do some other stuff
1919
let _data = exe
2020
.retrieve_results(job_handle)

crates/lib/src/executable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ mod describe_qpu_for_id {
690690
qpu::Execution::new(
691691
"".into(),
692692
shots,
693-
"Aspen-11",
693+
"Aspen-M-3",
694694
exe.get_config().await.unwrap_or_default(),
695695
exe.compile_with_quilc,
696696
)
@@ -700,7 +700,7 @@ mod describe_qpu_for_id {
700700
// Load config with no credentials to prevent creating a new Execution if it tries
701701
exe.config = Some(Arc::new(Configuration::default()));
702702

703-
assert!(exe.qpu_for_id("Aspen-11").await.is_ok());
703+
assert!(exe.qpu_for_id("Aspen-M-3").await.is_ok());
704704
}
705705

706706
#[tokio::test]

crates/python/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ serde_json.workspace = true
2828
tokio.workspace = true
2929
numpy.workspace = true
3030
rigetti-pyo3.workspace = true
31+
paste = "1.0.11"
3132

3233
[build-dependencies]
3334
pyo3-build-config.workspace = true

crates/python/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ dependencies = [
2828
"pre-test-install-lib",
2929
"test",
3030
"post-test",
31-
]
31+
]

crates/python/qcs_sdk/__init__.pyi

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
from .api import *
1+
from .api import (
2+
compile as compile,
3+
compile_async as compile_async,
4+
rewrite_arithmetic as rewrite_arithmetic,
5+
build_patch_values as build_patch_values,
6+
translate as translate,
7+
translate_async as translate_async,
8+
submit as submit,
9+
submit_async as submit_async,
10+
retrieve_results as retrieve_results,
11+
retrieve_results_async as retrieve_results_async,
12+
get_quilc_version as get_quilc_version,
13+
get_quilc_version_async as get_quilc_version_async,
14+
list_quantum_processors as list_quantum_processors,
15+
list_quantum_processors_async as list_quantum_processors_async,
16+
)
217

3-
from .qpu.client import QcsClient as QcsClient
18+
from .qpu.client import (
19+
QCSClient as QCSClient,
20+
)
421
from .qpu.isa import (
522
get_instruction_set_architecture as get_instruction_set_architecture,
23+
get_instruction_set_architecture_async as get_instruction_set_architecture_async,
624
)
725

826
from ._execution_data import (
@@ -17,7 +35,7 @@ from ._executable import (
1735
Executable as Executable,
1836
ExeParameter as ExeParameter,
1937
JobHandle as JobHandle,
20-
QcsExecutionError as QcsExecutionError,
38+
QCSExecutionError as QCSExecutionError,
2139
Service as Service,
2240
)
2341

crates/python/qcs_sdk/_executable.pyi

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from typing import Dict, List, Optional
88
from .qpu.quilc import CompilerOpts
99
from ._execution_data import ExecutionData
1010

11-
class QcsExecutionError(RuntimeError):
11+
class QCSExecutionError(RuntimeError):
1212
"""Error encounteted when executing programs."""
1313

1414
...
@@ -22,28 +22,58 @@ class Executable:
2222
compile_with_quilc: Optional[bool] = None,
2323
compiler_options: Optional[CompilerOpts] = None,
2424
) -> "Executable": ...
25-
async def execute_on_qvm(self) -> ExecutionData:
25+
def execute_on_qvm(self) -> ExecutionData:
2626
"""
2727
Execute on a QVM which must be available at the configured URL (default http://localhost:5000).
2828
2929
Raises:
30-
- ``QcsExecutionError``: If the job fails to execute.
30+
- ``QCSExecutionError``: If the job fails to execute.
3131
"""
3232
...
33-
async def execute_on_qpu(self, quantum_processor_id: str) -> ExecutionData:
33+
async def execute_on_qvm_async(self) -> ExecutionData:
34+
"""
35+
Async version of ``execute_on_qvm``.
36+
37+
Execute on a QVM which must be available at the configured URL (default http://localhost:5000).
38+
39+
Raises:
40+
- ``QCSExecutionError``: If the job fails to execute.
41+
"""
42+
...
43+
def execute_on_qpu(self, quantum_processor_id: str) -> ExecutionData:
3444
"""
3545
Compile the program and execute it on a QPU, waiting for results.
3646
3747
Raises:
38-
- ``QcsExecutionError``: If the job fails to execute.
48+
- ``QCSExecutionError``: If the job fails to execute.
3949
"""
4050
...
41-
async def retrieve_results(self, job_handle: JobHandle) -> ExecutionData:
51+
async def execute_on_qpu_async(self, quantum_processor_id: str) -> ExecutionData:
4252
"""
53+
Async version of ``execute_on_qvm``.
54+
55+
Compile the program and execute it on a QPU, waiting for results.
56+
57+
Raises:
58+
- ``QCSExecutionError``: If the job fails to execute.
59+
"""
60+
...
61+
def retrieve_results(self, job_handle: JobHandle) -> ExecutionData:
62+
"""
63+
Wait for the results of a job to complete.
64+
65+
Raises:
66+
- ``QCSExecutionError``: If there is a problem constructing job results.
67+
"""
68+
...
69+
async def retrieve_results_async(self, job_handle: JobHandle) -> ExecutionData:
70+
"""
71+
Async version of ``retrieve_results``.
72+
4373
Wait for the results of a job to complete.
4474
4575
Raises:
46-
- ``QcsExecutionError``: If there is a problem constructing job results.
76+
- ``QCSExecutionError``: If there is a problem constructing job results.
4777
"""
4878
...
4979

@@ -95,6 +125,6 @@ class ExeParameter:
95125

96126
class Service(Enum):
97127
Quilc = "Quilc"
98-
Qvm = "Qvm"
99-
Qcs = "Qcs"
100-
Qpu = "Qpu"
128+
QVM = "QVM"
129+
QCS = "QCS"
130+
QPU = "QPU"

0 commit comments

Comments
 (0)