Skip to content

Commit 577cc3e

Browse files
authored
feat: ExecutionOptions supports the pickle module. (#485)
* feat(python): ExecutionOptions supports the pickle module * update quil dep * update bytes from yanked version * fix number list * anotha one
1 parent d47bde3 commit 577cc3e

File tree

5 files changed

+132
-10
lines changed

5 files changed

+132
-10
lines changed

Cargo.lock

+96-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tokio = "1.36.0"
1616
# `crates/python/pyproject.toml`.
1717
# The version must also be specified in order to publish to crates.io. Cargo enforces
1818
# that the specified version is the same as the version in the git repository.
19-
quil-rs = { version = "0.26.0", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.10.0" }
19+
quil-rs = { version = "0.27.1", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.11.1" }
2020

2121
# ndarray is used by the `qcs` crate, but it is also used in the `python` crate via a
2222
# re-export through the numpy crate. They should be updated as a pair to keep both

crates/lib/src/executable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'execution> Executable<'_, 'execution> {
470470
/// The [`Executable`] will only live as long as the last parameter passed into this function.
471471
/// 2. `translation_options`: An optional [`TranslationOptions`] that is used to configure how
472472
/// the program in translated.
473-
/// 3 `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
473+
/// 3. `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
474474
/// is [`crate::qpu::api::ConnectionStrategy::EndpointId`] then direct access to that endpoint
475475
/// overrides the `quantum_processor_id` parameter.
476476
///
@@ -528,7 +528,7 @@ impl<'execution> Executable<'_, 'execution> {
528528
/// The [`Executable`] will only live as long as the last parameter passed into this function.
529529
/// 2. `translation_options`: An optional [`TranslationOptions`] that is used to configure how
530530
/// the program in translated.
531-
/// 3 `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
531+
/// 3. `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
532532
/// is [`crate::qpu::api::ConnectionStrategy::EndpointId`] then direct access to that endpoint
533533
/// overrides the `quantum_processor_id` parameter.
534534
///

crates/python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ classifiers = [
2020
"Programming Language :: Python :: 3.11",
2121
"Operating System :: OS Independent",
2222
]
23-
dependencies = ["quil==0.10.0"]
23+
dependencies = ["quil==0.11.1"]
2424

2525
# PEP 621 specifies the [project] table as the source for project metadata. However, Poetry only supports [tool.poetry]
2626
# We can remove this table once this issue is resolved: https://github.com/python-poetry/poetry/issues/3332

crates/python/src/qpu/api.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use pyo3::{
88
pyclass,
99
pyclass::CompareOp,
1010
pyfunction, pymethods,
11-
types::{PyComplex, PyInt},
12-
IntoPy, Py, PyObject, PyResult, Python, ToPyObject,
11+
types::{PyComplex, PyDict, PyInt},
12+
IntoPy, Py, PyAny, PyObject, PyResult, Python, ToPyObject,
1313
};
1414
use qcs::qpu::api::{
1515
ApiExecutionOptions, ApiExecutionOptionsBuilder, ConnectionStrategy, ExecutionOptions,
@@ -431,6 +431,36 @@ impl PyExecutionOptions {
431431
_ => py.NotImplemented(),
432432
}
433433
}
434+
435+
fn __getstate__(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
436+
let dict = PyDict::new(py);
437+
dict.set_item("connection_strategy", self.connection_strategy())?;
438+
dict.set_item("timeout_seconds", self.timeout_seconds())?;
439+
dict.set_item("api_options", self.api_options())?;
440+
Ok(dict.into())
441+
}
442+
443+
fn __setstate__(&mut self, py: Python<'_>, state: Py<PyAny>) -> PyResult<()> {
444+
*self = Self::_from_parts(
445+
state.getattr(py, "connection_strategy")?.extract(py)?,
446+
state.getattr(py, "timeout_seconds")?.extract(py)?,
447+
state.getattr(py, "api_options")?.extract(py)?,
448+
)?;
449+
Ok(())
450+
}
451+
452+
#[staticmethod]
453+
fn _from_parts(
454+
connection_strategy: PyConnectionStrategy,
455+
timeout_seconds: Option<f64>,
456+
api_options: Option<PyApiExecutionOptions>,
457+
) -> PyResult<Self> {
458+
let mut builder = Self::builder();
459+
builder.connection_strategy(connection_strategy);
460+
builder.timeout_seconds(timeout_seconds);
461+
builder.api_options(api_options);
462+
builder.build()
463+
}
434464
}
435465

436466
#[pymethods]

0 commit comments

Comments
 (0)