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 bindings for hugr-model. #1959

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
108 changes: 108 additions & 0 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
Expand Up @@ -10,6 +10,7 @@ members = [
"hugr-cli",
"hugr-model",
"hugr-llvm",
"hugr-py",
]
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]

Expand Down Expand Up @@ -84,6 +85,7 @@ pest_derive = "2.7.12"
pretty = "0.12.4"
pretty_assertions = "1.4.1"
zstd = "0.13.2"
pyo3 = "0.23.4"

[profile.dev.package]
insta.opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/std_extensions/arithmetic/float_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl std::ops::Deref for ConstF64 {
impl ConstF64 {
/// Name of the constructor for creating constant 64bit floats.
#[cfg_attr(not(feature = "model_unstable"), allow(dead_code))]
pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const-f64";
pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const_f64";

/// Create a new [`ConstF64`]
pub fn new(value: f64) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/tests/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use hugr::std_extensions::std_reg;
use hugr_core::{export::export_hugr, import::import_hugr};
use hugr_model::v0 as model;
use hugr_model::v0::{self as model};

fn roundtrip(source: &str) -> String {
let bump = model::bumpalo::Bump::new();
Expand Down
8 changes: 4 additions & 4 deletions hugr-core/tests/snapshots/model__roundtrip_const.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons

(import arithmetic.int.const)

(import arithmetic.float.const_f64)

(import core.const.adt)

(import arithmetic.int.types.int)
Expand All @@ -24,8 +26,6 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons

(import core.adt)

(import arithmetic.float.const-f64)

(define-func
example.bools
(core.fn [] [(core.adt [[] []]) (core.adt [[] []])] (ext))
Expand Down Expand Up @@ -69,7 +69,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
(arithmetic.int.const 6 3)
(arithmetic.int.const 6 4)
(arithmetic.int.const 6 5)])
(arithmetic.float.const-f64 -3.0)]))
(arithmetic.float.const_f64 -3.0)]))
[] [%0]
(signature
(core.fn
Expand All @@ -88,7 +88,7 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cons
[]
[arithmetic.float.types.float64 arithmetic.float.types.float64]
(ext)))
((core.load_const _ _ (arithmetic.float.const-f64 1.0)) [] [%0]
((core.load_const _ _ (arithmetic.float.const_f64 1.0)) [] [%0]
(signature (core.fn [] [arithmetic.float.types.float64] (ext))))
((core.load_const
_
Expand Down
1 change: 1 addition & 0 deletions hugr-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pest_derive = { workspace = true }
pretty = { workspace = true }
smol_str = { workspace = true, features = ["serde"] }
thiserror.workspace = true
pyo3 = { workspace = true, optional = true }

[lints]
workspace = true
Expand Down
2 changes: 2 additions & 0 deletions hugr-model/src/v0/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use super::{LinkName, Literal, RegionKind, SymbolName, VarName};

mod parse;
mod print;
#[cfg(feature = "pyo3")]
mod python;
mod resolve;
mod view;

Expand Down
1 change: 1 addition & 0 deletions hugr-model/src/v0/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,4 @@ impl_from_str!(Param, param, parse_param);
impl_from_str!(Module, module, parse_module);
impl_from_str!(SeqPart, part, parse_seq_part);
impl_from_str!(Literal, literal, parse_literal);
impl_from_str!(Symbol, symbol, parse_symbol);
1 change: 1 addition & 0 deletions hugr-model/src/v0/ast/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl_display!(Param, print_param);
impl_display!(Term, print_term);
impl_display!(SeqPart, print_seq_part);
impl_display!(Literal, print_literal);
impl_display!(Symbol, print_symbol);

impl Display for VarName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
Loading
Loading