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: return replaced ops from lowering #1568

Merged
merged 1 commit into from
Oct 9, 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
4 changes: 2 additions & 2 deletions .github/workflows/ci-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
enable-cache: true
- name: Install Python
run: uv python install ${{ matrix.python-version }}

- name: Setup dependencies. Fail if the lockfile is outdated.
run: uv sync --locked

Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
- { py: '3.12', coverage: true }
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
Expand Down
8 changes: 4 additions & 4 deletions hugr-passes/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum LowerError {
pub fn lower_ops(
hugr: &mut impl HugrMut,
lowering: impl Fn(&OpType) -> Option<Hugr>,
) -> Result<Vec<Node>, LowerError> {
) -> Result<Vec<(Node, OpType)>, LowerError> {
let replacements = hugr
.nodes()
.filter_map(|node| {
Expand All @@ -69,9 +69,9 @@ pub fn lower_ops(
.map(|(node, replacement)| {
let subcirc = SiblingSubgraph::try_from_nodes([node], hugr)?;
let rw = subcirc.create_simple_replacement(hugr, replacement)?;
// TODO return weights once https://github.com/CQCL/hugr/issues/476 is done.
hugr.apply_rewrite(rw)?;
Ok(node)
let mut repls = hugr.apply_rewrite(rw)?;
debug_assert_eq!(repls.len(), 1);
Ok(repls.remove(0))
})
.collect()
}
Expand Down
Loading