Skip to content
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
33 changes: 6 additions & 27 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ python = [
"dep:rigetti-pyo3",
"experimental",
"tracing-opentelemetry",
"quil-rs/python",
"qcs-api-client-common/python",
]
stubs = [
"python",
"dep:pyo3-stub-gen",
"quil-rs/stubs",
"qcs-api-client-common/stubs",
"pyo3-tracing-subscriber-build",
"rigetti-pyo3/stubs",
Expand Down
3 changes: 1 addition & 2 deletions crates/lib/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"quil>=0.37.1,<0.38.0",
"qcs-api-client-common>=0.19.0,<0.20.0",
"qcs-api-client-common>=0.19.0,<0.27.0",
]

[dependency-groups]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import builtins
import collections.abc
from qcs_sdk import _qcs_sdk
from qcs_sdk._qcs_sdk.qpu import isa
import quil._quil.program
import typing
from quil._quil import program

__all__ = [
"CompilationResult",
Expand Down Expand Up @@ -46,9 +44,9 @@ class CompilationResult:
Metadata about the compiled program
"""
@property
def program(self) -> program.Program:
def program(self) -> builtins.str:
Comment thread
jselig-rigetti marked this conversation as resolved.
r"""
The compiled program
The compiled program, as a Quil string.
"""

@typing.final
Expand Down
13 changes: 13 additions & 0 deletions crates/lib/src/compiler/python.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use qcs_api_client_openapi::models::InstructionSetArchitecture;
use quil_rs::quil::Quil;
use rigetti_pyo3::{create_init_submodule, impl_repr, py_function_sync_async};
use std::convert::TryFrom;

Expand Down Expand Up @@ -78,6 +79,18 @@ impl CompilerOpts {
}
}

#[cfg_attr(feature = "stubs", gen_stub_pymethods)]
#[pymethods]
impl CompilationResult {
Comment thread
jselig-rigetti marked this conversation as resolved.
/// The compiled program, as a Quil string.
#[getter]
fn program(&self) -> PyResult<String> {
self.program
.to_quil()
.map_err(|err| errors::QuilcError::new_err(err.to_string()))
}
}

#[cfg_attr(feature = "stubs", gen_stub_pymethods)]
#[pymethods]
impl TargetDevice {
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/compiler/quilc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ pub trait Client {

/// The result of compiling a Quil program to native quil with `quilc`
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(not(feature = "python"), optipy::strip_pyo3)]
#[cfg_attr(feature = "stubs", gen_stub_pyclass)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(
module = "qcs_sdk._qcs_sdk.compiler.quilc",
get_all,
Comment thread
jselig-rigetti marked this conversation as resolved.
frozen,
from_py_object
)
Expand All @@ -74,6 +74,7 @@ pub struct CompilationResult {
/// The compiled program
pub program: Program,
/// Metadata about the compiled program
#[pyo3(get)]
pub native_quil_metadata: Option<NativeQuilMetadata>,
}

Expand Down
17 changes: 6 additions & 11 deletions crates/lib/src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
mod stubs {
use pyo3_stub_gen::{
define_stub_info_gatherer, derive::gen_type_alias_from_python, exclude_from_all,
export_verbatim, module_doc, reexport_module_members, Result, StubInfo,
export_verbatim, reexport_module_members, Result, StubInfo,
};
use std::path::Path;

Expand Down Expand Up @@ -166,9 +166,7 @@ mod stubs {
reexport_module_members!("qcs_sdk.qvm.api" from "qcs_sdk._qcs_sdk.qvm.api");

reexport_module_members!("qcs_sdk._qcs_sdk.client" from "qcs_api_client_common._qcs_api_client_common"; "configuration");
reexport_module_members!("qcs_sdk._qcs_sdk.compiler.quilc" from "quil._quil"; "program");
exclude_from_all!("qcs_sdk._qcs_sdk.client", "configuration");
exclude_from_all!("qcs_sdk._qcs_sdk.compiler.quilc", "program");

reexport_module_members!("qcs_sdk" from "qcs_sdk._qcs_sdk.client"; "QCSClient");

Expand All @@ -178,8 +176,6 @@ mod stubs {
export_verbatim!("qcs_sdk._qcs_sdk", "_gather_diagnostics");
export_verbatim!("qcs_sdk._qcs_sdk", "__version__");

module_doc!("quil._quil.validation", "");

define_stub_info_gatherer!(internal_stub_info);

/// Gather stub information to generate stub files.
Expand All @@ -188,12 +184,11 @@ mod stubs {
let mut stubs = StubInfo::from_pyproject_toml(manifest_dir.join("pyproject.toml"))?;

// `pyo3_stub_gen` gathers declarations from every linked crate, so dependencies that
// define their own Python packages (`quil-rs` and `qcs-api-client-common`) contribute
// their modules here too. Generation rejects any non-empty module outside this
// package's module path, and writing files for them would shadow the real, installed
// packages, so drop them. The stubs refer to foreign types by their private paths
// (`quil._quil.program.Program`), since resolving the public alias needs the foreign
// module to still be present at generation time.
// define their own Python packages (`qcs-api-client-common`) contribute their modules
// here too. Generation rejects any non-empty module outside this package's module path,
// and writing files for them would shadow the real, installed packages, so drop them.
// The stubs refer to foreign types by their private paths, since resolving the public
// alias needs the foreign module to still be present at generation time.
stubs
.modules
.retain(|name, _| name == "qcs_sdk" || name.starts_with("qcs_sdk."));
Expand Down
8 changes: 4 additions & 4 deletions crates/lib/src/qpu/experimental/python.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Python bindings for the experimental QPU module.

use quil_rs::quil::{Quil, ToQuilError};
use quil_rs::quil::Quil;
use rigetti_pyo3::create_init_submodule;

use crate::qpu::experimental::random::ChooseRandomRealSubRegions;
use crate::qpu::experimental::random::{ChooseRandomRealSubRegions, Error as RandomError};

create_init_submodule! {
submodules: [ "random": random::init_submodule ],
Expand Down Expand Up @@ -40,7 +40,7 @@ impl ChooseRandomRealSubRegions {
/// ```
#[staticmethod]
#[pyo3(name = "build_signature")]
fn py_build_signature() -> Result<String, ToQuilError> {
ChooseRandomRealSubRegions::build_signature().to_quil()
fn py_build_signature() -> Result<String, RandomError> {
Ok(ChooseRandomRealSubRegions::build_signature().to_quil()?)
}
}
2 changes: 1 addition & 1 deletion crates/lib/tests_py/compiler/test_quilc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_compile_program(
result = compile_program(
bell_program, target_device, client=quilc_rpcq_client, options=CompilerOpts(protoquil=True)
)
assert result.program.to_quil() == snapshot
assert result.program == snapshot
assert result.native_quil_metadata == snapshot


Expand Down
50 changes: 5 additions & 45 deletions crates/lib/tests_py/qpu/experimental/test_random.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
from quil.program import Program
from quil.instructions import (
Declaration,
Instruction,
Pragma,
Call,
CallArgument,
MemoryReference,
Vector,
ScalarType,
PragmaArgument,
)
from qcs_sdk.qpu.experimental.random import ChooseRandomRealSubRegions


EXPECTED_QUIL = """
PRAGMA EXTERN choose_random_real_sub_regions "(destination : mut REAL[], source : REAL[], sub_region_size : INTEGER, seed : mut INTEGER)"
DECLARE destination REAL[3]
DECLARE source REAL[12]
DECLARE seed INTEGER[1]
CALL choose_random_real_sub_regions destination source 3 seed[0]
"""


def test_choose_random_real_subregions():
"""Test that `ChooseRandomRealSubRegions` is correctly added to a Quil progrram."""
program = Program()
destination = Declaration("destination", Vector(ScalarType.REAL, 3), None)
program.add_instruction(Instruction.Declaration(destination))
source = Declaration("source", Vector(ScalarType.REAL, 12), None)
program.add_instruction(Instruction.Declaration(source))
seed = Declaration("seed", Vector(ScalarType.INTEGER, 1), None)
program.add_instruction(Instruction.Declaration(seed))
pragma_extern = Pragma(
"EXTERN",
[PragmaArgument.Identifier(ChooseRandomRealSubRegions.NAME)],
ChooseRandomRealSubRegions.build_signature(),
)
program.add_instruction(Instruction.Pragma(pragma_extern))
call = Call(
ChooseRandomRealSubRegions.NAME,
[
CallArgument.Identifier("destination"),
CallArgument.Identifier("source"),
CallArgument.Immediate(complex(3, 0)),
CallArgument.MemoryReference(MemoryReference("seed", 0)),
],
"""Test the name and signature used to declare `ChooseRandomRealSubRegions` in a Quil program."""
assert ChooseRandomRealSubRegions.NAME == "choose_random_real_sub_regions"
assert (
ChooseRandomRealSubRegions.build_signature()
== "(destination : mut REAL[], source : REAL[], sub_region_size : INTEGER, seed : mut INTEGER)"
Comment thread
jselig-rigetti marked this conversation as resolved.
)
program.add_instruction(Instruction.Call(call))
assert program == Program.parse(EXPECTED_QUIL)
39 changes: 2 additions & 37 deletions crates/lib/uv.lock

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

Loading