Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ab/replacement-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jun 7, 2024
2 parents c8b33d4 + 15c3ea9 commit a7dfad8
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 21 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions hugr-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions hugr-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -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

Expand Down
17 changes: 17 additions & 0 deletions hugr-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hugr-core"
version = "0.1.0"
version = "0.2.0"
edition = { workspace = true }
rust-version = { workspace = true }

Expand Down
4 changes: 3 additions & 1 deletion hugr-core/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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]
Expand Down
26 changes: 23 additions & 3 deletions hugr-core/src/builder/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Value>) -> Wire {
self.builder.add_load_value(value)
}

/// Add a wire to the list of tracked wires.
///
/// Returns the new unit index.
Expand Down Expand Up @@ -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},
Expand All @@ -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();

Expand All @@ -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)
},
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/builder/tail_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> TailLoopBuilder<B> {
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,
Expand Down
7 changes: 6 additions & 1 deletion hugr-core/src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ impl SiblingSubgraph {
let [rep_input, rep_output] = replacement
.get_io(rep_root)
.expect("DFG root in the replacement does not have input and output nodes.");
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(&current_signature.input)
|| new_signature.as_ref().map(|s| &s.output) != Some(&current_signature.output)
{
return Err(InvalidReplacement::InvalidSignature {
expected: self.signature(hugr),
actual: dfg_optype.dataflow_signature(),
Expand Down
7 changes: 7 additions & 0 deletions hugr-passes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions hugr-passes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -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 }
Expand Down
21 changes: 21 additions & 0 deletions hugr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions hugr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hugr"
version = "0.5.0"
version = "0.5.1"
edition = { workspace = true }
rust-version = { workspace = true }

Expand All @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions release-plz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ git_release_name = "{{ package }}: v{{ version }}"

[[package]]
name = "hugr"
changelog_include = ["hugr-core", "hugr-passes"]
release = true

[[package]]
Expand Down

0 comments on commit a7dfad8

Please sign in to comment.