Skip to content

Update qcs api client #513

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

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ __pycache__/
venv/
.venv

# JetBrains
# IDEs
.idea
.vscode/
.nlsp-settings/
pyrightconfig.json

# Clang debug / memory detection / test artifacts
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ members = ["crates/*"]
resolver = "2"

[workspace.dependencies]
qcs-api-client-common = "0.11.2"
qcs-api-client-grpc = "0.11.2"
qcs-api-client-openapi = "0.12.2"
qcs-api-client-common = "0.11.5"
qcs-api-client-grpc = "0.11.5"
qcs-api-client-openapi = "0.12.5"
serde_json = "1.0.86"
thiserror = "1.0.57"
tokio = "1.36.0"
Expand All @@ -15,7 +15,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.28.1", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.12.1" }
quil-rs = { version = "0.29.2", git = "https://github.com/rigetti/quil-rs", tag = "quil-py/v0.13.2" }

# 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
2 changes: 1 addition & 1 deletion crates/lib/src/qpu/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
.collect(),
job: Some(execute_controller_job_request::Job::Encrypted(program)),
target: execution_options.get_job_target(quantum_processor_id),
options: execution_options.api_options().cloned(),
options: execution_options.api_options().copied(),
};

let mut controller_client = execution_options
Expand Down Expand Up @@ -363,7 +363,7 @@
/// to build a custom set of options.
#[derive(Builder, Clone, Debug, Default, PartialEq)]
#[allow(clippy::module_name_repetitions)]
pub struct ApiExecutionOptions {

Check warning on line 366 in crates/lib/src/qpu/api.rs

View workflow job for this annotation

GitHub Actions / publish-docs

type could implement `Copy`; consider adding `impl Copy`

Check warning on line 366 in crates/lib/src/qpu/api.rs

View workflow job for this annotation

GitHub Actions / Run Checks

type could implement `Copy`; consider adding `impl Copy`

Check warning on line 366 in crates/lib/src/qpu/api.rs

View workflow job for this annotation

GitHub Actions / publish-docs

type could implement `Copy`; consider adding `impl Copy`
/// the inner proto representation
inner: InnerApiExecutionOptions,
}
Expand Down
13 changes: 11 additions & 2 deletions crates/lib/src/qpu/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
models::controller::EncryptedControllerJob,
services::translation::{
translate_quil_to_encrypted_controller_job_request::NumShots,
translation_options::TranslationBackend, BackendV1Options, BackendV2Options,
GetQuantumProcessorQuilCalibrationProgramRequest,
translation_options::{self, TranslationBackend},
BackendV1Options, BackendV2Options, GetQuantumProcessorQuilCalibrationProgramRequest,
TranslateQuilToEncryptedControllerJobRequest, TranslationOptions as ApiTranslationOptions,
},
};
Expand Down Expand Up @@ -139,7 +139,7 @@
/// because the structs auto-generated by `prost` can be clumsy to use directly.
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug, Default)]
pub struct TranslationOptions {

Check warning on line 142 in crates/lib/src/qpu/translation.rs

View workflow job for this annotation

GitHub Actions / publish-docs

type could implement `Copy`; consider adding `impl Copy`

Check warning on line 142 in crates/lib/src/qpu/translation.rs

View workflow job for this annotation

GitHub Actions / Run Checks

type could implement `Copy`; consider adding `impl Copy`

Check warning on line 142 in crates/lib/src/qpu/translation.rs

View workflow job for this annotation

GitHub Actions / publish-docs

type could implement `Copy`; consider adding `impl Copy`
inner: ApiTranslationOptions,
}

Expand Down Expand Up @@ -255,6 +255,15 @@
self.ensure_backend_v2()?.allow_frame_redefinition = Some(allow);
Ok(self)
}

/// Set the Q-CTRL option for compiling the program through Q-CTRL's API prior to translation.
///
/// Generally, the client should set this option to `QCtrl::default()`, as options are
/// specially authorized and not generally available to the client.
pub fn q_ctrl(&mut self, q_ctrl: translation_options::QCtrl) -> &mut Self {
self.inner.q_ctrl = Some(q_ctrl);
self
}
}

impl From<TranslationOptions> for ApiTranslationOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

__doc__ = common.__doc__
__all__ = getattr(common, "__all__", [])

6 changes: 2 additions & 4 deletions crates/python/qcs_sdk/_tracing_subscriber/common/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

from typing import Dict, Optional, final


@final
class InstrumentationLibrary:
"""
Information about a library or crate providing instrumentation.

An instrumentation library should be named to follow any naming conventions
of the instrumented library (e.g. 'middleware' for a web framework).

See the `instrumentation libraries <https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/overview.md#instrumentation-libraries>`_
spec for more information.
"""
Expand All @@ -42,4 +41,3 @@ class InstrumentationLibrary:
:param attributes: The attributes of the instrumentation library.
"""
...

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

__doc__ = layers.__doc__
__all__ = getattr(layers, "__all__", [])

16 changes: 8 additions & 8 deletions crates/python/qcs_sdk/_tracing_subscriber/layers/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
from __future__ import annotations
from typing import TYPE_CHECKING

from . import file as file
from . import file as file
from . import otel_otlp_file as otel_otlp_file
from . import otel_otlp as otel_otlp

if TYPE_CHECKING:
from typing import Union
from typing import Union

Config = Union[
file.Config,
otel_otlp_file.Config,
otel_otlp.Config,
]
"""
Config = Union[
file.Config,
otel_otlp_file.Config,
otel_otlp.Config,
]
"""
One of the supported layer configurations that may be set on the subscriber configuration.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@

__doc__ = file.__doc__
__all__ = getattr(file, "__all__", [])


Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ class Config:
:param json: Whether or not to format the output as JSON. Defaults to `True`.
"""
...

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

__doc__ = otel_otlp.__doc__
__all__ = getattr(otel_otlp, "__all__", [])

Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class Resource:
schema_url: Optional[str] = None,
) -> "Resource": ...



@final
class Config:
"""
Expand Down Expand Up @@ -101,14 +99,14 @@ class Config:
...

if TYPE_CHECKING:
from typing import List, Union
from typing import List, Union

ResourceValueArray = Union[List[bool], List[int], List[float], List[str]]
"""
An array of `ResourceValue`s. This array is homogenous, so all values must be of the same type.
"""

ResourceValue= Union[bool, int, float, str, ResourceValueArray]
ResourceValue = Union[bool, int, float, str, ResourceValueArray]
"""
A value that can be added to a `Resource`.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

__doc__ = otel_otlp_file.__doc__
__all__ = getattr(otel_otlp_file, "__all__", [])

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
from typing import Optional, final
from qcs_sdk._tracing_subscriber.common import InstrumentationLibrary


@final
class Config:
"""
A configuration for `opentelemetry-stdout <https://docs.rs/opentelemetry-stdout/latest/opentelemetry_stdout/>`_
layer.
"""

def __new__(cls, *, file_path: Optional[str] = None, filter: Optional[str] = None, instrumentation_library: Optional[InstrumentationLibrary] = None) -> "Config":
def __new__(
cls,
*,
file_path: Optional[str] = None,
filter: Optional[str] = None,
instrumentation_library: Optional[InstrumentationLibrary] = None,
) -> "Config":
"""
:param file_path: The path to the file to write to. If not specified, defaults to stdout.
:param filter: A filter string to use for this layer. This uses the same format as the
Expand All @@ -35,4 +40,3 @@ class Config:
:param instrumentation_library: Information about the library providing the tracing instrumentation.
"""
...

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

__doc__ = subscriber.__doc__
__all__ = getattr(subscriber, "__all__", [])

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ class Config:
"""

def __new__(cls, *, layer: layers.Config) -> "Config": ...

16 changes: 16 additions & 0 deletions crates/python/qcs_sdk/qpu/translation.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, Optional, final
from typing_extensions import Self
from enum import Enum, auto

from qcs_sdk.client import QCSClient
Expand Down Expand Up @@ -112,6 +113,15 @@ async def translate_async(
"""
...

@final
class QCtrl:
"""
Options for compiling programs through the Q-CTRL API. Options here are specially authorized
and are not generally available to the client.
"""

def __new__(cls, /, fixed_layout: Optional[bool] = ...) -> Self: ...

@final
class TranslationOptions:
"""
Expand All @@ -131,6 +141,12 @@ class TranslationOptions:
"""
Use the v2 backend for translation, available on QCS since 2023.
"""
def use_q_ctrl(self, q_ctrl: QCtrl = ..., /) -> None:
"""
Compile the program through Q-CTRL's API prior to translation. The client
should generally leave the `q_ctrl` compile options unset as it is
specially authorized and not generally available.
"""
@staticmethod
def v1() -> "TranslationOptions":
"""
Expand Down
28 changes: 27 additions & 1 deletion crates/python/src/qpu/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pyo3::types::PyBytes;
use pyo3::Python;
use pyo3::{exceptions::PyRuntimeError, pyclass, pyfunction, pymethods, PyResult};
use qcs::qpu::translation::TranslationOptions;
use qcs_api_client_grpc::services::translation::translation_options;
use qcs_api_client_grpc::services::translation::{
translation_options::TranslationBackend as ApiTranslationBackend,
TranslationOptions as ApiTranslationOptions,
Expand All @@ -21,7 +22,8 @@ create_init_submodule! {
classes: [
PyTranslationOptions,
PyTranslationResult,
PyTranslationBackend
PyTranslationBackend,
PyQCtrl
],
errors: [
TranslationError
Expand Down Expand Up @@ -113,6 +115,11 @@ impl PyTranslationOptions {
self.0.with_backend_v2();
}

#[pyo3(signature = (q_ctrl = PyQCtrl::default(), /))]
fn use_q_ctrl(&mut self, q_ctrl: PyQCtrl) {
self.0.q_ctrl(*q_ctrl.as_inner());
}

#[staticmethod]
fn v1() -> Self {
let mut builder = TranslationOptions::default();
Expand Down Expand Up @@ -169,6 +176,25 @@ impl PyTranslationOptions {
}
}

#[derive(Clone, Default, Debug)]
#[pyclass(name = "QCtrl")]
pub struct PyQCtrl(translation_options::QCtrl);

#[pymethods]
impl PyQCtrl {
#[new]
#[pyo3(signature = (/, fixed_layout = None))]
fn __new__(fixed_layout: Option<bool>) -> PyResult<Self> {
Ok(Self(translation_options::QCtrl { fixed_layout }))
}
}

impl PyQCtrl {
fn as_inner(&self) -> &translation_options::QCtrl {
&self.0
}
}

/// The result of a call to [`translate`] which provides information about the
/// translated program.
#[pyclass]
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ignore = [
{ id = "RUSTSEC-2024-0375", reason = "introduced by atty, a transitive dependency of multiple dependencies, with no upgrade path" },
{ id = "RUSTSEC-2024-0006", reason = "introduced by shlex, a transitive dependency of bindgen with no upgrade path" },
{ id = "RUSTSEC-2021-0139", reason = "ansi_term is unmaintained, but used by clap" },
{ id = "RUSTSEC-2024-0384", reason = "instant is unmaintained, but used by backoff" },
{ id = "RUSTSEC-2024-0384", reason = "instant is unmaintained, dependency of \"backoff\", which also appears to be unmaintained" }
]
yanked = "deny"
# If this is true, then cargo deny will use the git executable to fetch advisory database.
Expand Down
Loading