Skip to content

Conversation

@cqc-alec
Copy link
Collaborator

@cqc-alec cqc-alec commented Sep 24, 2025

Towards #2287 .

This is a temporary workaround to get the functionality now; it should be replaced with a proper implementation that parses the model data directly without going via JSON.

@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.99%. Comparing base (85ba42b) to head (f6cea5b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2581      +/-   ##
==========================================
+ Coverage   82.97%   82.99%   +0.01%     
==========================================
  Files         254      254              
  Lines       48021    48022       +1     
  Branches    43532    43532              
==========================================
+ Hits        39845    39854       +9     
+ Misses       6106     6098       -8     
  Partials     2070     2070              
Flag Coverage Δ
python 91.60% <100.00%> (+0.18%) ⬆️
rust 82.10% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cqc-alec
Copy link
Collaborator Author

I think this is working correctly as far as it goes, but its usefulness is currently limited by:

@cqc-alec cqc-alec requested a review from ss2165 September 29, 2025 13:26
@cqc-alec cqc-alec marked this pull request as ready for review September 29, 2025 13:26
@cqc-alec cqc-alec requested a review from a team as a code owner September 29, 2025 13:26
Ok(package)
}

#[pyfunction]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small docstring would help

}

#[pyfunction]
fn model_to_json(bytes: &[u8]) -> PyResult<Vec<u8>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not essential but I think it would be better to instead bind

fn convert_envelope(bytes: &[u8], output_config: EnvelopeConfig) -> PyResult<Vec<u8>>; 

for more general purpose use, like in the cli:

pub fn run_convert(&mut self) -> Result<()> {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but unfortunately pyo3 doesn't know how to bind an EnvelopeConfig. I'm sure this could be fixed but not sure it's worth it for this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least worth renaming to to_json_envelope or similar then I think, since the input can actually be any format

case EnvelopeFormat.MODEL | EnvelopeFormat.MODEL_WITH_EXTS:
msg = "Decoding HUGR envelopes in MODULE format is not supported yet."
raise ValueError(msg)
# TODO Going via JSON is a temporary solution, until we get model import to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to link to an issue here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link to #2287 ; will update the description there to clarify that this is the remaining task.

assert op2.visibility == "Private"


@pytest.mark.xfail(reason="https://github.com/CQCL/hugr/issues/2589")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally wait to merge #2590 for the fix to merge (imminent) to avoid this xfail


[dependencies]
bumpalo = { workspace = true, features = ["collections"] }
hugr = { version = "0.22.4", path = "../hugr" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import from hugr_core directly

@cqc-alec cqc-alec requested a review from ss2165 September 29, 2025 16:10
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers

@cqc-alec cqc-alec added this pull request to the merge queue Sep 30, 2025
Merged via the queue into main with commit 4fb0a5e Sep 30, 2025
26 checks passed
@cqc-alec cqc-alec deleted the ae/model-hack branch September 30, 2025 07:56
github-merge-queue bot pushed a commit that referenced this pull request Oct 13, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.14.0](hugr-py-v0.13.1...hugr-py-v0.14.0)
(2025-10-13)


### ⚠ BREAKING CHANGES

* BorrowArray::{borrow, is_borrowed} return types have been swapped such
that the array is first.

### Features

* Add more options to `DotRenderer` config
([#2540](#2540))
([45f7573](45f7573))
* Allow importing from model data to python.
([#2581](#2581))
([4fb0a5e](4fb0a5e))
* **py, core, llvm:** add `is_borrowed` op for BorrowArray
([#2610](#2610))
([1cd08ef](1cd08ef)),
closes [#2569](#2569)


### Bug Fixes

* Preserve offset for CFG edges when serializing to JSON
([#2606](#2606))
([69a126d](69a126d))


### Code Refactoring

* consistent inout order in borrow array
([#2621](#2621))
([8fc59f3](8fc59f3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants