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

feat(python): Constructors, iterators, and other utility methods have been added to make working with ResultData, RegisterMap, and others easier. #342

Merged
merged 23 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3689958
fix: don't wrap ReadoutValues twice
Shadow53 Aug 9, 2023
47e9c12
feat(python): add constructor to QVMResultData and as_ndarray to Read…
Shadow53 Aug 9, 2023
5956daf
allow RegisterMap to be used as dictionary
MarquessV Aug 10, 2023
19542bd
remove dbg print
MarquessV Aug 10, 2023
e665246
feat(python)!: The ExecutionData now takes a datetime duration
MarquessV Aug 14, 2023
697ed8a
feat: ExecutionResult now has a `from_register` constructor
MarquessV Aug 14, 2023
57a514c
feat(python): QpuResultData now has an `asdict()` method for retrieving
MarquessV Aug 14, 2023
212b001
update typehints
MarquessV Aug 14, 2023
6e888da
update stubtest allowlist
MarquessV Aug 14, 2023
534f82b
Merge branch 'main' into pyquil-1630-support
MarquessV Aug 14, 2023
7e6ceed
replace asdict with to_raw_readout_data methods
MarquessV Aug 14, 2023
f5edafd
update tests that used asdict
MarquessV Aug 14, 2023
ee52b60
fix type hints
MarquessV Aug 25, 2023
dd58e12
simplify mapping and input arguments
MarquessV Aug 25, 2023
90c8916
cleanup
MarquessV Aug 25, 2023
e3a9eb7
update rustls
MarquessV Aug 25, 2023
fd54ecb
fix compilation errors
MarquessV Aug 25, 2023
e37d416
unpin reqwest to allow webpki to be updated
MarquessV Aug 25, 2023
5fc7b2d
add to_raw_readout_data method to ResultData
MarquessV Aug 25, 2023
4f8d12f
type hints, tokio fix
MarquessV Aug 28, 2023
a1391c3
ignore `webpki` advisory
MarquessV Aug 28, 2023
3feb3c1
that needs quotes
MarquessV Aug 28, 2023
ca2a242
allow missing panic docs for function
MarquessV Aug 29, 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
90 changes: 28 additions & 62 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.dependencies]
qcs-api = "0.2.1"
Expand Down Expand Up @@ -27,3 +28,4 @@ pyo3 = { version = "0.17" }
pyo3-asyncio = { version = "0.17", features = ["tokio-runtime"] }
pyo3-build-config = { version = "0.17" }
rigetti-pyo3 = { version = "0.1.0", features = ["complex"] }

4 changes: 2 additions & 2 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ qcs-api-client-common.workspace = true
qcs-api-client-openapi.workspace = true
qcs-api-client-grpc.workspace = true
quil-rs.workspace = true
reqwest = { version = "0.11.12", default-features = false, features = [
reqwest = { version = "0.11.20", default-features = false, features = [
"rustls-tls",
"json",
] }
rmp-serde = "1.1.1"
serde = { version = "1.0.145", features = ["derive"] }
serde_json.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["fs"] }
tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
toml = "0.7.3"
tracing = { version = "0.1", optional = true, features = ["log"] }
uuid = { version = "1.2.1", features = ["v4"] }
Expand Down
1 change: 1 addition & 0 deletions crates/lib/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl<'executable> Executable<'executable, '_> {
/// 1. `quil` is a string slice representing the original program to be run. The returned
/// [`Executable`] will only live as long as this reference.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn from_quil<Quil: Into<Arc<str>>>(quil: Quil) -> Self {
Self {
quil: quil.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/execution_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum RegisterMatrix {
/// register.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[repr(transparent)]
pub struct RegisterMap(HashMap<String, RegisterMatrix>);
pub struct RegisterMap(pub HashMap<String, RegisterMatrix>);
Shadow53 marked this conversation as resolved.
Show resolved Hide resolved

/// Errors that may occur when trying to build a [`RegisterMatrix`] from execution data
#[allow(missing_docs)]
Expand Down
2 changes: 1 addition & 1 deletion crates/python/.stubtest-allowlist
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qcs_sdk.qcs_sdk
qcs_sdk._gather_diagnostics
qcs_sdk.diagnostics
qcs_sdk.qcs_sdk
34 changes: 31 additions & 3 deletions crates/python/qcs_sdk/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import datetime
from enum import Enum
from typing import Dict, List, Sequence, Optional, Union, final
from typing import Dict, List, Sequence, Optional, Union, final, Iterable, Tuple

import numpy as np
from numpy.typing import NDArray

from qcs_sdk.qpu import QPUResultData
from qcs_sdk.qvm import QVMResultData
from qcs_sdk.qpu import QPUResultData, RawQPUReadoutData
from qcs_sdk.qvm import QVMResultData, RawQVMReadoutData
from qcs_sdk.compiler.quilc import CompilerOpts

from qcs_sdk.client import QCSClient as QCSClient
Expand Down Expand Up @@ -205,6 +205,11 @@ class RegisterMatrix:
def from_real(inner: NDArray[np.float64]) -> "RegisterMatrix": ...
@staticmethod
def from_complex(inner: NDArray[np.complex128]) -> "RegisterMatrix": ...
def to_ndarray(self) -> Union[NDArray[np.complex128], NDArray[np.int64], NDArray[np.float64]]:
"""
Get the RegisterMatrix as numpy ``ndarray``.
"""
...

@final
class RegisterMap:
Expand All @@ -213,6 +218,14 @@ class RegisterMap:
def get_register_matrix(self, register_name: str) -> Optional[RegisterMatrix]:
"""Get the ``RegisterMatrix`` for the given register. Returns `None` if the register doesn't exist."""
...
def get(self, default: Optional[RegisterMatrix] = None) -> Optional[RegisterMatrix]: ...
def items(self) -> Iterable[Tuple[str, RegisterMatrix]]: ...
def keys(self) -> Iterable[str]: ...
def values(self) -> Iterable[RegisterMatrix]: ...
def __iter__(self) -> Iterable[str]: ...
def __getitem__(self, item: str) -> RegisterMatrix: ...
def __contains__(self, key: str) -> bool: ...
def __len__(self) -> int: ...

@final
class ResultData:
Expand Down Expand Up @@ -261,6 +274,11 @@ class ResultData:
- ``from_*``: wrap underlying values as this enum type.
"""

def __new__(cls, inner: Union[QPUResultData, QVMResultData]) -> "ResultData":
"""
Create a new ResultData from either QVM or QPU result data.
"""
...
def to_register_map(self) -> RegisterMap:
"""
Convert ``ResultData`` from its inner representation as ``QVMResultData`` or
Expand All @@ -281,6 +299,11 @@ class ResultData:
selects the last value per-shot based on the program that was run.
"""
...
def to_raw_readout_data(self) -> Union[RawQPUReadoutData, RawQVMReadoutData]:
"""
Get the raw data returned from the QVM or QPU. See ``RawQPUReadoutData`` and
``RawQVMReadoutData`` for more information.
"""
def inner(
self,
) -> Union[QVMResultData, QPUResultData]:
Expand All @@ -299,6 +322,7 @@ class ResultData:

@final
class ExecutionData:
def __new__(cls, result_data: ResultData, duration: Optional[datetime.timedelta] = None): ...
@property
def result_data(self) -> ResultData: ...
@result_data.setter
Expand Down Expand Up @@ -327,11 +351,15 @@ class RegisterData:

"""

def __new__(cls, inner: Union[List[List[int]], List[List[float]], List[List[complex]]]) -> "RegisterData": ...
def inner(
self,
) -> Union[List[List[int]], List[List[float]], List[List[complex]]]:
"""Returns the inner value."""
...
def as_ndarray(self) -> Union[NDArray[np.int64], NDArray[np.float64], NDArray[np.complex128]]:
"""Returns the values as an ``ndarray``."""
...
def is_i8(self) -> bool: ...
def is_i16(self) -> bool: ...
def is_f64(self) -> bool: ...
Expand Down
Loading
Loading