-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Add a hugr-core
crate
#1108
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b709998
refactor: Add a `hugr-core` crate
aborgna-q 0d58e56
Configure CI/metadata for the new package
aborgna-q 5dec197
Simplify README, with less text to go stale
aborgna-q b2ef149
Cleanup main crate docs
aborgna-q 0f23521
Use main crate in doc examples
aborgna-q 407bb18
Fix incorrect feature name
aborgna-q 2cc8776
Simplify hugr-core crate doc
aborgna-q 008e635
Move lint config to workspace Cargo.toml
aborgna-q dc4341b
s/hugr_core::/hugr::/ in all examples
aborgna-q File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
rust: | ||
- "hugr/**" | ||
- "hugr-passes/**" | ||
- "hugr-*/**" | ||
- "Cargo.toml" | ||
- "specification/schema/**" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
[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 } | ||
|
||
# Required for documentation examples | ||
hugr = { path = "../hugr" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
![](/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) | ||
|
||
Internal core definitions for the `hugr` package. | ||
Refer to the [main crate](http://crates.io/crates/hugr) for more information. | ||
|
||
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ts/hugr__hugr__views__tests__dot_cfg.snap → ...gr_core__hugr__views__tests__dot_cfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/hugr__hugr__views__tests__dot_dfg.snap → ...gr_core__hugr__views__tests__dot_dfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
source: hugr/views/tests.rs | ||
source: hugr-core/views/tests.rs | ||
expression: h.dot_string() | ||
--- | ||
digraph { | ||
|
2 changes: 1 addition & 1 deletion
2
...r__hugr__views__tests__dot_empty_dfg.snap → ...e__hugr__views__tests__dot_empty_dfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/hugr__hugr__views__tests__mmd_cfg.snap → ...gr_core__hugr__views__tests__mmd_cfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/hugr__hugr__views__tests__mmd_dfg.snap → ...gr_core__hugr__views__tests__mmd_dfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r__hugr__views__tests__mmd_empty_dfg.snap → ...e__hugr__views__tests__mmd_empty_dfg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
//! Extensible, graph-based program representation with first-class support for linear types. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a copy paste of the lib docs? another thing to go out of date potentially? |
||
//! | ||
//! 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(), [], ®) | ||
//! .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; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these have
#
in front of themThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed module-level docs when searching for examples...
I think these give a bit of context to the example below, so it's fine to have them explicit.
I changed all
hugr_core::
uses forhugr::
, to avoid further confusions.