From 6800e68bb4006d9603ac498095d81893613bfac3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Agust=C3=ADn=20Borgna?=
<121866228+aborgna-q@users.noreply.github.com>
Date: Fri, 7 Jun 2024 10:14:41 +0100
Subject: [PATCH 1/4] ci: Unpin nightly (#1179)
The ICE on nightly got fixed with a revert commit
https://github.com/rust-lang/rust/commit/98489f2487465f3765e5dd28d7305ebfd40f0865
---
.github/workflows/ci-rs.yml | 9 ++-------
hugr-core/src/builder/tail_loop.rs | 2 +-
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/ci-rs.yml b/.github/workflows/ci-rs.yml
index cb171fd5a..d14124173 100644
--- a/.github/workflows/ci-rs.yml
+++ b/.github/workflows/ci-rs.yml
@@ -123,9 +123,7 @@ jobs:
strategy:
fail-fast: true
matrix:
- # Pinned nightly version until this gets resolved:
- # https://github.com/rust-lang/rust/issues/125474
- rust: ['1.75', beta, 'nightly-2024-05-22']
+ rust: ['1.75', beta, 'nightly']
name: tests (Rust ${{ matrix.rust }})
steps:
- uses: actions/checkout@v4
@@ -182,10 +180,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
# Nightly is required to count doctests coverage
- #
- # Pinned nightly version until this gets resolved
- # https://github.com/rust-lang/rust/issues/125474
- toolchain: 'nightly-2024-05-22'
+ toolchain: 'nightly'
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
diff --git a/hugr-core/src/builder/tail_loop.rs b/hugr-core/src/builder/tail_loop.rs
index 901324fe9..0c87d8393 100644
--- a/hugr-core/src/builder/tail_loop.rs
+++ b/hugr-core/src/builder/tail_loop.rs
@@ -26,7 +26,7 @@ impl + AsRef> TailLoopBuilder {
Ok(TailLoopBuilder::from_dfg_builder(dfg_build))
}
/// Set the outputs of the [`ops::TailLoop`], with `out_variant` as the value of the
- /// termination Sum, and `rest` being the remaining outputs
+ /// termination Sum, and `rest` being the remaining outputs.
pub fn set_outputs(
&mut self,
out_variant: Wire,
From 68595c8a776b7a789a078f3c6d5f7ed384f97901 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Agust=C3=ADn=20Borgna?=
<121866228+aborgna-q@users.noreply.github.com>
Date: Fri, 7 Jun 2024 13:10:57 +0100
Subject: [PATCH 2/4] fix: Do not require matching extension_reqs when creating
a replacement (#1177)
Fixes #1175
Signatures have three components:
- The input type row
- The output type row
- The set of extensions used by the local operations
Many interesting replacements in a graph changes the latter, but
`SiblingSubgraph::create_simple_replacement` required the signatures to
match exactly.
---
hugr-core/src/hugr/views/sibling_subgraph.rs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hugr-core/src/hugr/views/sibling_subgraph.rs b/hugr-core/src/hugr/views/sibling_subgraph.rs
index ddc307509..a024bcc17 100644
--- a/hugr-core/src/hugr/views/sibling_subgraph.rs
+++ b/hugr-core/src/hugr/views/sibling_subgraph.rs
@@ -345,7 +345,12 @@ impl SiblingSubgraph {
let Some([rep_input, rep_output]) = replacement.get_io(rep_root) else {
return Err(InvalidReplacement::InvalidDataflowParent);
};
- if dfg_optype.dataflow_signature() != Some(self.signature(hugr)) {
+
+ let current_signature = self.signature(hugr);
+ let new_signature = dfg_optype.dataflow_signature();
+ if new_signature.as_ref().map(|s| &s.input) != Some(¤t_signature.input)
+ || new_signature.as_ref().map(|s| &s.output) != Some(¤t_signature.output)
+ {
return Err(InvalidReplacement::InvalidSignature);
}
From 71509d9fa4a0d45108e12601204b4e556783d1dc Mon Sep 17 00:00:00 2001
From: hugrbot
Date: Fri, 7 Jun 2024 14:26:17 +0100
Subject: [PATCH 3/4] chore: release (#1180)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## 🤖 New release
* `hugr`: 0.5.0 -> 0.5.1
* `hugr-core`: 0.1.0 -> 0.2.0
* `hugr-passes`: 0.1.0 -> 0.2.0
* `hugr-cli`: 0.1.0 -> 0.1.1
Changelog
## `hugr`
## 0.5.1 (2024-06-07)
### Refactor
- Move binary to hugr-cli
([#1134](https://github.com/CQCL/hugr/pull/1134))
## `hugr-core`
## 0.2.0 (2024-06-07)
### Bug Fixes
- [**breaking**] Validate that control-flow outputs have exactly one
successor ([#1144](https://github.com/CQCL/hugr/pull/1144))
- Do not require matching extension_reqs when creating a replacement
([#1177](https://github.com/CQCL/hugr/pull/1177))
### Features
- Add `ConstExternalSymbol` to prelude
([#1123](https://github.com/CQCL/hugr/pull/1123))
- `HugrView::extract_hugr` to extract regions into owned hugrs.
([#1173](https://github.com/CQCL/hugr/pull/1173))
### Testing
- Serialisation round trip testing for `OpDef`
([#999](https://github.com/CQCL/hugr/pull/999))
## `hugr-passes`
## 0.2.0 (2024-06-07)
### Features
- Add `ValidationLevel` tooling and apply to `constant_fold_pass`
([#1035](https://github.com/CQCL/hugr/pull/1035))
## `hugr-cli`
## 0.1.1 (2024-06-07)
### Features
- Reexport `clap::Parser` and `clap_verbosity_flag::Level` from hugr_cli
([#1146](https://github.com/CQCL/hugr/pull/1146))
### Refactor
- Move binary to hugr-cli
([#1134](https://github.com/CQCL/hugr/pull/1134))
---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
---
hugr-cli/CHANGELOG.md | 11 +++++++++++
hugr-cli/Cargo.toml | 4 ++--
hugr-core/CHANGELOG.md | 17 +++++++++++++++++
hugr-core/Cargo.toml | 2 +-
hugr-passes/CHANGELOG.md | 7 +++++++
hugr-passes/Cargo.toml | 4 ++--
hugr/CHANGELOG.md | 21 +++++++++++++++++++++
hugr/Cargo.toml | 6 +++---
release-plz.toml | 1 +
9 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/hugr-cli/CHANGELOG.md b/hugr-cli/CHANGELOG.md
index 56ceb5d6e..018e58f46 100644
--- a/hugr-cli/CHANGELOG.md
+++ b/hugr-cli/CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog
+## 0.1.1 (2024-06-07)
+
+### Features
+
+- Reexport `clap::Parser` and `clap_verbosity_flag::Level` from hugr_cli ([#1146](https://github.com/CQCL/hugr/pull/1146))
+
+### Refactor
+
+- Move binary to hugr-cli ([#1134](https://github.com/CQCL/hugr/pull/1134))
+
+
## 0.1.0 (2024-05-29)
Initial release, ported from `hugr::cli` module.
diff --git a/hugr-cli/Cargo.toml b/hugr-cli/Cargo.toml
index 1bded9844..0d6d01264 100644
--- a/hugr-cli/Cargo.toml
+++ b/hugr-cli/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hugr-cli"
-version = "0.1.0"
+version = "0.1.1"
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
@@ -17,7 +17,7 @@ categories = ["compilers"]
clap = {workspace = true, features = ["derive"]}
clap-stdin.workspace = true
clap-verbosity-flag.workspace = true
-hugr-core = { path = "../hugr-core", version = "0.1.0" }
+hugr-core = { path = "../hugr-core", version = "0.2.0" }
serde_json.workspace = true
thiserror.workspace = true
diff --git a/hugr-core/CHANGELOG.md b/hugr-core/CHANGELOG.md
index 825172112..bc0079bfa 100644
--- a/hugr-core/CHANGELOG.md
+++ b/hugr-core/CHANGELOG.md
@@ -1,5 +1,22 @@
# Changelog
+## 0.2.0 (2024-06-07)
+
+### Bug Fixes
+
+- [**breaking**] Validate that control-flow outputs have exactly one successor ([#1144](https://github.com/CQCL/hugr/pull/1144))
+- Do not require matching extension_reqs when creating a replacement ([#1177](https://github.com/CQCL/hugr/pull/1177))
+
+### Features
+
+- Add `ConstExternalSymbol` to prelude ([#1123](https://github.com/CQCL/hugr/pull/1123))
+- `HugrView::extract_hugr` to extract regions into owned hugrs. ([#1173](https://github.com/CQCL/hugr/pull/1173))
+
+### Testing
+
+- Serialisation round trip testing for `OpDef` ([#999](https://github.com/CQCL/hugr/pull/999))
+
+
## 0.1.0 (2024-05-29)
### Bug Fixes
diff --git a/hugr-core/Cargo.toml b/hugr-core/Cargo.toml
index cedb24c52..21c52a5ec 100644
--- a/hugr-core/Cargo.toml
+++ b/hugr-core/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hugr-core"
-version = "0.1.0"
+version = "0.2.0"
edition = { workspace = true }
rust-version = { workspace = true }
diff --git a/hugr-passes/CHANGELOG.md b/hugr-passes/CHANGELOG.md
index d59f22aea..dee4ec6c3 100644
--- a/hugr-passes/CHANGELOG.md
+++ b/hugr-passes/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## 0.2.0 (2024-06-07)
+
+### Features
+
+- Add `ValidationLevel` tooling and apply to `constant_fold_pass` ([#1035](https://github.com/CQCL/hugr/pull/1035))
+
+
## 0.1.0 (2024-05-29)
Initial release, with functions ported from the `hugr::algorithms` module.
diff --git a/hugr-passes/Cargo.toml b/hugr-passes/Cargo.toml
index 240468f4c..231b04d05 100644
--- a/hugr-passes/Cargo.toml
+++ b/hugr-passes/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hugr-passes"
-version = "0.1.0"
+version = "0.2.0"
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
@@ -13,7 +13,7 @@ keywords = ["Quantum", "Quantinuum"]
categories = ["compilers"]
[dependencies]
-hugr-core = { path = "../hugr-core", version = "0.1.0" }
+hugr-core = { path = "../hugr-core", version = "0.2.0" }
itertools = { workspace = true }
lazy_static = { workspace = true }
paste = { workspace = true }
diff --git a/hugr/CHANGELOG.md b/hugr/CHANGELOG.md
index 0dc838a40..3bddd8307 100644
--- a/hugr/CHANGELOG.md
+++ b/hugr/CHANGELOG.md
@@ -1,5 +1,26 @@
# Changelog
+## 0.5.1 (2024-06-07)
+
+### Bug Fixes
+
+- Validate that control-flow outputs have exactly one successor ([#1144](https://github.com/CQCL/hugr/pull/1144))
+- Do not require matching extension_reqs when creating a replacement ([#1177](https://github.com/CQCL/hugr/pull/1177))
+
+### Features
+
+- Add `ConstExternalSymbol` to prelude ([#1123](https://github.com/CQCL/hugr/pull/1123))
+- `HugrView::extract_hugr` to extract regions into owned hugrs. ([#1173](https://github.com/CQCL/hugr/pull/1173))
+
+### Testing
+
+- Serialisation round trip testing for `OpDef` ([#999](https://github.com/CQCL/hugr/pull/999))
+
+### Refactor
+
+- Move binary to hugr-cli ([#1134](https://github.com/CQCL/hugr/pull/1134))
+
+
## 0.5.0 (2024-05-29)
### Bug Fixes
diff --git a/hugr/Cargo.toml b/hugr/Cargo.toml
index 19049eafc..dff1dd10b 100644
--- a/hugr/Cargo.toml
+++ b/hugr/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hugr"
-version = "0.5.0"
+version = "0.5.1"
edition = { workspace = true }
rust-version = { workspace = true }
@@ -25,8 +25,8 @@ path = "src/lib.rs"
extension_inference = []
[dependencies]
-hugr-core = { path = "../hugr-core", version = "0.1.0" }
-hugr-passes = { path = "../hugr-passes", version = "0.1.0" }
+hugr-core = { path = "../hugr-core", version = "0.2.0" }
+hugr-passes = { path = "../hugr-passes", version = "0.2.0" }
[dev-dependencies]
rstest = { workspace = true }
diff --git a/release-plz.toml b/release-plz.toml
index c2e0c3d40..4a4d4a902 100644
--- a/release-plz.toml
+++ b/release-plz.toml
@@ -17,6 +17,7 @@ git_release_name = "{{ package }}: v{{ version }}"
[[package]]
name = "hugr"
+changelog_include = ["hugr-core", "hugr-passes"]
release = true
[[package]]
From 15c3ea904e4733a5756b5ef0f3521e908f1ec9b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Agust=C3=ADn=20Borgna?=
<121866228+aborgna-q@users.noreply.github.com>
Date: Fri, 7 Jun 2024 15:41:53 +0100
Subject: [PATCH 4/4] feat: CircuitBuilder::add_constant (#1168)
Closes #1163.
~~Blocked by #1142.~~
---
hugr-core/src/builder.rs | 4 +++-
hugr-core/src/builder/circuit.rs | 26 +++++++++++++++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/hugr-core/src/builder.rs b/hugr-core/src/builder.rs
index c186b57cd..787decc07 100644
--- a/hugr-core/src/builder.rs
+++ b/hugr-core/src/builder.rs
@@ -222,6 +222,7 @@ pub(crate) mod test {
use crate::hugr::{views::HugrView, HugrMut, NodeType};
use crate::ops;
+ use crate::std_extensions::arithmetic::float_ops::FLOAT_OPS_REGISTRY;
use crate::types::{FunctionType, PolyFuncType, Type};
use crate::{type_row, Hugr};
@@ -252,7 +253,8 @@ pub(crate) mod test {
let f_builder = module_builder.define_function("main", signature)?;
f(f_builder)?;
- Ok(module_builder.finish_prelude_hugr()?)
+
+ Ok(module_builder.finish_hugr(&FLOAT_OPS_REGISTRY)?)
}
#[fixture]
diff --git a/hugr-core/src/builder/circuit.rs b/hugr-core/src/builder/circuit.rs
index d59098776..22475cb03 100644
--- a/hugr-core/src/builder/circuit.rs
+++ b/hugr-core/src/builder/circuit.rs
@@ -3,7 +3,7 @@ use std::mem;
use thiserror::Error;
-use crate::ops::{NamedOp, OpType};
+use crate::ops::{NamedOp, OpType, Value};
use crate::utils::collect_array;
use super::{BuildError, Dataflow};
@@ -199,6 +199,11 @@ impl<'a, T: Dataflow + ?Sized> CircuitBuilder<'a, T> {
Ok(collect_array(outputs))
}
+ /// Adds a constant value to the circuit and loads it into a wire.
+ pub fn add_constant(&mut self, value: impl Into) -> Wire {
+ self.builder.add_load_value(value)
+ }
+
/// Add a wire to the list of tracked wires.
///
/// Returns the new unit index.
@@ -237,7 +242,10 @@ mod test {
use super::*;
use cool_asserts::assert_matches;
- use crate::utils::test_quantum_extension::{cx_gate, h_gate, measure, q_alloc, q_discard};
+ use crate::std_extensions::arithmetic::float_types::{self, ConstF64};
+ use crate::utils::test_quantum_extension::{
+ cx_gate, h_gate, measure, q_alloc, q_discard, rz_f64,
+ };
use crate::{
builder::{
test::{build_main, NAT, QB},
@@ -250,9 +258,15 @@ mod test {
};
#[test]
+ #[cfg_attr(
+ feature = "extension_inference",
+ ignore = "Extension validation fails when mixing in the float extension"
+ )]
fn simple_linear() {
let build_res = build_main(
- FunctionType::new(type_row![QB, QB], type_row![QB, QB]).into(),
+ FunctionType::new(type_row![QB, QB], type_row![QB, QB])
+ .with_extension_delta(float_types::EXTENSION_ID)
+ .into(),
|mut f_build| {
let wires = f_build.input_wires().map(Some).collect();
@@ -268,6 +282,12 @@ mod test {
.append(cx_gate(), [0, 1])?
.append(cx_gate(), [1, 0])?;
+ let angle = linear.add_constant(ConstF64::new(0.5));
+ linear.append_and_consume(
+ rz_f64(),
+ [CircuitUnit::Linear(0), CircuitUnit::Wire(angle)],
+ )?;
+
let outs = linear.finish();
f_build.finish_with_outputs(outs)
},