From b70999883ec7da4078b077bb674dd28623489750 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Fri, 24 May 2024 14:05:41 +0100
Subject: [PATCH 1/9] refactor: Add a `hugr-core` crate

---
 Cargo.toml                                    |   5 +-
 hugr-core/CHANGELOG.md                        |   1 +
 hugr-core/Cargo.toml                          |  63 +++++++
 hugr-core/README.md                           |  56 ++++++
 {hugr => hugr-core}/build.rs                  |   0
 {hugr => hugr-core}/src/builder.rs            |  10 +-
 .../src/builder/build_traits.rs               |   0
 {hugr => hugr-core}/src/builder/cfg.rs        |   2 +-
 {hugr => hugr-core}/src/builder/circuit.rs    |   0
 .../src/builder/conditional.rs                |   0
 {hugr => hugr-core}/src/builder/dataflow.rs   |   0
 {hugr => hugr-core}/src/builder/handle.rs     |   0
 {hugr => hugr-core}/src/builder/module.rs     |   0
 {hugr => hugr-core}/src/builder/tail_loop.rs  |   0
 {hugr => hugr-core}/src/cli.rs                |   0
 {hugr => hugr-core}/src/core.rs               |   0
 {hugr => hugr-core}/src/extension.rs          |   0
 .../src/extension/const_fold.rs               |   0
 .../src/extension/declarative.rs              |  10 +-
 .../src/extension/declarative/ops.rs          |   0
 .../src/extension/declarative/signature.rs    |   0
 .../src/extension/declarative/types.rs        |   0
 {hugr => hugr-core}/src/extension/infer.rs    |   0
 .../src/extension/infer/test.rs               |   0
 {hugr => hugr-core}/src/extension/op_def.rs   |   0
 {hugr => hugr-core}/src/extension/prelude.rs  |   0
 .../src/extension/simple_op.rs                |   0
 {hugr => hugr-core}/src/extension/type_def.rs |   0
 {hugr => hugr-core}/src/extension/validate.rs |   0
 {hugr => hugr-core}/src/hugr.rs               |   0
 {hugr => hugr-core}/src/hugr/hugrmut.rs       |   0
 {hugr => hugr-core}/src/hugr/ident.rs         |   0
 {hugr => hugr-core}/src/hugr/rewrite.rs       |   0
 .../src/hugr/rewrite/consts.rs                |   0
 .../src/hugr/rewrite/inline_dfg.rs            |   0
 .../src/hugr/rewrite/insert_identity.rs       |   0
 .../src/hugr/rewrite/outline_cfg.rs           |   0
 .../src/hugr/rewrite/replace.rs               |   0
 .../src/hugr/rewrite/simple_replace.rs        |   0
 {hugr => hugr-core}/src/hugr/serialize.rs     |   0
 .../src/hugr/serialize/test.rs                |   0
 {hugr => hugr-core}/src/hugr/validate.rs      |   0
 {hugr => hugr-core}/src/hugr/validate/test.rs |   0
 {hugr => hugr-core}/src/hugr/views.rs         |   0
 .../src/hugr/views/descendants.rs             |   0
 .../src/hugr/views/petgraph.rs                |   0
 {hugr => hugr-core}/src/hugr/views/render.rs  |   0
 .../src/hugr/views/root_checked.rs            |   0
 {hugr => hugr-core}/src/hugr/views/sibling.rs |   0
 .../src/hugr/views/sibling_subgraph.rs        |   0
 ...ugr_core__hugr__views__tests__dot_cfg.snap |   2 +-
 ...ugr_core__hugr__views__tests__dot_dfg.snap |   2 +-
 ...re__hugr__views__tests__dot_empty_dfg.snap |   2 +-
 ...ugr_core__hugr__views__tests__mmd_cfg.snap |   2 +-
 ...ugr_core__hugr__views__tests__mmd_dfg.snap |   2 +-
 ...re__hugr__views__tests__mmd_empty_dfg.snap |   2 +-
 {hugr => hugr-core}/src/hugr/views/tests.rs   |   0
 hugr-core/src/lib.rs                          | 163 ++++++++++++++++++
 {hugr => hugr-core}/src/macros.rs             |   6 +-
 {hugr => hugr-core}/src/ops.rs                |   0
 {hugr => hugr-core}/src/ops/constant.rs       |   2 +-
 .../src/ops/constant/custom.rs                |   2 +-
 {hugr => hugr-core}/src/ops/controlflow.rs    |   0
 {hugr => hugr-core}/src/ops/custom.rs         |   0
 {hugr => hugr-core}/src/ops/dataflow.rs       |  16 +-
 {hugr => hugr-core}/src/ops/handle.rs         |   0
 {hugr => hugr-core}/src/ops/leaf.rs           |   0
 {hugr => hugr-core}/src/ops/module.rs         |   0
 {hugr => hugr-core}/src/ops/tag.rs            |   0
 {hugr => hugr-core}/src/ops/validate.rs       |   0
 {hugr => hugr-core}/src/proptest.rs           |   0
 {hugr => hugr-core}/src/std_extensions.rs     |   0
 .../std_extensions/arithmetic/conversions.rs  |   0
 .../arithmetic/conversions/const_fold.rs      |   0
 .../std_extensions/arithmetic/float_ops.rs    |   0
 .../arithmetic/float_ops/const_fold.rs        |   0
 .../std_extensions/arithmetic/float_types.rs  |   0
 .../src/std_extensions/arithmetic/int_ops.rs  |   0
 .../arithmetic/int_ops/const_fold.rs          |   0
 .../std_extensions/arithmetic/int_types.rs    |   0
 .../src/std_extensions/arithmetic/mod.rs      |   0
 .../src/std_extensions/collections.rs         |   0
 .../src/std_extensions/logic.rs               |   0
 {hugr => hugr-core}/src/types.rs              |   6 +-
 {hugr => hugr-core}/src/types/check.rs        |   0
 {hugr => hugr-core}/src/types/custom.rs       |   0
 {hugr => hugr-core}/src/types/poly_func.rs    |   0
 {hugr => hugr-core}/src/types/serialize.rs    |   0
 {hugr => hugr-core}/src/types/signature.rs    |   0
 {hugr => hugr-core}/src/types/type_param.rs   |   0
 {hugr => hugr-core}/src/types/type_row.rs     |   0
 {hugr => hugr-core}/src/utils.rs              |   0
 hugr-passes/Cargo.toml                        |   4 +-
 hugr-passes/src/const_fold.rs                 |   8 +-
 hugr-passes/src/const_fold/test.rs            |  36 ++--
 hugr-passes/src/half_node.rs                  |  14 +-
 hugr-passes/src/merge_bbs.rs                  |  34 ++--
 hugr-passes/src/nest_cfgs.rs                  |  40 +++--
 hugr/Cargo.toml                               |  46 ++---
 hugr/src/lib.rs                               |  25 +--
 hugr/src/main.rs                              |   2 +-
 hugr/tests/cli.rs                             |   6 +-
 102 files changed, 410 insertions(+), 159 deletions(-)
 create mode 100644 hugr-core/CHANGELOG.md
 create mode 100644 hugr-core/Cargo.toml
 create mode 100644 hugr-core/README.md
 rename {hugr => hugr-core}/build.rs (100%)
 rename {hugr => hugr-core}/src/builder.rs (96%)
 rename {hugr => hugr-core}/src/builder/build_traits.rs (100%)
 rename {hugr => hugr-core}/src/builder/cfg.rs (99%)
 rename {hugr => hugr-core}/src/builder/circuit.rs (100%)
 rename {hugr => hugr-core}/src/builder/conditional.rs (100%)
 rename {hugr => hugr-core}/src/builder/dataflow.rs (100%)
 rename {hugr => hugr-core}/src/builder/handle.rs (100%)
 rename {hugr => hugr-core}/src/builder/module.rs (100%)
 rename {hugr => hugr-core}/src/builder/tail_loop.rs (100%)
 rename {hugr => hugr-core}/src/cli.rs (100%)
 rename {hugr => hugr-core}/src/core.rs (100%)
 rename {hugr => hugr-core}/src/extension.rs (100%)
 rename {hugr => hugr-core}/src/extension/const_fold.rs (100%)
 rename {hugr => hugr-core}/src/extension/declarative.rs (97%)
 rename {hugr => hugr-core}/src/extension/declarative/ops.rs (100%)
 rename {hugr => hugr-core}/src/extension/declarative/signature.rs (100%)
 rename {hugr => hugr-core}/src/extension/declarative/types.rs (100%)
 rename {hugr => hugr-core}/src/extension/infer.rs (100%)
 rename {hugr => hugr-core}/src/extension/infer/test.rs (100%)
 rename {hugr => hugr-core}/src/extension/op_def.rs (100%)
 rename {hugr => hugr-core}/src/extension/prelude.rs (100%)
 rename {hugr => hugr-core}/src/extension/simple_op.rs (100%)
 rename {hugr => hugr-core}/src/extension/type_def.rs (100%)
 rename {hugr => hugr-core}/src/extension/validate.rs (100%)
 rename {hugr => hugr-core}/src/hugr.rs (100%)
 rename {hugr => hugr-core}/src/hugr/hugrmut.rs (100%)
 rename {hugr => hugr-core}/src/hugr/ident.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/consts.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/inline_dfg.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/insert_identity.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/outline_cfg.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/replace.rs (100%)
 rename {hugr => hugr-core}/src/hugr/rewrite/simple_replace.rs (100%)
 rename {hugr => hugr-core}/src/hugr/serialize.rs (100%)
 rename {hugr => hugr-core}/src/hugr/serialize/test.rs (100%)
 rename {hugr => hugr-core}/src/hugr/validate.rs (100%)
 rename {hugr => hugr-core}/src/hugr/validate/test.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/descendants.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/petgraph.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/render.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/root_checked.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/sibling.rs (100%)
 rename {hugr => hugr-core}/src/hugr/views/sibling_subgraph.rs (100%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap (98%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap (98%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap (94%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap (94%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap (90%)
 rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap (81%)
 rename {hugr => hugr-core}/src/hugr/views/tests.rs (100%)
 create mode 100644 hugr-core/src/lib.rs
 rename {hugr => hugr-core}/src/macros.rs (95%)
 rename {hugr => hugr-core}/src/ops.rs (100%)
 rename {hugr => hugr-core}/src/ops/constant.rs (99%)
 rename {hugr => hugr-core}/src/ops/constant/custom.rs (99%)
 rename {hugr => hugr-core}/src/ops/controlflow.rs (100%)
 rename {hugr => hugr-core}/src/ops/custom.rs (100%)
 rename {hugr => hugr-core}/src/ops/dataflow.rs (97%)
 rename {hugr => hugr-core}/src/ops/handle.rs (100%)
 rename {hugr => hugr-core}/src/ops/leaf.rs (100%)
 rename {hugr => hugr-core}/src/ops/module.rs (100%)
 rename {hugr => hugr-core}/src/ops/tag.rs (100%)
 rename {hugr => hugr-core}/src/ops/validate.rs (100%)
 rename {hugr => hugr-core}/src/proptest.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/conversions.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/conversions/const_fold.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_ops.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_ops/const_fold.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_types.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_ops.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_ops/const_fold.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_types.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/arithmetic/mod.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/collections.rs (100%)
 rename {hugr => hugr-core}/src/std_extensions/logic.rs (100%)
 rename {hugr => hugr-core}/src/types.rs (99%)
 rename {hugr => hugr-core}/src/types/check.rs (100%)
 rename {hugr => hugr-core}/src/types/custom.rs (100%)
 rename {hugr => hugr-core}/src/types/poly_func.rs (100%)
 rename {hugr => hugr-core}/src/types/serialize.rs (100%)
 rename {hugr => hugr-core}/src/types/signature.rs (100%)
 rename {hugr => hugr-core}/src/types/type_param.rs (100%)
 rename {hugr => hugr-core}/src/types/type_row.rs (100%)
 rename {hugr => hugr-core}/src/utils.rs (100%)

diff --git a/Cargo.toml b/Cargo.toml
index b7adbd9b4..a013edfc4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,8 +3,9 @@ lto = "thin"
 
 [workspace]
 resolver = "2"
-members = ["hugr", "hugr-passes"]
-default-members = ["hugr", "hugr-passes"]
+members = ["hugr", "hugr-core", "hugr-passes"]
+default-members = ["hugr", "hugr-core", "hugr-passes"]
+default-run = "hugr"
 
 [workspace.package]
 rust-version = "1.75"
diff --git a/hugr-core/CHANGELOG.md b/hugr-core/CHANGELOG.md
new file mode 100644
index 000000000..825c32f0d
--- /dev/null
+++ b/hugr-core/CHANGELOG.md
@@ -0,0 +1 @@
+# Changelog
diff --git a/hugr-core/Cargo.toml b/hugr-core/Cargo.toml
new file mode 100644
index 000000000..f32dd58ec
--- /dev/null
+++ b/hugr-core/Cargo.toml
@@ -0,0 +1,63 @@
+[package]
+name = "hugr-core"
+version = "0.0.0"
+edition = { workspace = true }
+rust-version = { workspace = true }
+
+license = { workspace = true }
+readme = "README.md"
+documentation = "https://docs.rs/hugr/"
+homepage = { workspace = true }
+repository = { workspace = true }
+description = "Quantinuum's Hierarchical Unified Graph Representation"
+keywords = ["Quantum", "Quantinuum"]
+categories = ["compilers"]
+
+[lints]
+workspace = true
+
+[features]
+extension_inference = []
+cli = ["dep:clap", "dep:clap-stdin"]
+
+[dependencies]
+portgraph = { workspace = true, features = ["serde", "petgraph"] }
+thiserror = { workspace = true }
+regex = { workspace = true }
+cgmath = { workspace = true, features = ["serde"] }
+num-rational = { workspace = true, features = ["serde"] }
+downcast-rs = { workspace = true }
+# Rc used here for Extension, but unfortunately we must turn the feature on globally
+serde = { workspace = true, features = ["derive", "rc"] }
+serde_yaml = { workspace = true }
+typetag = { workspace = true }
+smol_str = { workspace = true, features = ["serde"] }
+derive_more = { workspace = true }
+itertools = { workspace = true }
+html-escape = { workspace = true }
+bitvec = { workspace = true, features = ["serde"] }
+enum_dispatch = { workspace = true }
+lazy_static = { workspace = true }
+petgraph = { workspace = true }
+context-iterators = { workspace = true }
+serde_json = { workspace = true }
+delegate = { workspace = true }
+paste = { workspace = true }
+strum = { workspace = true }
+strum_macros = { workspace = true }
+clap = { workspace = true, features = ["derive"], optional = true }
+clap-stdin = { workspace = true, optional = true }
+
+[dev-dependencies]
+rstest = { workspace = true }
+webbrowser = { workspace = true }
+urlencoding = { workspace = true }
+cool_asserts = { workspace = true }
+insta = { workspace = true, features = ["yaml"] }
+jsonschema = { workspace = true }
+proptest = { workspace = true }
+proptest-derive = { workspace = true }
+regex-syntax = { workspace = true }
+assert_cmd = { workspace = true }
+predicates = { workspace = true }
+assert_fs = { workspace = true }
diff --git a/hugr-core/README.md b/hugr-core/README.md
new file mode 100644
index 000000000..11479c106
--- /dev/null
+++ b/hugr-core/README.md
@@ -0,0 +1,56 @@
+![](/hugr/assets/hugr_logo.svg)
+
+hugr-core
+===============
+
+[![build_status][]](https://github.com/CQCL/hugr/actions)
+[![crates][]](https://crates.io/crates/hugr-core)
+[![msrv][]](https://github.com/CQCL/hugr)
+[![codecov][]](https://codecov.io/gh/CQCL/hugr)
+
+The Hierarchical Unified Graph Representation (HUGR, pronounced _hugger_) is the
+common representation of quantum circuits and operations in the Quantinuum
+ecosystem.
+
+It provides a high-fidelity representation of operations, that facilitates
+compilation and encodes runnable programs.
+
+The HUGR specification is [here](https://github.com/CQCL/hugr/blob/main/specification/hugr.md).
+
+## Usage
+
+Add the dependency to your project:
+
+```bash
+cargo add hugr-core
+```
+
+Please read the [API documentation here][].
+
+## Experimental Features
+
+- `extension_inference`:
+  Experimental feature which allows automatic inference of extension usages and
+  requirements in a HUGR and validation that extensions are correctly specified.
+  Not enabled by default.
+
+## Recent Changes
+
+See [CHANGELOG][] for a list of changes. The minimum supported rust
+version will only change on major releases.
+
+## Development
+
+See [DEVELOPMENT.md](https://github.com/CQCL/hugr/blob/main/DEVELOPMENT.md) for instructions on setting up the development environment.
+
+## License
+
+This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0).
+
+  [API documentation here]: https://docs.rs/hugr-core/
+  [build_status]: https://github.com/CQCL/hugr/actions/workflows/ci-rs.yml/badge.svg?branch=main
+  [msrv]: https://img.shields.io/badge/rust-1.75.0%2B-blue.svg
+  [crates]: https://img.shields.io/crates/v/hugr-core
+  [codecov]: https://img.shields.io/codecov/c/gh/CQCL/hugr?logo=codecov
+  [LICENSE]: https://github.com/CQCL/hugr/blob/main/LICENCE
+  [CHANGELOG]: https://github.com/CQCL/hugr/blob/main/hugr-core/CHANGELOG.md
diff --git a/hugr/build.rs b/hugr-core/build.rs
similarity index 100%
rename from hugr/build.rs
rename to hugr-core/build.rs
diff --git a/hugr/src/builder.rs b/hugr-core/src/builder.rs
similarity index 96%
rename from hugr/src/builder.rs
rename to hugr-core/src/builder.rs
index c186b57cd..3d0365904 100644
--- a/hugr/src/builder.rs
+++ b/hugr-core/src/builder.rs
@@ -26,11 +26,11 @@
 //! `CircuitBuilder`.
 //!
 //! ```rust
-//! # use hugr::Hugr;
-//! # use hugr::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
-//! use hugr::extension::prelude::BOOL_T;
-//! use hugr::std_extensions::logic::{NotOp, LOGIC_REG};
-//! use hugr::types::FunctionType;
+//! # use hugr_core::Hugr;
+//! # use hugr_core::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
+//! use hugr_core::extension::prelude::BOOL_T;
+//! use hugr_core::std_extensions::logic::{NotOp, LOGIC_REG};
+//! use hugr_core::types::FunctionType;
 //!
 //! # fn doctest() -> Result<(), BuildError> {
 //! let hugr = {
diff --git a/hugr/src/builder/build_traits.rs b/hugr-core/src/builder/build_traits.rs
similarity index 100%
rename from hugr/src/builder/build_traits.rs
rename to hugr-core/src/builder/build_traits.rs
diff --git a/hugr/src/builder/cfg.rs b/hugr-core/src/builder/cfg.rs
similarity index 99%
rename from hugr/src/builder/cfg.rs
rename to hugr-core/src/builder/cfg.rs
index 1ac852b45..9280917ae 100644
--- a/hugr/src/builder/cfg.rs
+++ b/hugr-core/src/builder/cfg.rs
@@ -45,7 +45,7 @@ use crate::{
 ///            |    Exit    |
 ///            +------------+
 /// */
-/// use hugr::{
+/// use hugr_core::{
 ///     builder::{BuildError, CFGBuilder, Container, Dataflow, HugrBuilder},
 ///     extension::{prelude, ExtensionSet},
 ///     ops, type_row,
diff --git a/hugr/src/builder/circuit.rs b/hugr-core/src/builder/circuit.rs
similarity index 100%
rename from hugr/src/builder/circuit.rs
rename to hugr-core/src/builder/circuit.rs
diff --git a/hugr/src/builder/conditional.rs b/hugr-core/src/builder/conditional.rs
similarity index 100%
rename from hugr/src/builder/conditional.rs
rename to hugr-core/src/builder/conditional.rs
diff --git a/hugr/src/builder/dataflow.rs b/hugr-core/src/builder/dataflow.rs
similarity index 100%
rename from hugr/src/builder/dataflow.rs
rename to hugr-core/src/builder/dataflow.rs
diff --git a/hugr/src/builder/handle.rs b/hugr-core/src/builder/handle.rs
similarity index 100%
rename from hugr/src/builder/handle.rs
rename to hugr-core/src/builder/handle.rs
diff --git a/hugr/src/builder/module.rs b/hugr-core/src/builder/module.rs
similarity index 100%
rename from hugr/src/builder/module.rs
rename to hugr-core/src/builder/module.rs
diff --git a/hugr/src/builder/tail_loop.rs b/hugr-core/src/builder/tail_loop.rs
similarity index 100%
rename from hugr/src/builder/tail_loop.rs
rename to hugr-core/src/builder/tail_loop.rs
diff --git a/hugr/src/cli.rs b/hugr-core/src/cli.rs
similarity index 100%
rename from hugr/src/cli.rs
rename to hugr-core/src/cli.rs
diff --git a/hugr/src/core.rs b/hugr-core/src/core.rs
similarity index 100%
rename from hugr/src/core.rs
rename to hugr-core/src/core.rs
diff --git a/hugr/src/extension.rs b/hugr-core/src/extension.rs
similarity index 100%
rename from hugr/src/extension.rs
rename to hugr-core/src/extension.rs
diff --git a/hugr/src/extension/const_fold.rs b/hugr-core/src/extension/const_fold.rs
similarity index 100%
rename from hugr/src/extension/const_fold.rs
rename to hugr-core/src/extension/const_fold.rs
diff --git a/hugr/src/extension/declarative.rs b/hugr-core/src/extension/declarative.rs
similarity index 97%
rename from hugr/src/extension/declarative.rs
rename to hugr-core/src/extension/declarative.rs
index 80c44b40f..3931184b5 100644
--- a/hugr/src/extension/declarative.rs
+++ b/hugr-core/src/extension/declarative.rs
@@ -9,15 +9,15 @@
 //! ### Example
 //!
 //! ```yaml
-#![doc = include_str!("../../examples/extension/declarative.yaml")]
+#![doc = include_str!("../../../hugr/examples/extension/declarative.yaml")]
 //! ```
 //!
 //! The definition can be loaded into a registry using the [`load_extensions`] or [`load_extensions_file`] functions.
 //! ```rust
-//! # const DECLARATIVE_YAML: &str = include_str!("../../examples/extension/declarative.yaml");
-//! # use hugr::extension::declarative::load_extensions;
+//! # const DECLARATIVE_YAML: &str = include_str!("../../../hugr/examples/extension/declarative.yaml");
+//! # use hugr_core::extension::declarative::load_extensions;
 //! // Required extensions must already be present in the registry.
-//! let mut reg = hugr::std_extensions::logic::LOGIC_REG.clone();
+//! let mut reg = hugr_core::std_extensions::logic::LOGIC_REG.clone();
 //! load_extensions(DECLARATIVE_YAML, &mut reg).unwrap();
 //! ```
 //!
@@ -327,7 +327,7 @@ extensions:
 "#;
 
     /// The yaml used in the module documentation.
-    const EXAMPLE_YAML_FILE: &str = "examples/extension/declarative.yaml";
+    const EXAMPLE_YAML_FILE: &str = "../hugr/examples/extension/declarative.yaml";
 
     #[rstest]
     #[case(EMPTY_YAML, 1, 0, 0, &PRELUDE_REGISTRY)]
diff --git a/hugr/src/extension/declarative/ops.rs b/hugr-core/src/extension/declarative/ops.rs
similarity index 100%
rename from hugr/src/extension/declarative/ops.rs
rename to hugr-core/src/extension/declarative/ops.rs
diff --git a/hugr/src/extension/declarative/signature.rs b/hugr-core/src/extension/declarative/signature.rs
similarity index 100%
rename from hugr/src/extension/declarative/signature.rs
rename to hugr-core/src/extension/declarative/signature.rs
diff --git a/hugr/src/extension/declarative/types.rs b/hugr-core/src/extension/declarative/types.rs
similarity index 100%
rename from hugr/src/extension/declarative/types.rs
rename to hugr-core/src/extension/declarative/types.rs
diff --git a/hugr/src/extension/infer.rs b/hugr-core/src/extension/infer.rs
similarity index 100%
rename from hugr/src/extension/infer.rs
rename to hugr-core/src/extension/infer.rs
diff --git a/hugr/src/extension/infer/test.rs b/hugr-core/src/extension/infer/test.rs
similarity index 100%
rename from hugr/src/extension/infer/test.rs
rename to hugr-core/src/extension/infer/test.rs
diff --git a/hugr/src/extension/op_def.rs b/hugr-core/src/extension/op_def.rs
similarity index 100%
rename from hugr/src/extension/op_def.rs
rename to hugr-core/src/extension/op_def.rs
diff --git a/hugr/src/extension/prelude.rs b/hugr-core/src/extension/prelude.rs
similarity index 100%
rename from hugr/src/extension/prelude.rs
rename to hugr-core/src/extension/prelude.rs
diff --git a/hugr/src/extension/simple_op.rs b/hugr-core/src/extension/simple_op.rs
similarity index 100%
rename from hugr/src/extension/simple_op.rs
rename to hugr-core/src/extension/simple_op.rs
diff --git a/hugr/src/extension/type_def.rs b/hugr-core/src/extension/type_def.rs
similarity index 100%
rename from hugr/src/extension/type_def.rs
rename to hugr-core/src/extension/type_def.rs
diff --git a/hugr/src/extension/validate.rs b/hugr-core/src/extension/validate.rs
similarity index 100%
rename from hugr/src/extension/validate.rs
rename to hugr-core/src/extension/validate.rs
diff --git a/hugr/src/hugr.rs b/hugr-core/src/hugr.rs
similarity index 100%
rename from hugr/src/hugr.rs
rename to hugr-core/src/hugr.rs
diff --git a/hugr/src/hugr/hugrmut.rs b/hugr-core/src/hugr/hugrmut.rs
similarity index 100%
rename from hugr/src/hugr/hugrmut.rs
rename to hugr-core/src/hugr/hugrmut.rs
diff --git a/hugr/src/hugr/ident.rs b/hugr-core/src/hugr/ident.rs
similarity index 100%
rename from hugr/src/hugr/ident.rs
rename to hugr-core/src/hugr/ident.rs
diff --git a/hugr/src/hugr/rewrite.rs b/hugr-core/src/hugr/rewrite.rs
similarity index 100%
rename from hugr/src/hugr/rewrite.rs
rename to hugr-core/src/hugr/rewrite.rs
diff --git a/hugr/src/hugr/rewrite/consts.rs b/hugr-core/src/hugr/rewrite/consts.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/consts.rs
rename to hugr-core/src/hugr/rewrite/consts.rs
diff --git a/hugr/src/hugr/rewrite/inline_dfg.rs b/hugr-core/src/hugr/rewrite/inline_dfg.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/inline_dfg.rs
rename to hugr-core/src/hugr/rewrite/inline_dfg.rs
diff --git a/hugr/src/hugr/rewrite/insert_identity.rs b/hugr-core/src/hugr/rewrite/insert_identity.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/insert_identity.rs
rename to hugr-core/src/hugr/rewrite/insert_identity.rs
diff --git a/hugr/src/hugr/rewrite/outline_cfg.rs b/hugr-core/src/hugr/rewrite/outline_cfg.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/outline_cfg.rs
rename to hugr-core/src/hugr/rewrite/outline_cfg.rs
diff --git a/hugr/src/hugr/rewrite/replace.rs b/hugr-core/src/hugr/rewrite/replace.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/replace.rs
rename to hugr-core/src/hugr/rewrite/replace.rs
diff --git a/hugr/src/hugr/rewrite/simple_replace.rs b/hugr-core/src/hugr/rewrite/simple_replace.rs
similarity index 100%
rename from hugr/src/hugr/rewrite/simple_replace.rs
rename to hugr-core/src/hugr/rewrite/simple_replace.rs
diff --git a/hugr/src/hugr/serialize.rs b/hugr-core/src/hugr/serialize.rs
similarity index 100%
rename from hugr/src/hugr/serialize.rs
rename to hugr-core/src/hugr/serialize.rs
diff --git a/hugr/src/hugr/serialize/test.rs b/hugr-core/src/hugr/serialize/test.rs
similarity index 100%
rename from hugr/src/hugr/serialize/test.rs
rename to hugr-core/src/hugr/serialize/test.rs
diff --git a/hugr/src/hugr/validate.rs b/hugr-core/src/hugr/validate.rs
similarity index 100%
rename from hugr/src/hugr/validate.rs
rename to hugr-core/src/hugr/validate.rs
diff --git a/hugr/src/hugr/validate/test.rs b/hugr-core/src/hugr/validate/test.rs
similarity index 100%
rename from hugr/src/hugr/validate/test.rs
rename to hugr-core/src/hugr/validate/test.rs
diff --git a/hugr/src/hugr/views.rs b/hugr-core/src/hugr/views.rs
similarity index 100%
rename from hugr/src/hugr/views.rs
rename to hugr-core/src/hugr/views.rs
diff --git a/hugr/src/hugr/views/descendants.rs b/hugr-core/src/hugr/views/descendants.rs
similarity index 100%
rename from hugr/src/hugr/views/descendants.rs
rename to hugr-core/src/hugr/views/descendants.rs
diff --git a/hugr/src/hugr/views/petgraph.rs b/hugr-core/src/hugr/views/petgraph.rs
similarity index 100%
rename from hugr/src/hugr/views/petgraph.rs
rename to hugr-core/src/hugr/views/petgraph.rs
diff --git a/hugr/src/hugr/views/render.rs b/hugr-core/src/hugr/views/render.rs
similarity index 100%
rename from hugr/src/hugr/views/render.rs
rename to hugr-core/src/hugr/views/render.rs
diff --git a/hugr/src/hugr/views/root_checked.rs b/hugr-core/src/hugr/views/root_checked.rs
similarity index 100%
rename from hugr/src/hugr/views/root_checked.rs
rename to hugr-core/src/hugr/views/root_checked.rs
diff --git a/hugr/src/hugr/views/sibling.rs b/hugr-core/src/hugr/views/sibling.rs
similarity index 100%
rename from hugr/src/hugr/views/sibling.rs
rename to hugr-core/src/hugr/views/sibling.rs
diff --git a/hugr/src/hugr/views/sibling_subgraph.rs b/hugr-core/src/hugr/views/sibling_subgraph.rs
similarity index 100%
rename from hugr/src/hugr/views/sibling_subgraph.rs
rename to hugr-core/src/hugr/views/sibling_subgraph.rs
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap
similarity index 98%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap
index ac95341fd..c07f68144 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap
@@ -1,5 +1,5 @@
 ---
-source: hugr/src/hugr/views/tests.rs
+source: hugr-core/src/hugr/views/tests.rs
 expression: h.dot_string()
 ---
 digraph {
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap
similarity index 98%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap
index 49497fac5..a77760fe3 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap
@@ -1,5 +1,5 @@
 ---
-source: hugr/views/tests.rs
+source: hugr-core/views/tests.rs
 expression: h.dot_string()
 ---
 digraph {
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap
similarity index 94%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap
index 61b594731..fe82c83fe 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap
@@ -1,5 +1,5 @@
 ---
-source: hugr/src/hugr/views/tests.rs
+source: hugr-core/src/hugr/views/tests.rs
 expression: h.dot_string()
 ---
 digraph {
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap
similarity index 94%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap
index cb75f44ab..e70c19256 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap
@@ -1,5 +1,5 @@
 ---
-source: hugr/src/hugr/views/tests.rs
+source: hugr-core/src/hugr/views/tests.rs
 expression: h.mermaid_string()
 ---
 graph LR
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap
similarity index 90%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap
index 5e7debf9e..0ab5fcceb 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap
@@ -1,5 +1,5 @@
 ---
-source: src/hugr/views/tests.rs
+source: hugr-core/src/hugr/views/tests.rs
 expression: h.mermaid_string()
 ---
 graph LR
diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap
similarity index 81%
rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap
rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap
index 7f4d2c253..ff4422889 100644
--- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap
+++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap
@@ -1,5 +1,5 @@
 ---
-source: hugr/src/hugr/views/tests.rs
+source: hugr-core/src/hugr/views/tests.rs
 expression: h.mermaid_string()
 ---
 graph LR
diff --git a/hugr/src/hugr/views/tests.rs b/hugr-core/src/hugr/views/tests.rs
similarity index 100%
rename from hugr/src/hugr/views/tests.rs
rename to hugr-core/src/hugr/views/tests.rs
diff --git a/hugr-core/src/lib.rs b/hugr-core/src/lib.rs
new file mode 100644
index 000000000..73bc5c6d5
--- /dev/null
+++ b/hugr-core/src/lib.rs
@@ -0,0 +1,163 @@
+//! Extensible, graph-based program representation with first-class support for linear types.
+//!
+//! The name HUGR stands for "Hierarchical Unified Graph Representation". It is designed primarily
+//! as an intermediate representation and interchange format for quantum and hybrid
+//! classical–quantum programs.
+//!
+//! Both data-flow and control-flow graphs can be represented in the HUGR. Nodes in the graph may
+//! represent basic operations, or may themselves have "child" graphs, which inherit their inputs
+//! and outputs. Special "non-local" edges allow data to pass directly from a node to another node
+//! that is not a direct descendent (subject to causality constraints).
+//!
+//! The specification can be found
+//! [here](https://github.com/CQCL/hugr/blob/main/specification/hugr.md).
+//!
+//! This crate provides a Rust implementation of HUGR and the standard extensions defined in the
+//! specification.
+//!
+//! It includes methods for:
+//!
+//! - building HUGRs from basic operations;
+//! - defining new extensions;
+//! - serializing and deserializing HUGRs;
+//! - performing local rewrites.
+//!
+//! # Example
+//!
+//! To build a HUGR for a simple quantum circuit and then serialize it to a buffer, we can define
+//! a simple quantum extension and then use the [[builder::DFGBuilder]] as follows:
+//! ```
+//! use hugr_core::builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr};
+//! use hugr_core::extension::prelude::{BOOL_T, QB_T};
+//! use hugr_core::hugr::Hugr;
+//! use hugr_core::type_row;
+//! use hugr_core::types::FunctionType;
+//!
+//! // The type of qubits, `QB_T` is in the prelude but, by default, no gateset
+//! // is defined. This module provides Hadamard and CX gates.
+//! mod mini_quantum_extension {
+//!     use hugr_core::{
+//!         extension::{
+//!             prelude::{BOOL_T, QB_T},
+//!             ExtensionId, ExtensionRegistry, PRELUDE,
+//!         },
+//!         ops::{CustomOp, OpName},
+//!         type_row,
+//!         types::{FunctionType, PolyFuncType},
+//!         Extension,
+//!     };
+//!
+//!     use lazy_static::lazy_static;
+//!
+//!     fn one_qb_func() -> PolyFuncType {
+//!         FunctionType::new_endo(type_row![QB_T]).into()
+//!     }
+//!
+//!     fn two_qb_func() -> PolyFuncType {
+//!         FunctionType::new_endo(type_row![QB_T, QB_T]).into()
+//!     }
+//!     /// The extension identifier.
+//!     pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("mini.quantum");
+//!     fn extension() -> Extension {
+//!         let mut extension = Extension::new(EXTENSION_ID);
+//!
+//!         extension
+//!             .add_op(OpName::new_inline("H"), "Hadamard".into(), one_qb_func())
+//!             .unwrap();
+//!
+//!         extension
+//!             .add_op(OpName::new_inline("CX"), "CX".into(), two_qb_func())
+//!             .unwrap();
+//!
+//!         extension
+//!             .add_op(
+//!                 OpName::new_inline("Measure"),
+//!                 "Measure a qubit, returning the qubit and the measurement result.".into(),
+//!                 FunctionType::new(type_row![QB_T], type_row![QB_T, BOOL_T]),
+//!             )
+//!             .unwrap();
+//!
+//!         extension
+//!     }
+//!
+//!     lazy_static! {
+//!         /// Quantum extension definition.
+//!         pub static ref EXTENSION: Extension = extension();
+//!         static ref REG: ExtensionRegistry =
+//!             ExtensionRegistry::try_new([EXTENSION.to_owned(), PRELUDE.to_owned()]).unwrap();
+//!
+//!     }
+//!     fn get_gate(gate_name: impl Into<OpName>) -> CustomOp {
+//!         EXTENSION
+//!             .instantiate_extension_op(&gate_name.into(), [], &REG)
+//!             .unwrap()
+//!             .into()
+//!     }
+//!     pub fn h_gate() -> CustomOp {
+//!         get_gate("H")
+//!     }
+//!
+//!     pub fn cx_gate() -> CustomOp {
+//!         get_gate("CX")
+//!     }
+//!
+//!     pub fn measure() -> CustomOp {
+//!         get_gate("Measure")
+//!     }
+//! }
+//!
+//! use mini_quantum_extension::{cx_gate, h_gate, measure};
+//!
+//! //      ┌───┐
+//! // q_0: ┤ H ├──■─────
+//! //      ├───┤┌─┴─┐┌─┐
+//! // q_1: ┤ H ├┤ X ├┤M├
+//! //      └───┘└───┘└╥┘
+//! // c:              ╚═
+//! fn make_dfg_hugr() -> Result<Hugr, BuildError> {
+//!     let mut dfg_builder = DFGBuilder::new(FunctionType::new(
+//!         type_row![QB_T, QB_T],
+//!         type_row![QB_T, QB_T, BOOL_T],
+//!     ))?;
+//!     let [wire0, wire1] = dfg_builder.input_wires_arr();
+//!     let h0 = dfg_builder.add_dataflow_op(h_gate(), vec![wire0])?;
+//!     let h1 = dfg_builder.add_dataflow_op(h_gate(), vec![wire1])?;
+//!     let cx = dfg_builder.add_dataflow_op(cx_gate(), h0.outputs().chain(h1.outputs()))?;
+//!     let measure = dfg_builder.add_dataflow_op(measure(), cx.outputs().last())?;
+//!     dfg_builder.finish_prelude_hugr_with_outputs(cx.outputs().take(1).chain(measure.outputs()))
+//! }
+//!
+//! let h: Hugr = make_dfg_hugr().unwrap();
+//! let serialized = serde_json::to_string(&h).unwrap();
+//! println!("{}", serialized);
+//! ```
+
+// Unstable check, may cause false positives.
+// https://github.com/rust-lang/rust-clippy/issues/5112
+#![warn(clippy::debug_assert_with_mut_call)]
+// proptest-derive generates many of these warnings.
+// https://github.com/rust-lang/rust/issues/120363
+// https://github.com/proptest-rs/proptest/issues/447
+#![cfg_attr(test, allow(non_local_definitions))]
+
+pub mod builder;
+pub mod core;
+pub mod extension;
+pub mod hugr;
+pub mod macros;
+pub mod ops;
+pub mod std_extensions;
+pub mod types;
+pub mod utils;
+
+pub use crate::core::{
+    CircuitUnit, Direction, IncomingPort, Node, NodeIndex, OutgoingPort, Port, PortIndex, Wire,
+};
+pub use crate::extension::Extension;
+pub use crate::hugr::{Hugr, HugrView, SimpleReplacement};
+
+#[cfg(feature = "cli")]
+pub mod cli;
+
+#[cfg(test)]
+pub mod proptest;
diff --git a/hugr/src/macros.rs b/hugr-core/src/macros.rs
similarity index 95%
rename from hugr/src/macros.rs
rename to hugr-core/src/macros.rs
index e6b511daa..cf948a55c 100644
--- a/hugr/src/macros.rs
+++ b/hugr-core/src/macros.rs
@@ -42,8 +42,8 @@ pub(crate) use impl_box_clone;
 ///
 /// Example:
 /// ```
-/// # use hugr::macros::type_row;
-/// # use hugr::types::{FunctionType, Type, TypeRow};
+/// # use hugr_core::macros::type_row;
+/// # use hugr_core::types::{FunctionType, Type, TypeRow};
 /// const U: Type = Type::UNIT;
 /// let static_row: TypeRow = type_row![U, U];
 /// let dynamic_row: TypeRow = vec![U, U, U].into();
@@ -86,7 +86,7 @@ pub use type_row;
 /// of a test module only. Example:
 /// ```rust
 /// # mod test {
-/// # use hugr::macros::const_extension_ids;
+/// # use hugr_core::macros::const_extension_ids;
 /// const_extension_ids! {
 ///   pub const EXT_A: ExtensionId = "A";
 ///   /// A doc comment
diff --git a/hugr/src/ops.rs b/hugr-core/src/ops.rs
similarity index 100%
rename from hugr/src/ops.rs
rename to hugr-core/src/ops.rs
diff --git a/hugr/src/ops/constant.rs b/hugr-core/src/ops/constant.rs
similarity index 99%
rename from hugr/src/ops/constant.rs
rename to hugr-core/src/ops/constant.rs
index 7e3a1ac37..3e8d0acca 100644
--- a/hugr/src/ops/constant.rs
+++ b/hugr-core/src/ops/constant.rs
@@ -160,7 +160,7 @@ pub enum Value {
 #[cfg_attr(not(miri), doc = "```")] // this doctest depends on typetag, so fails with miri
 #[cfg_attr(miri, doc = "```ignore")]
 /// use serde::{Serialize,Deserialize};
-/// use hugr::{
+/// use hugr_core::{
 ///   types::Type,ops::constant::{OpaqueValue, ValueName, CustomConst, CustomSerialized},
 ///   extension::{ExtensionSet, prelude::{USIZE_T, ConstUsize}},
 ///   std_extensions::arithmetic::int_types};
diff --git a/hugr/src/ops/constant/custom.rs b/hugr-core/src/ops/constant/custom.rs
similarity index 99%
rename from hugr/src/ops/constant/custom.rs
rename to hugr-core/src/ops/constant/custom.rs
index 54a9af514..25a3690dd 100644
--- a/hugr/src/ops/constant/custom.rs
+++ b/hugr-core/src/ops/constant/custom.rs
@@ -32,7 +32,7 @@ use super::ValueName;
 #[cfg_attr(not(miri), doc = "```")] // this doctest depends on typetag, so fails with miri
 #[cfg_attr(miri, doc = "```ignore")]
 /// use serde::{Serialize,Deserialize};
-/// use hugr::{
+/// use hugr_core::{
 ///   types::Type,ops::constant::{OpaqueValue, ValueName, CustomConst},
 ///   extension::ExtensionSet, std_extensions::arithmetic::int_types};
 /// use serde_json::json;
diff --git a/hugr/src/ops/controlflow.rs b/hugr-core/src/ops/controlflow.rs
similarity index 100%
rename from hugr/src/ops/controlflow.rs
rename to hugr-core/src/ops/controlflow.rs
diff --git a/hugr/src/ops/custom.rs b/hugr-core/src/ops/custom.rs
similarity index 100%
rename from hugr/src/ops/custom.rs
rename to hugr-core/src/ops/custom.rs
diff --git a/hugr/src/ops/dataflow.rs b/hugr-core/src/ops/dataflow.rs
similarity index 97%
rename from hugr/src/ops/dataflow.rs
rename to hugr-core/src/ops/dataflow.rs
index 54202ffc0..76eccbd79 100644
--- a/hugr/src/ops/dataflow.rs
+++ b/hugr-core/src/ops/dataflow.rs
@@ -210,11 +210,11 @@ impl Call {
     /// This matches [`OpType::static_input_port`].
     ///
     /// ```
-    /// # use hugr::ops::dataflow::Call;
-    /// # use hugr::ops::OpType;
-    /// # use hugr::types::FunctionType;
-    /// # use hugr::extension::prelude::QB_T;
-    /// # use hugr::extension::PRELUDE_REGISTRY;
+    /// # use hugr_core::ops::dataflow::Call;
+    /// # use hugr_core::ops::OpType;
+    /// # use hugr_core::types::FunctionType;
+    /// # use hugr_core::extension::prelude::QB_T;
+    /// # use hugr_core::extension::PRELUDE_REGISTRY;
     /// let signature = FunctionType::new(vec![QB_T, QB_T], vec![QB_T, QB_T]);
     /// let call = Call::try_new(signature.into(), &[], &PRELUDE_REGISTRY).unwrap();
     /// let op = OpType::Call(call.clone());
@@ -308,9 +308,9 @@ impl LoadConstant {
     /// This matches [`OpType::static_input_port`].
     ///
     /// ```
-    /// # use hugr::ops::dataflow::LoadConstant;
-    /// # use hugr::ops::OpType;
-    /// # use hugr::types::Type;
+    /// # use hugr_core::ops::dataflow::LoadConstant;
+    /// # use hugr_core::ops::OpType;
+    /// # use hugr_core::types::Type;
     /// let datatype = Type::UNIT;
     /// let load_constant = LoadConstant { datatype };
     /// let op = OpType::LoadConstant(load_constant.clone());
diff --git a/hugr/src/ops/handle.rs b/hugr-core/src/ops/handle.rs
similarity index 100%
rename from hugr/src/ops/handle.rs
rename to hugr-core/src/ops/handle.rs
diff --git a/hugr/src/ops/leaf.rs b/hugr-core/src/ops/leaf.rs
similarity index 100%
rename from hugr/src/ops/leaf.rs
rename to hugr-core/src/ops/leaf.rs
diff --git a/hugr/src/ops/module.rs b/hugr-core/src/ops/module.rs
similarity index 100%
rename from hugr/src/ops/module.rs
rename to hugr-core/src/ops/module.rs
diff --git a/hugr/src/ops/tag.rs b/hugr-core/src/ops/tag.rs
similarity index 100%
rename from hugr/src/ops/tag.rs
rename to hugr-core/src/ops/tag.rs
diff --git a/hugr/src/ops/validate.rs b/hugr-core/src/ops/validate.rs
similarity index 100%
rename from hugr/src/ops/validate.rs
rename to hugr-core/src/ops/validate.rs
diff --git a/hugr/src/proptest.rs b/hugr-core/src/proptest.rs
similarity index 100%
rename from hugr/src/proptest.rs
rename to hugr-core/src/proptest.rs
diff --git a/hugr/src/std_extensions.rs b/hugr-core/src/std_extensions.rs
similarity index 100%
rename from hugr/src/std_extensions.rs
rename to hugr-core/src/std_extensions.rs
diff --git a/hugr/src/std_extensions/arithmetic/conversions.rs b/hugr-core/src/std_extensions/arithmetic/conversions.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/conversions.rs
rename to hugr-core/src/std_extensions/arithmetic/conversions.rs
diff --git a/hugr/src/std_extensions/arithmetic/conversions/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/conversions/const_fold.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/conversions/const_fold.rs
rename to hugr-core/src/std_extensions/arithmetic/conversions/const_fold.rs
diff --git a/hugr/src/std_extensions/arithmetic/float_ops.rs b/hugr-core/src/std_extensions/arithmetic/float_ops.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/float_ops.rs
rename to hugr-core/src/std_extensions/arithmetic/float_ops.rs
diff --git a/hugr/src/std_extensions/arithmetic/float_ops/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/float_ops/const_fold.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/float_ops/const_fold.rs
rename to hugr-core/src/std_extensions/arithmetic/float_ops/const_fold.rs
diff --git a/hugr/src/std_extensions/arithmetic/float_types.rs b/hugr-core/src/std_extensions/arithmetic/float_types.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/float_types.rs
rename to hugr-core/src/std_extensions/arithmetic/float_types.rs
diff --git a/hugr/src/std_extensions/arithmetic/int_ops.rs b/hugr-core/src/std_extensions/arithmetic/int_ops.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/int_ops.rs
rename to hugr-core/src/std_extensions/arithmetic/int_ops.rs
diff --git a/hugr/src/std_extensions/arithmetic/int_ops/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/int_ops/const_fold.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/int_ops/const_fold.rs
rename to hugr-core/src/std_extensions/arithmetic/int_ops/const_fold.rs
diff --git a/hugr/src/std_extensions/arithmetic/int_types.rs b/hugr-core/src/std_extensions/arithmetic/int_types.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/int_types.rs
rename to hugr-core/src/std_extensions/arithmetic/int_types.rs
diff --git a/hugr/src/std_extensions/arithmetic/mod.rs b/hugr-core/src/std_extensions/arithmetic/mod.rs
similarity index 100%
rename from hugr/src/std_extensions/arithmetic/mod.rs
rename to hugr-core/src/std_extensions/arithmetic/mod.rs
diff --git a/hugr/src/std_extensions/collections.rs b/hugr-core/src/std_extensions/collections.rs
similarity index 100%
rename from hugr/src/std_extensions/collections.rs
rename to hugr-core/src/std_extensions/collections.rs
diff --git a/hugr/src/std_extensions/logic.rs b/hugr-core/src/std_extensions/logic.rs
similarity index 100%
rename from hugr/src/std_extensions/logic.rs
rename to hugr-core/src/std_extensions/logic.rs
diff --git a/hugr/src/types.rs b/hugr-core/src/types.rs
similarity index 99%
rename from hugr/src/types.rs
rename to hugr-core/src/types.rs
index cb8cd0706..081caf46f 100644
--- a/hugr/src/types.rs
+++ b/hugr-core/src/types.rs
@@ -260,15 +260,15 @@ impl TypeEnum {
 ///
 /// Examples:
 /// ```
-/// # use hugr::types::{Type, TypeBound};
-/// # use hugr::type_row;
+/// # use hugr_core::types::{Type, TypeBound};
+/// # use hugr_core::type_row;
 ///
 /// let sum = Type::new_sum([type_row![], type_row![]]);
 /// assert_eq!(sum.least_upper_bound(), TypeBound::Eq);
 /// ```
 ///
 /// ```
-/// # use hugr::types::{Type, TypeBound, FunctionType};
+/// # use hugr_core::types::{Type, TypeBound, FunctionType};
 ///
 /// let func_type = Type::new_function(FunctionType::new_endo(vec![]));
 /// assert_eq!(func_type.least_upper_bound(), TypeBound::Copyable);
diff --git a/hugr/src/types/check.rs b/hugr-core/src/types/check.rs
similarity index 100%
rename from hugr/src/types/check.rs
rename to hugr-core/src/types/check.rs
diff --git a/hugr/src/types/custom.rs b/hugr-core/src/types/custom.rs
similarity index 100%
rename from hugr/src/types/custom.rs
rename to hugr-core/src/types/custom.rs
diff --git a/hugr/src/types/poly_func.rs b/hugr-core/src/types/poly_func.rs
similarity index 100%
rename from hugr/src/types/poly_func.rs
rename to hugr-core/src/types/poly_func.rs
diff --git a/hugr/src/types/serialize.rs b/hugr-core/src/types/serialize.rs
similarity index 100%
rename from hugr/src/types/serialize.rs
rename to hugr-core/src/types/serialize.rs
diff --git a/hugr/src/types/signature.rs b/hugr-core/src/types/signature.rs
similarity index 100%
rename from hugr/src/types/signature.rs
rename to hugr-core/src/types/signature.rs
diff --git a/hugr/src/types/type_param.rs b/hugr-core/src/types/type_param.rs
similarity index 100%
rename from hugr/src/types/type_param.rs
rename to hugr-core/src/types/type_param.rs
diff --git a/hugr/src/types/type_row.rs b/hugr-core/src/types/type_row.rs
similarity index 100%
rename from hugr/src/types/type_row.rs
rename to hugr-core/src/types/type_row.rs
diff --git a/hugr/src/utils.rs b/hugr-core/src/utils.rs
similarity index 100%
rename from hugr/src/utils.rs
rename to hugr-core/src/utils.rs
diff --git a/hugr-passes/Cargo.toml b/hugr-passes/Cargo.toml
index 688d32e48..4a1bdc680 100644
--- a/hugr-passes/Cargo.toml
+++ b/hugr-passes/Cargo.toml
@@ -13,14 +13,14 @@ keywords = ["Quantum", "Quantinuum"]
 categories = ["compilers"]
 
 [dependencies]
-hugr = { path = "../hugr", version = "0.4.0" }
+hugr-core = { path = "../hugr-core", version = "0.0.0" }
 itertools = { workspace = true }
 lazy_static = { workspace = true }
 paste = { workspace = true }
 thiserror = { workspace = true }
 
 [features]
-extension_inference = ["hugr/extension_inference"]
+extension_inference = ["hugr-core/extension_inference"]
 
 [dev-dependencies]
 rstest = "0.19.0"
diff --git a/hugr-passes/src/const_fold.rs b/hugr-passes/src/const_fold.rs
index 4a124c1a4..bead78c50 100644
--- a/hugr-passes/src/const_fold.rs
+++ b/hugr-passes/src/const_fold.rs
@@ -5,10 +5,10 @@ use std::collections::{BTreeSet, HashMap};
 use itertools::Itertools;
 use thiserror::Error;
 
-use hugr::hugr::{SimpleReplacementError, ValidationError};
-use hugr::types::SumType;
-use hugr::Direction;
-use hugr::{
+use hugr_core::hugr::{SimpleReplacementError, ValidationError};
+use hugr_core::types::SumType;
+use hugr_core::Direction;
+use hugr_core::{
     builder::{DFGBuilder, Dataflow, DataflowHugr},
     extension::{ConstFoldResult, ExtensionRegistry},
     hugr::{
diff --git a/hugr-passes/src/const_fold/test.rs b/hugr-passes/src/const_fold/test.rs
index 07b881bc7..3f5eb2ba4 100644
--- a/hugr-passes/src/const_fold/test.rs
+++ b/hugr-passes/src/const_fold/test.rs
@@ -1,25 +1,25 @@
 use crate::const_fold::constant_fold_pass;
-use hugr::builder::{DFGBuilder, Dataflow, DataflowHugr};
-use hugr::extension::prelude::{sum_with_error, ConstError, ConstString, BOOL_T, STRING_TYPE};
-use hugr::extension::{ExtensionRegistry, PRELUDE};
-use hugr::ops::Value;
-use hugr::std_extensions::arithmetic;
-use hugr::std_extensions::arithmetic::int_ops::IntOpDef;
-use hugr::std_extensions::arithmetic::int_types::{ConstInt, INT_TYPES};
-use hugr::std_extensions::logic::{self, NaryLogic, NotOp};
-use hugr::type_row;
-use hugr::types::{FunctionType, Type, TypeRow};
+use hugr_core::builder::{DFGBuilder, Dataflow, DataflowHugr};
+use hugr_core::extension::prelude::{sum_with_error, ConstError, ConstString, BOOL_T, STRING_TYPE};
+use hugr_core::extension::{ExtensionRegistry, PRELUDE};
+use hugr_core::ops::Value;
+use hugr_core::std_extensions::arithmetic;
+use hugr_core::std_extensions::arithmetic::int_ops::IntOpDef;
+use hugr_core::std_extensions::arithmetic::int_types::{ConstInt, INT_TYPES};
+use hugr_core::std_extensions::logic::{self, NaryLogic, NotOp};
+use hugr_core::type_row;
+use hugr_core::types::{FunctionType, Type, TypeRow};
 
 use rstest::rstest;
 
 use lazy_static::lazy_static;
 
 use super::*;
-use hugr::builder::Container;
-use hugr::ops::{OpType, UnpackTuple};
-use hugr::std_extensions::arithmetic::conversions::ConvertOpDef;
-use hugr::std_extensions::arithmetic::float_ops::FloatOps;
-use hugr::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE};
+use hugr_core::builder::Container;
+use hugr_core::ops::{OpType, UnpackTuple};
+use hugr_core::std_extensions::arithmetic::conversions::ConvertOpDef;
+use hugr_core::std_extensions::arithmetic::float_ops::FloatOps;
+use hugr_core::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE};
 
 /// Check that a hugr just loads and returns a single expected constant.
 pub fn assert_fully_folded(h: &Hugr, expected_value: &Value) {
@@ -127,7 +127,7 @@ fn test_big() {
     ignore = "inference fails for test graph, it shouldn't"
 )]
 fn test_list_ops() -> Result<(), Box<dyn std::error::Error>> {
-    use hugr::std_extensions::collections::{self, ListOp, ListValue};
+    use hugr_core::std_extensions::collections::{self, ListOp, ListValue};
 
     let reg = ExtensionRegistry::try_new([
         PRELUDE.to_owned(),
@@ -230,8 +230,8 @@ fn orphan_output() {
     //
     // We arange things so that the `or` folds away first, leaving the not
     // with no outputs.
-    use hugr::hugr::NodeType;
-    use hugr::ops::handle::NodeHandle;
+    use hugr_core::hugr::NodeType;
+    use hugr_core::ops::handle::NodeHandle;
 
     let mut build = DFGBuilder::new(FunctionType::new(type_row![], vec![BOOL_T])).unwrap();
     let true_wire = build.add_load_value(Value::true_val());
diff --git a/hugr-passes/src/half_node.rs b/hugr-passes/src/half_node.rs
index cb9c6e55e..4bacac548 100644
--- a/hugr-passes/src/half_node.rs
+++ b/hugr-passes/src/half_node.rs
@@ -2,12 +2,12 @@ use std::hash::Hash;
 
 use super::nest_cfgs::CfgNodeMap;
 
-use hugr::hugr::RootTagged;
+use hugr_core::hugr::RootTagged;
 
-use hugr::ops::handle::CfgID;
-use hugr::ops::{OpTag, OpTrait};
+use hugr_core::ops::handle::CfgID;
+use hugr_core::ops::{OpTag, OpTrait};
 
-use hugr::{Direction, Node};
+use hugr_core::{Direction, Node};
 
 /// We provide a view of a cfg where every node has at most one of
 /// (multiple predecessors, multiple successors).
@@ -97,9 +97,9 @@ impl<H: RootTagged<RootHandle = CfgID>> CfgNodeMap<HalfNode> for HalfNodeView<H>
 mod test {
     use super::super::nest_cfgs::{test::*, EdgeClassifier};
     use super::{HalfNode, HalfNodeView};
-    use hugr::builder::BuildError;
-    use hugr::hugr::views::RootChecked;
-    use hugr::ops::handle::NodeHandle;
+    use hugr_core::builder::BuildError;
+    use hugr_core::hugr::views::RootChecked;
+    use hugr_core::ops::handle::NodeHandle;
 
     use itertools::Itertools;
     use std::collections::HashSet;
diff --git a/hugr-passes/src/merge_bbs.rs b/hugr-passes/src/merge_bbs.rs
index 17adc4e57..7d1cf9d52 100644
--- a/hugr-passes/src/merge_bbs.rs
+++ b/hugr-passes/src/merge_bbs.rs
@@ -2,16 +2,16 @@
 //! and the target BB has no other predecessors.
 use std::collections::HashMap;
 
-use hugr::hugr::hugrmut::HugrMut;
+use hugr_core::hugr::hugrmut::HugrMut;
 use itertools::Itertools;
 
-use hugr::hugr::rewrite::inline_dfg::InlineDFG;
-use hugr::hugr::rewrite::replace::{NewEdgeKind, NewEdgeSpec, Replacement};
-use hugr::hugr::RootTagged;
-use hugr::ops::handle::CfgID;
-use hugr::ops::leaf::UnpackTuple;
-use hugr::ops::{DataflowBlock, DataflowParent, Input, Output, DFG};
-use hugr::{Hugr, HugrView, Node};
+use hugr_core::hugr::rewrite::inline_dfg::InlineDFG;
+use hugr_core::hugr::rewrite::replace::{NewEdgeKind, NewEdgeSpec, Replacement};
+use hugr_core::hugr::RootTagged;
+use hugr_core::ops::handle::CfgID;
+use hugr_core::ops::leaf::UnpackTuple;
+use hugr_core::ops::{DataflowBlock, DataflowParent, Input, Output, DFG};
+use hugr_core::{Hugr, HugrView, Node};
 
 /// Merge any basic blocks that are direct children of the specified CFG
 /// i.e. where a basic block B has a single successor B' whose only predecessor
@@ -161,15 +161,15 @@ mod test {
     use itertools::Itertools;
     use rstest::rstest;
 
-    use hugr::builder::{CFGBuilder, DFGWrapper, Dataflow, HugrBuilder};
-    use hugr::extension::prelude::{ConstUsize, PRELUDE_ID, QB_T, USIZE_T};
-    use hugr::extension::{ExtensionRegistry, ExtensionSet, PRELUDE, PRELUDE_REGISTRY};
-    use hugr::hugr::views::sibling::SiblingMut;
-    use hugr::ops::constant::Value;
-    use hugr::ops::handle::CfgID;
-    use hugr::ops::{Lift, LoadConstant, Noop, OpTrait, OpType};
-    use hugr::types::{FunctionType, Type, TypeRow};
-    use hugr::{const_extension_ids, type_row, Extension, Hugr, HugrView, Wire};
+    use hugr_core::builder::{CFGBuilder, DFGWrapper, Dataflow, HugrBuilder};
+    use hugr_core::extension::prelude::{ConstUsize, PRELUDE_ID, QB_T, USIZE_T};
+    use hugr_core::extension::{ExtensionRegistry, ExtensionSet, PRELUDE, PRELUDE_REGISTRY};
+    use hugr_core::hugr::views::sibling::SiblingMut;
+    use hugr_core::ops::constant::Value;
+    use hugr_core::ops::handle::CfgID;
+    use hugr_core::ops::{Lift, LoadConstant, Noop, OpTrait, OpType};
+    use hugr_core::types::{FunctionType, Type, TypeRow};
+    use hugr_core::{const_extension_ids, type_row, Extension, Hugr, HugrView, Wire};
 
     use super::merge_basic_blocks;
 
diff --git a/hugr-passes/src/nest_cfgs.rs b/hugr-passes/src/nest_cfgs.rs
index 4231e2583..8753464d0 100644
--- a/hugr-passes/src/nest_cfgs.rs
+++ b/hugr-passes/src/nest_cfgs.rs
@@ -44,14 +44,14 @@ use std::hash::Hash;
 use itertools::Itertools;
 use thiserror::Error;
 
-use hugr::hugr::rewrite::outline_cfg::OutlineCfg;
-use hugr::hugr::views::sibling::SiblingMut;
-use hugr::hugr::views::{HierarchyView, HugrView, SiblingGraph};
-use hugr::hugr::{hugrmut::HugrMut, Rewrite, RootTagged};
-use hugr::ops::handle::{BasicBlockID, CfgID};
-use hugr::ops::OpTag;
-use hugr::ops::OpTrait;
-use hugr::{Direction, Hugr, Node};
+use hugr_core::hugr::rewrite::outline_cfg::OutlineCfg;
+use hugr_core::hugr::views::sibling::SiblingMut;
+use hugr_core::hugr::views::{HierarchyView, HugrView, SiblingGraph};
+use hugr_core::hugr::{hugrmut::HugrMut, Rewrite, RootTagged};
+use hugr_core::ops::handle::{BasicBlockID, CfgID};
+use hugr_core::ops::OpTag;
+use hugr_core::ops::OpTrait;
+use hugr_core::{Direction, Hugr, Node};
 
 /// A "view" of a CFG in a Hugr which allows basic blocks in the underlying CFG to be split into
 /// multiple blocks in the view (or merged together).
@@ -574,17 +574,19 @@ impl<T: Copy + Clone + PartialEq + Eq + Hash> EdgeClassifier<T> {
 #[cfg(test)]
 pub(crate) mod test {
     use super::*;
-    use hugr::builder::{BuildError, CFGBuilder, Container, DataflowSubContainer, HugrBuilder};
-    use hugr::extension::PRELUDE_REGISTRY;
-    use hugr::extension::{prelude::USIZE_T, ExtensionSet};
-
-    use hugr::hugr::rewrite::insert_identity::{IdentityInsertion, IdentityInsertionError};
-    use hugr::hugr::views::RootChecked;
-    use hugr::ops::handle::{ConstID, NodeHandle};
-    use hugr::ops::Value;
-    use hugr::type_row;
-    use hugr::types::{EdgeKind, FunctionType, Type};
-    use hugr::utils::depth;
+    use hugr_core::builder::{
+        BuildError, CFGBuilder, Container, DataflowSubContainer, HugrBuilder,
+    };
+    use hugr_core::extension::PRELUDE_REGISTRY;
+    use hugr_core::extension::{prelude::USIZE_T, ExtensionSet};
+
+    use hugr_core::hugr::rewrite::insert_identity::{IdentityInsertion, IdentityInsertionError};
+    use hugr_core::hugr::views::RootChecked;
+    use hugr_core::ops::handle::{ConstID, NodeHandle};
+    use hugr_core::ops::Value;
+    use hugr_core::type_row;
+    use hugr_core::types::{EdgeKind, FunctionType, Type};
+    use hugr_core::utils::depth;
     const NAT: Type = USIZE_T;
 
     pub fn group_by<E: Eq + Hash + Ord, V: Eq + Hash>(h: HashMap<E, V>) -> HashSet<Vec<E>> {
diff --git a/hugr/Cargo.toml b/hugr/Cargo.toml
index 4993a8cd7..59d468014 100644
--- a/hugr/Cargo.toml
+++ b/hugr/Cargo.toml
@@ -23,50 +23,24 @@ path = "src/lib.rs"
 
 [features]
 extension_inference = []
-cli = ["dep:clap", "dep:clap-stdin"]
+
+# Definitions used by the `hugr` binary
+_cli = ["hugr-core/cli", "dep:clap"]
 
 [dependencies]
-portgraph = { workspace = true, features = ["serde", "petgraph"] }
-thiserror = { workspace = true }
-regex = { workspace = true }
-cgmath = { workspace = true, features = ["serde"] }
-num-rational = { workspace = true, features = ["serde"] }
-downcast-rs = { workspace = true }
-# Rc used here for Extension, but unfortunately we must turn the feature on globally
-serde = { workspace = true, features = ["derive", "rc"] }
-serde_yaml = { workspace = true }
-typetag = { workspace = true }
-smol_str = { workspace = true, features = ["serde"] }
-derive_more = { workspace = true }
-itertools = { workspace = true }
-html-escape = { workspace = true }
-bitvec = { workspace = true, features = ["serde"] }
-enum_dispatch = { workspace = true }
-lazy_static = { workspace = true }
-petgraph = { workspace = true }
-context-iterators = { workspace = true }
-serde_json = { workspace = true }
-delegate = { workspace = true }
-paste = { workspace = true }
-strum = { workspace = true }
-strum_macros = { workspace = true }
+hugr-core = { path = "../hugr-core", version = "0.0.0" }
+hugr-passes = { path = "../hugr-passes", version = "0.1.0" }
+
 clap = { workspace = true, features = ["derive"], optional = true }
-clap-stdin = { workspace = true, optional = true }
 
 [dev-dependencies]
-criterion = { workspace = true, features = ["html_reports"] }
 rstest = { workspace = true }
-webbrowser = { workspace = true }
-urlencoding = { workspace = true }
-cool_asserts = { workspace = true }
-insta = { workspace = true, features = ["yaml"] }
-jsonschema = { workspace = true }
-proptest = { workspace = true }
-proptest-derive = { workspace = true }
-regex-syntax = { workspace = true }
 assert_cmd = { workspace = true }
 predicates = { workspace = true }
 assert_fs = { workspace = true }
+lazy_static = { workspace = true }
+criterion = { workspace = true, features = ["html_reports"] }
+serde_json = { workspace = true }
 
 [[bench]]
 name = "bench_main"
@@ -75,4 +49,4 @@ harness = false
 
 [[bin]]
 name = "hugr"
-required-features = ["cli"]
+required-features = ["_cli"]
diff --git a/hugr/src/lib.rs b/hugr/src/lib.rs
index c093ba2aa..ce41427cf 100644
--- a/hugr/src/lib.rs
+++ b/hugr/src/lib.rs
@@ -140,24 +140,15 @@
 // https://github.com/proptest-rs/proptest/issues/447
 #![cfg_attr(test, allow(non_local_definitions))]
 
-pub mod builder;
-pub mod core;
-pub mod extension;
-pub mod hugr;
-pub mod macros;
-pub mod ops;
-pub mod std_extensions;
-pub mod types;
-pub mod utils;
+// These modules are re-exported as-is. If more control is needed, define a new module in this crate with the desired exports.
+pub use hugr_core::{builder, core, extension, hugr, ops, std_extensions, types, utils};
+pub use hugr_passes as algorithms;
 
-pub use crate::core::{
+// Top-level re-exports for convenience.
+pub use hugr_core::core::{
     CircuitUnit, Direction, IncomingPort, Node, NodeIndex, OutgoingPort, Port, PortIndex, Wire,
 };
-pub use crate::extension::Extension;
-pub use crate::hugr::{Hugr, HugrView, SimpleReplacement};
+pub use hugr_core::extension::Extension;
+pub use hugr_core::hugr::{Hugr, HugrView, SimpleReplacement};
 
-#[cfg(feature = "cli")]
-pub mod cli;
-
-#[cfg(test)]
-pub mod proptest;
+pub use hugr_core::macros::{const_extension_ids, type_row};
diff --git a/hugr/src/main.rs b/hugr/src/main.rs
index 7055446fa..4c2e163ac 100644
--- a/hugr/src/main.rs
+++ b/hugr/src/main.rs
@@ -10,7 +10,7 @@ use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;
 use hugr::extension::{ExtensionRegistry, PRELUDE};
 
 use clap::Parser;
-use hugr::cli::CmdLineArgs;
+use hugr_core::cli::CmdLineArgs;
 
 fn main() {
     let opts = CmdLineArgs::parse();
diff --git a/hugr/tests/cli.rs b/hugr/tests/cli.rs
index 601762081..b447de71e 100644
--- a/hugr/tests/cli.rs
+++ b/hugr/tests/cli.rs
@@ -1,6 +1,7 @@
 #![cfg(feature = "cli")]
 use assert_cmd::Command;
 use assert_fs::{fixture::FileWriteStr, NamedTempFile};
+use hugr::builder::DFGBuilder;
 use hugr::{
     builder::{Container, Dataflow, DataflowHugr},
     extension::prelude::{BOOL_T, QB_T},
@@ -8,14 +9,13 @@ use hugr::{
     types::FunctionType,
     Hugr,
 };
+use hugr_core::cli::VALID_PRINT;
 use predicates::{prelude::*, str::contains};
 use rstest::{fixture, rstest};
 
-use hugr::builder::DFGBuilder;
-use hugr::cli::VALID_PRINT;
 #[fixture]
 fn cmd() -> Command {
-    Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
+    Command::cargo_bin("hugr").unwrap()
 }
 
 #[fixture]

From 0d58e563bdc159377c54ee722f9f23c5b3b96768 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Fri, 24 May 2024 14:12:27 +0100
Subject: [PATCH 2/9] Configure CI/metadata for the new package

---
 .github/CODEOWNERS         |  4 +---
 .github/change-filters.yml |  2 +-
 hugr-core/README.md        |  2 ++
 release-plz.toml           | 22 +++++++++++++---------
 4 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 9ce5c2067..e75b144d6 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -8,6 +8,4 @@
 
 # The release PRs that trigger publication to crates.io or PyPI always modify the changelog.
 # We require those PRs to be approved by someone with release permissions.
-hugr/CHANGELOG.md @aborgna-q @cqc-alec @ss2165
-hugr-passes/CHANGELOG.md @aborgna-q @cqc-alec @ss2165
-hugr-py/CHANGELOG.md @aborgna-q @cqc-alec @ss2165
+**/CHANGELOG.md @aborgna-q @cqc-alec @ss2165
diff --git a/.github/change-filters.yml b/.github/change-filters.yml
index ebf6b45e7..d3e901aa9 100644
--- a/.github/change-filters.yml
+++ b/.github/change-filters.yml
@@ -3,7 +3,7 @@
 
 rust:
   - "hugr/**"
-  - "hugr-passes/**"
+  - "hugr-*/**"
   - "Cargo.toml"
   - "specification/schema/**"
 
diff --git a/hugr-core/README.md b/hugr-core/README.md
index 11479c106..1303f82a8 100644
--- a/hugr-core/README.md
+++ b/hugr-core/README.md
@@ -8,6 +8,8 @@ hugr-core
 [![msrv][]](https://github.com/CQCL/hugr)
 [![codecov][]](https://codecov.io/gh/CQCL/hugr)
 
+Internal core definitions for the `hugr` package.
+
 The Hierarchical Unified Graph Representation (HUGR, pronounced _hugger_) is the
 common representation of quantum circuits and operations in the Quantinuum
 ecosystem.
diff --git a/release-plz.toml b/release-plz.toml
index 549cd7637..d67ae9122 100644
--- a/release-plz.toml
+++ b/release-plz.toml
@@ -1,32 +1,36 @@
 # Automatic changelog generation for rust projects
 
 [workspace]
+# Disable processing the packages by default
+release = false
+
 # Open the release PR as a draft
 pr_draft = true
 
 # Use a custom git-cliff configuration
 changelog_config = "cliff.toml"
 
-# Disable the changelog generation by default
-changelog_update = false
-
 # Enforce adding the project name in the git tag, to avoid collisions with python.
 # (This would normally only be enabled once there are multiple packages in the workspace)
 git_tag_name = "{{ package }}-v{{ version }}"
-
 git_release_name = "{{ package }}: v{{ version }}"
 
 [[package]]
 name = "hugr"
+release = true
+
+[[package]]
+name = "hugr-core"
+release = true
 
-# Enable the changelog for this package
-changelog_update = true
+# Disabled until the first version is manually published
+publish = false
+github_release = false
 
 [[package]]
 name = "hugr-passes"
-
-# Enable the changelog for this package
-changelog_update = true
+release = true
 
 # Disabled until the first version is manually published
 publish = false
+github_release = false

From 5dec197f0370aec5b734e1d6693d9db6cfa46947 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 10:59:24 +0100
Subject: [PATCH 3/9] Simplify README, with less text to go stale

---
 hugr-core/README.md | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/hugr-core/README.md b/hugr-core/README.md
index 1303f82a8..2b45f92ec 100644
--- a/hugr-core/README.md
+++ b/hugr-core/README.md
@@ -9,23 +9,7 @@ hugr-core
 [![codecov][]](https://codecov.io/gh/CQCL/hugr)
 
 Internal core definitions for the `hugr` package.
-
-The Hierarchical Unified Graph Representation (HUGR, pronounced _hugger_) is the
-common representation of quantum circuits and operations in the Quantinuum
-ecosystem.
-
-It provides a high-fidelity representation of operations, that facilitates
-compilation and encodes runnable programs.
-
-The HUGR specification is [here](https://github.com/CQCL/hugr/blob/main/specification/hugr.md).
-
-## Usage
-
-Add the dependency to your project:
-
-```bash
-cargo add hugr-core
-```
+Refer to the [main crate](http://crates.io/crates/hugr) for more information.
 
 Please read the [API documentation here][].
 

From b2ef1497c7f974bea5037941994c0dd50f552059 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 11:17:25 +0100
Subject: [PATCH 4/9] Cleanup main crate docs

---
 hugr/src/lib.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hugr/src/lib.rs b/hugr/src/lib.rs
index ce41427cf..f578d1324 100644
--- a/hugr/src/lib.rs
+++ b/hugr/src/lib.rs
@@ -141,7 +141,9 @@
 #![cfg_attr(test, allow(non_local_definitions))]
 
 // These modules are re-exported as-is. If more control is needed, define a new module in this crate with the desired exports.
+// The doc inline directive is necessary for renamed modules to appear as if they were defined in this crate.
 pub use hugr_core::{builder, core, extension, hugr, ops, std_extensions, types, utils};
+#[doc(inline)]
 pub use hugr_passes as algorithms;
 
 // Top-level re-exports for convenience.
@@ -151,4 +153,5 @@ pub use hugr_core::core::{
 pub use hugr_core::extension::Extension;
 pub use hugr_core::hugr::{Hugr, HugrView, SimpleReplacement};
 
+// Re-export macros.
 pub use hugr_core::macros::{const_extension_ids, type_row};

From 0f23521f212afe234506f9750f3eabf0ef7b4f45 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 11:17:54 +0100
Subject: [PATCH 5/9] Use main crate in doc examples

---
 hugr-core/Cargo.toml                 | 3 +++
 hugr-core/src/builder/cfg.rs         | 2 +-
 hugr-core/src/ops/constant.rs        | 2 +-
 hugr-core/src/ops/constant/custom.rs | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hugr-core/Cargo.toml b/hugr-core/Cargo.toml
index f32dd58ec..5894ef984 100644
--- a/hugr-core/Cargo.toml
+++ b/hugr-core/Cargo.toml
@@ -61,3 +61,6 @@ regex-syntax = { workspace = true }
 assert_cmd = { workspace = true }
 predicates = { workspace = true }
 assert_fs = { workspace = true }
+
+# Required for documentation examples
+hugr = { path = "../hugr" }
diff --git a/hugr-core/src/builder/cfg.rs b/hugr-core/src/builder/cfg.rs
index 9280917ae..1ac852b45 100644
--- a/hugr-core/src/builder/cfg.rs
+++ b/hugr-core/src/builder/cfg.rs
@@ -45,7 +45,7 @@ use crate::{
 ///            |    Exit    |
 ///            +------------+
 /// */
-/// use hugr_core::{
+/// use hugr::{
 ///     builder::{BuildError, CFGBuilder, Container, Dataflow, HugrBuilder},
 ///     extension::{prelude, ExtensionSet},
 ///     ops, type_row,
diff --git a/hugr-core/src/ops/constant.rs b/hugr-core/src/ops/constant.rs
index 3e8d0acca..7e3a1ac37 100644
--- a/hugr-core/src/ops/constant.rs
+++ b/hugr-core/src/ops/constant.rs
@@ -160,7 +160,7 @@ pub enum Value {
 #[cfg_attr(not(miri), doc = "```")] // this doctest depends on typetag, so fails with miri
 #[cfg_attr(miri, doc = "```ignore")]
 /// use serde::{Serialize,Deserialize};
-/// use hugr_core::{
+/// use hugr::{
 ///   types::Type,ops::constant::{OpaqueValue, ValueName, CustomConst, CustomSerialized},
 ///   extension::{ExtensionSet, prelude::{USIZE_T, ConstUsize}},
 ///   std_extensions::arithmetic::int_types};
diff --git a/hugr-core/src/ops/constant/custom.rs b/hugr-core/src/ops/constant/custom.rs
index 25a3690dd..54a9af514 100644
--- a/hugr-core/src/ops/constant/custom.rs
+++ b/hugr-core/src/ops/constant/custom.rs
@@ -32,7 +32,7 @@ use super::ValueName;
 #[cfg_attr(not(miri), doc = "```")] // this doctest depends on typetag, so fails with miri
 #[cfg_attr(miri, doc = "```ignore")]
 /// use serde::{Serialize,Deserialize};
-/// use hugr_core::{
+/// use hugr::{
 ///   types::Type,ops::constant::{OpaqueValue, ValueName, CustomConst},
 ///   extension::ExtensionSet, std_extensions::arithmetic::int_types};
 /// use serde_json::json;

From 407bb18e03bf9420c476f4b5e93567cf1146b0e5 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 11:29:09 +0100
Subject: [PATCH 6/9] Fix incorrect feature name

---
 hugr/tests/cli.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hugr/tests/cli.rs b/hugr/tests/cli.rs
index b447de71e..2da86bc32 100644
--- a/hugr/tests/cli.rs
+++ b/hugr/tests/cli.rs
@@ -1,4 +1,4 @@
-#![cfg(feature = "cli")]
+#![cfg(feature = "_cli")]
 use assert_cmd::Command;
 use assert_fs::{fixture::FileWriteStr, NamedTempFile};
 use hugr::builder::DFGBuilder;

From 2cc8776ac09ac3d27e0da3ee8e0ab4ae82c1d6c6 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 13:14:27 +0100
Subject: [PATCH 7/9] Simplify hugr-core crate doc

---
 hugr-core/src/lib.rs | 133 +------------------------------------------
 1 file changed, 2 insertions(+), 131 deletions(-)

diff --git a/hugr-core/src/lib.rs b/hugr-core/src/lib.rs
index 73bc5c6d5..40536996a 100644
--- a/hugr-core/src/lib.rs
+++ b/hugr-core/src/lib.rs
@@ -1,136 +1,7 @@
 //! Extensible, graph-based program representation with first-class support for linear types.
 //!
-//! The name HUGR stands for "Hierarchical Unified Graph Representation". It is designed primarily
-//! as an intermediate representation and interchange format for quantum and hybrid
-//! classical–quantum programs.
-//!
-//! Both data-flow and control-flow graphs can be represented in the HUGR. Nodes in the graph may
-//! represent basic operations, or may themselves have "child" graphs, which inherit their inputs
-//! and outputs. Special "non-local" edges allow data to pass directly from a node to another node
-//! that is not a direct descendent (subject to causality constraints).
-//!
-//! The specification can be found
-//! [here](https://github.com/CQCL/hugr/blob/main/specification/hugr.md).
-//!
-//! This crate provides a Rust implementation of HUGR and the standard extensions defined in the
-//! specification.
-//!
-//! It includes methods for:
-//!
-//! - building HUGRs from basic operations;
-//! - defining new extensions;
-//! - serializing and deserializing HUGRs;
-//! - performing local rewrites.
-//!
-//! # Example
-//!
-//! To build a HUGR for a simple quantum circuit and then serialize it to a buffer, we can define
-//! a simple quantum extension and then use the [[builder::DFGBuilder]] as follows:
-//! ```
-//! use hugr_core::builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr};
-//! use hugr_core::extension::prelude::{BOOL_T, QB_T};
-//! use hugr_core::hugr::Hugr;
-//! use hugr_core::type_row;
-//! use hugr_core::types::FunctionType;
-//!
-//! // The type of qubits, `QB_T` is in the prelude but, by default, no gateset
-//! // is defined. This module provides Hadamard and CX gates.
-//! mod mini_quantum_extension {
-//!     use hugr_core::{
-//!         extension::{
-//!             prelude::{BOOL_T, QB_T},
-//!             ExtensionId, ExtensionRegistry, PRELUDE,
-//!         },
-//!         ops::{CustomOp, OpName},
-//!         type_row,
-//!         types::{FunctionType, PolyFuncType},
-//!         Extension,
-//!     };
-//!
-//!     use lazy_static::lazy_static;
-//!
-//!     fn one_qb_func() -> PolyFuncType {
-//!         FunctionType::new_endo(type_row![QB_T]).into()
-//!     }
-//!
-//!     fn two_qb_func() -> PolyFuncType {
-//!         FunctionType::new_endo(type_row![QB_T, QB_T]).into()
-//!     }
-//!     /// The extension identifier.
-//!     pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("mini.quantum");
-//!     fn extension() -> Extension {
-//!         let mut extension = Extension::new(EXTENSION_ID);
-//!
-//!         extension
-//!             .add_op(OpName::new_inline("H"), "Hadamard".into(), one_qb_func())
-//!             .unwrap();
-//!
-//!         extension
-//!             .add_op(OpName::new_inline("CX"), "CX".into(), two_qb_func())
-//!             .unwrap();
-//!
-//!         extension
-//!             .add_op(
-//!                 OpName::new_inline("Measure"),
-//!                 "Measure a qubit, returning the qubit and the measurement result.".into(),
-//!                 FunctionType::new(type_row![QB_T], type_row![QB_T, BOOL_T]),
-//!             )
-//!             .unwrap();
-//!
-//!         extension
-//!     }
-//!
-//!     lazy_static! {
-//!         /// Quantum extension definition.
-//!         pub static ref EXTENSION: Extension = extension();
-//!         static ref REG: ExtensionRegistry =
-//!             ExtensionRegistry::try_new([EXTENSION.to_owned(), PRELUDE.to_owned()]).unwrap();
-//!
-//!     }
-//!     fn get_gate(gate_name: impl Into<OpName>) -> CustomOp {
-//!         EXTENSION
-//!             .instantiate_extension_op(&gate_name.into(), [], &REG)
-//!             .unwrap()
-//!             .into()
-//!     }
-//!     pub fn h_gate() -> CustomOp {
-//!         get_gate("H")
-//!     }
-//!
-//!     pub fn cx_gate() -> CustomOp {
-//!         get_gate("CX")
-//!     }
-//!
-//!     pub fn measure() -> CustomOp {
-//!         get_gate("Measure")
-//!     }
-//! }
-//!
-//! use mini_quantum_extension::{cx_gate, h_gate, measure};
-//!
-//! //      ┌───┐
-//! // q_0: ┤ H ├──■─────
-//! //      ├───┤┌─┴─┐┌─┐
-//! // q_1: ┤ H ├┤ X ├┤M├
-//! //      └───┘└───┘└╥┘
-//! // c:              ╚═
-//! fn make_dfg_hugr() -> Result<Hugr, BuildError> {
-//!     let mut dfg_builder = DFGBuilder::new(FunctionType::new(
-//!         type_row![QB_T, QB_T],
-//!         type_row![QB_T, QB_T, BOOL_T],
-//!     ))?;
-//!     let [wire0, wire1] = dfg_builder.input_wires_arr();
-//!     let h0 = dfg_builder.add_dataflow_op(h_gate(), vec![wire0])?;
-//!     let h1 = dfg_builder.add_dataflow_op(h_gate(), vec![wire1])?;
-//!     let cx = dfg_builder.add_dataflow_op(cx_gate(), h0.outputs().chain(h1.outputs()))?;
-//!     let measure = dfg_builder.add_dataflow_op(measure(), cx.outputs().last())?;
-//!     dfg_builder.finish_prelude_hugr_with_outputs(cx.outputs().take(1).chain(measure.outputs()))
-//! }
-//!
-//! let h: Hugr = make_dfg_hugr().unwrap();
-//! let serialized = serde_json::to_string(&h).unwrap();
-//! println!("{}", serialized);
-//! ```
+//! This crate contains the core definitions for the HUGR representation.
+//! See the [top-level crate documentation](https://docs.rs/hugr/latest/hugr/) for more information.
 
 // Unstable check, may cause false positives.
 // https://github.com/rust-lang/rust-clippy/issues/5112

From 008e6356ca53131f2aabb5c8c027c46f21a171d2 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 13:17:25 +0100
Subject: [PATCH 8/9] Move lint config to workspace Cargo.toml

---
 Cargo.toml           | 5 +++++
 hugr-core/src/lib.rs | 3 ---
 hugr/src/lib.rs      | 8 --------
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index a013edfc4..a1ff18b5e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,11 @@ license = "Apache-2.0"
 [workspace.lints.rust]
 missing_docs = "warn"
 
+[workspace.lints.clippy]
+# Unstable check, may cause false positives.
+# https://github.com/rust-lang/rust-clippy/issues/5112
+debug_assert_with_mut_call = "warn"
+
 [workspace.dependencies]
 portgraph = { version = "0.12.0" }
 insta = { version = "1.34.0" }
diff --git a/hugr-core/src/lib.rs b/hugr-core/src/lib.rs
index 40536996a..a0c7b95ba 100644
--- a/hugr-core/src/lib.rs
+++ b/hugr-core/src/lib.rs
@@ -3,9 +3,6 @@
 //! This crate contains the core definitions for the HUGR representation.
 //! See the [top-level crate documentation](https://docs.rs/hugr/latest/hugr/) for more information.
 
-// Unstable check, may cause false positives.
-// https://github.com/rust-lang/rust-clippy/issues/5112
-#![warn(clippy::debug_assert_with_mut_call)]
 // proptest-derive generates many of these warnings.
 // https://github.com/rust-lang/rust/issues/120363
 // https://github.com/proptest-rs/proptest/issues/447
diff --git a/hugr/src/lib.rs b/hugr/src/lib.rs
index f578d1324..d626d2dd8 100644
--- a/hugr/src/lib.rs
+++ b/hugr/src/lib.rs
@@ -132,14 +132,6 @@
 //! println!("{}", serialized);
 //! ```
 
-// Unstable check, may cause false positives.
-// https://github.com/rust-lang/rust-clippy/issues/5112
-#![warn(clippy::debug_assert_with_mut_call)]
-// proptest-derive generates many of these warnings.
-// https://github.com/rust-lang/rust/issues/120363
-// https://github.com/proptest-rs/proptest/issues/447
-#![cfg_attr(test, allow(non_local_definitions))]
-
 // These modules are re-exported as-is. If more control is needed, define a new module in this crate with the desired exports.
 // The doc inline directive is necessary for renamed modules to appear as if they were defined in this crate.
 pub use hugr_core::{builder, core, extension, hugr, ops, std_extensions, types, utils};

From dc4341bb4ca6ec87cba8f22cc983ab72d410a0c3 Mon Sep 17 00:00:00 2001
From: Agustin Borgna <agustin.borgna@quantinuum.com>
Date: Tue, 28 May 2024 13:22:10 +0100
Subject: [PATCH 9/9] s/hugr_core::/hugr::/ in all examples

---
 hugr-core/src/builder.rs               | 10 +++++-----
 hugr-core/src/extension/declarative.rs |  4 ++--
 hugr-core/src/macros.rs                |  6 +++---
 hugr-core/src/ops/dataflow.rs          | 16 ++++++++--------
 hugr-core/src/types.rs                 |  6 +++---
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/hugr-core/src/builder.rs b/hugr-core/src/builder.rs
index 3d0365904..c186b57cd 100644
--- a/hugr-core/src/builder.rs
+++ b/hugr-core/src/builder.rs
@@ -26,11 +26,11 @@
 //! `CircuitBuilder`.
 //!
 //! ```rust
-//! # use hugr_core::Hugr;
-//! # use hugr_core::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
-//! use hugr_core::extension::prelude::BOOL_T;
-//! use hugr_core::std_extensions::logic::{NotOp, LOGIC_REG};
-//! use hugr_core::types::FunctionType;
+//! # use hugr::Hugr;
+//! # use hugr::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
+//! use hugr::extension::prelude::BOOL_T;
+//! use hugr::std_extensions::logic::{NotOp, LOGIC_REG};
+//! use hugr::types::FunctionType;
 //!
 //! # fn doctest() -> Result<(), BuildError> {
 //! let hugr = {
diff --git a/hugr-core/src/extension/declarative.rs b/hugr-core/src/extension/declarative.rs
index 3931184b5..99ea08adb 100644
--- a/hugr-core/src/extension/declarative.rs
+++ b/hugr-core/src/extension/declarative.rs
@@ -15,9 +15,9 @@
 //! The definition can be loaded into a registry using the [`load_extensions`] or [`load_extensions_file`] functions.
 //! ```rust
 //! # const DECLARATIVE_YAML: &str = include_str!("../../../hugr/examples/extension/declarative.yaml");
-//! # use hugr_core::extension::declarative::load_extensions;
+//! # use hugr::extension::declarative::load_extensions;
 //! // Required extensions must already be present in the registry.
-//! let mut reg = hugr_core::std_extensions::logic::LOGIC_REG.clone();
+//! let mut reg = hugr::std_extensions::logic::LOGIC_REG.clone();
 //! load_extensions(DECLARATIVE_YAML, &mut reg).unwrap();
 //! ```
 //!
diff --git a/hugr-core/src/macros.rs b/hugr-core/src/macros.rs
index cf948a55c..10dccee70 100644
--- a/hugr-core/src/macros.rs
+++ b/hugr-core/src/macros.rs
@@ -42,8 +42,8 @@ pub(crate) use impl_box_clone;
 ///
 /// Example:
 /// ```
-/// # use hugr_core::macros::type_row;
-/// # use hugr_core::types::{FunctionType, Type, TypeRow};
+/// # use hugr::type_row;
+/// # use hugr::types::{FunctionType, Type, TypeRow};
 /// const U: Type = Type::UNIT;
 /// let static_row: TypeRow = type_row![U, U];
 /// let dynamic_row: TypeRow = vec![U, U, U].into();
@@ -86,7 +86,7 @@ pub use type_row;
 /// of a test module only. Example:
 /// ```rust
 /// # mod test {
-/// # use hugr_core::macros::const_extension_ids;
+/// # use hugr::const_extension_ids;
 /// const_extension_ids! {
 ///   pub const EXT_A: ExtensionId = "A";
 ///   /// A doc comment
diff --git a/hugr-core/src/ops/dataflow.rs b/hugr-core/src/ops/dataflow.rs
index 76eccbd79..54202ffc0 100644
--- a/hugr-core/src/ops/dataflow.rs
+++ b/hugr-core/src/ops/dataflow.rs
@@ -210,11 +210,11 @@ impl Call {
     /// This matches [`OpType::static_input_port`].
     ///
     /// ```
-    /// # use hugr_core::ops::dataflow::Call;
-    /// # use hugr_core::ops::OpType;
-    /// # use hugr_core::types::FunctionType;
-    /// # use hugr_core::extension::prelude::QB_T;
-    /// # use hugr_core::extension::PRELUDE_REGISTRY;
+    /// # use hugr::ops::dataflow::Call;
+    /// # use hugr::ops::OpType;
+    /// # use hugr::types::FunctionType;
+    /// # use hugr::extension::prelude::QB_T;
+    /// # use hugr::extension::PRELUDE_REGISTRY;
     /// let signature = FunctionType::new(vec![QB_T, QB_T], vec![QB_T, QB_T]);
     /// let call = Call::try_new(signature.into(), &[], &PRELUDE_REGISTRY).unwrap();
     /// let op = OpType::Call(call.clone());
@@ -308,9 +308,9 @@ impl LoadConstant {
     /// This matches [`OpType::static_input_port`].
     ///
     /// ```
-    /// # use hugr_core::ops::dataflow::LoadConstant;
-    /// # use hugr_core::ops::OpType;
-    /// # use hugr_core::types::Type;
+    /// # use hugr::ops::dataflow::LoadConstant;
+    /// # use hugr::ops::OpType;
+    /// # use hugr::types::Type;
     /// let datatype = Type::UNIT;
     /// let load_constant = LoadConstant { datatype };
     /// let op = OpType::LoadConstant(load_constant.clone());
diff --git a/hugr-core/src/types.rs b/hugr-core/src/types.rs
index 081caf46f..cb8cd0706 100644
--- a/hugr-core/src/types.rs
+++ b/hugr-core/src/types.rs
@@ -260,15 +260,15 @@ impl TypeEnum {
 ///
 /// Examples:
 /// ```
-/// # use hugr_core::types::{Type, TypeBound};
-/// # use hugr_core::type_row;
+/// # use hugr::types::{Type, TypeBound};
+/// # use hugr::type_row;
 ///
 /// let sum = Type::new_sum([type_row![], type_row![]]);
 /// assert_eq!(sum.least_upper_bound(), TypeBound::Eq);
 /// ```
 ///
 /// ```
-/// # use hugr_core::types::{Type, TypeBound, FunctionType};
+/// # use hugr::types::{Type, TypeBound, FunctionType};
 ///
 /// let func_type = Type::new_function(FunctionType::new_endo(vec![]));
 /// assert_eq!(func_type.least_upper_bound(), TypeBound::Copyable);