Skip to content

Commit

Permalink
feat: ExecutionOptions supports the pickle module. (#485)
Browse files Browse the repository at this point in the history
* feat(python): ExecutionOptions supports the pickle module

* update quil dep

* update bytes from yanked version

* fix number list

* anotha one
  • Loading branch information
MarquessV authored Jul 26, 2024
1 parent d47bde3 commit 577cc3e
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
100 changes: 96 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio = "1.36.0"
# `crates/python/pyproject.toml`.
# The version must also be specified in order to publish to crates.io. Cargo enforces
# that the specified version is the same as the version in the git repository.
quil-rs = { version = "0.26.0", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.10.0" }
quil-rs = { version = "0.27.1", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.11.1" }

# ndarray is used by the `qcs` crate, but it is also used in the `python` crate via a
# re-export through the numpy crate. They should be updated as a pair to keep both
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl<'execution> Executable<'_, 'execution> {
/// The [`Executable`] will only live as long as the last parameter passed into this function.
/// 2. `translation_options`: An optional [`TranslationOptions`] that is used to configure how
/// the program in translated.
/// 3 `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
/// 3. `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
/// is [`crate::qpu::api::ConnectionStrategy::EndpointId`] then direct access to that endpoint
/// overrides the `quantum_processor_id` parameter.
///
Expand Down Expand Up @@ -528,7 +528,7 @@ impl<'execution> Executable<'_, 'execution> {
/// The [`Executable`] will only live as long as the last parameter passed into this function.
/// 2. `translation_options`: An optional [`TranslationOptions`] that is used to configure how
/// the program in translated.
/// 3 `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
/// 3. `execution_options`: The [`ExecutionOptions`] to use. If the connection strategy used
/// is [`crate::qpu::api::ConnectionStrategy::EndpointId`] then direct access to that endpoint
/// overrides the `quantum_processor_id` parameter.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Operating System :: OS Independent",
]
dependencies = ["quil==0.10.0"]
dependencies = ["quil==0.11.1"]

# PEP 621 specifies the [project] table as the source for project metadata. However, Poetry only supports [tool.poetry]
# We can remove this table once this issue is resolved: https://github.com/python-poetry/poetry/issues/3332
Expand Down
34 changes: 32 additions & 2 deletions crates/python/src/qpu/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use pyo3::{
pyclass,
pyclass::CompareOp,
pyfunction, pymethods,
types::{PyComplex, PyInt},
IntoPy, Py, PyObject, PyResult, Python, ToPyObject,
types::{PyComplex, PyDict, PyInt},
IntoPy, Py, PyAny, PyObject, PyResult, Python, ToPyObject,
};
use qcs::qpu::api::{
ApiExecutionOptions, ApiExecutionOptionsBuilder, ConnectionStrategy, ExecutionOptions,
Expand Down Expand Up @@ -431,6 +431,36 @@ impl PyExecutionOptions {
_ => py.NotImplemented(),
}
}

fn __getstate__(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
let dict = PyDict::new(py);
dict.set_item("connection_strategy", self.connection_strategy())?;
dict.set_item("timeout_seconds", self.timeout_seconds())?;
dict.set_item("api_options", self.api_options())?;
Ok(dict.into())
}

fn __setstate__(&mut self, py: Python<'_>, state: Py<PyAny>) -> PyResult<()> {
*self = Self::_from_parts(
state.getattr(py, "connection_strategy")?.extract(py)?,
state.getattr(py, "timeout_seconds")?.extract(py)?,
state.getattr(py, "api_options")?.extract(py)?,
)?;
Ok(())
}

#[staticmethod]
fn _from_parts(
connection_strategy: PyConnectionStrategy,
timeout_seconds: Option<f64>,
api_options: Option<PyApiExecutionOptions>,
) -> PyResult<Self> {
let mut builder = Self::builder();
builder.connection_strategy(connection_strategy);
builder.timeout_seconds(timeout_seconds);
builder.api_options(api_options);
builder.build()
}
}

#[pymethods]
Expand Down

0 comments on commit 577cc3e

Please sign in to comment.