Skip to content

Commit

Permalink
Merge branch 'main' of gh:CQCL-DEV/hugr into ae/constvals
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed Jun 25, 2024
2 parents 0fee7e9 + 4ef4826 commit 6b9427e
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ num-rational = "0.4.1"
paste = "1.0"
petgraph = { version = "0.6.3", default-features = false }
proptest = "1.4.0"
proptest-derive = "0.4.0"
proptest-derive = "0.5.0"
regex = "1.9.5"
regex-syntax = "0.8.3"
rstest = "0.21.0"
Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//! let _dfg_handle = {
//! let mut dfg = module_builder.define_function(
//! "main",
//! FunctionType::new(vec![BOOL_T], vec![BOOL_T]).into(),
//! FunctionType::new(vec![BOOL_T], vec![BOOL_T]),
//! )?;
//!
//! // Get the wires from the function inputs.
Expand All @@ -59,7 +59,7 @@
//! let _circuit_handle = {
//! let mut dfg = module_builder.define_function(
//! "circuit",
//! FunctionType::new(vec![BOOL_T, BOOL_T], vec![BOOL_T, BOOL_T]).into(),
//! FunctionType::new_endo(vec![BOOL_T, BOOL_T]),
//! )?;
//! let mut circuit = dfg.as_circuit(dfg.input_wires());
//!
Expand Down
3 changes: 2 additions & 1 deletion hugr-core/src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ pub trait Container {
fn define_function(
&mut self,
name: impl Into<String>,
signature: PolyFuncType,
signature: impl Into<PolyFuncType>,
) -> Result<FunctionBuilder<&mut Hugr>, BuildError> {
let signature = signature.into();
let body = signature.body().clone();
let f_node = self.add_child_node(ops::FuncDefn {
name: name.into(),
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub(crate) mod test {
let build_result = {
let mut module_builder = ModuleBuilder::new();
let mut func_builder = module_builder
.define_function("main", FunctionType::new(vec![NAT], type_row![NAT]).into())?;
.define_function("main", FunctionType::new(vec![NAT], type_row![NAT]))?;
let _f_id = {
let [int] = func_builder.input_wires_arr();

Expand Down
6 changes: 2 additions & 4 deletions hugr-core/src/builder/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ mod test {
fn basic_conditional_module() -> Result<(), BuildError> {
let build_result: Result<Hugr, BuildError> = {
let mut module_builder = ModuleBuilder::new();
let mut fbuild = module_builder.define_function(
"main",
FunctionType::new(type_row![NAT], type_row![NAT]).into(),
)?;
let mut fbuild = module_builder
.define_function("main", FunctionType::new(type_row![NAT], type_row![NAT]))?;
let tru_const = fbuild.add_constant(Value::true_val());
let _fdef = {
let const_wire = fbuild.load_const(&tru_const);
Expand Down
34 changes: 15 additions & 19 deletions hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ impl FunctionBuilder<Hugr> {
/// # Errors
///
/// Error in adding DFG child nodes.
pub fn new(name: impl Into<String>, signature: PolyFuncType) -> Result<Self, BuildError> {
pub fn new(
name: impl Into<String>,
signature: impl Into<PolyFuncType>,
) -> Result<Self, BuildError> {
let signature = signature.into();
let body = signature.body().clone();
let op = ops::FuncDefn {
signature,
Expand Down Expand Up @@ -227,7 +231,7 @@ pub(crate) mod test {
let _f_id = {
let mut func_builder = module_builder.define_function(
"main",
FunctionType::new(type_row![NAT, QB], type_row![NAT, QB]).into(),
FunctionType::new(type_row![NAT, QB], type_row![NAT, QB]),
)?;

let [int, qb] = func_builder.input_wires_arr();
Expand Down Expand Up @@ -258,7 +262,7 @@ pub(crate) mod test {

let f_build = module_builder.define_function(
"main",
FunctionType::new(type_row![BOOL_T], type_row![BOOL_T, BOOL_T]).into(),
FunctionType::new(type_row![BOOL_T], type_row![BOOL_T, BOOL_T]),
)?;

f(f_build)?;
Expand Down Expand Up @@ -306,10 +310,8 @@ pub(crate) mod test {
let builder = || {
let mut module_builder = ModuleBuilder::new();

let f_build = module_builder.define_function(
"main",
FunctionType::new(type_row![QB], type_row![QB, QB]).into(),
)?;
let f_build = module_builder
.define_function("main", FunctionType::new(type_row![QB], type_row![QB, QB]))?;

let [q1] = f_build.input_wires_arr();
f_build.finish_with_outputs([q1, q1])?;
Expand All @@ -330,10 +332,8 @@ pub(crate) mod test {
#[test]
fn simple_inter_graph_edge() {
let builder = || -> Result<Hugr, BuildError> {
let mut f_build = FunctionBuilder::new(
"main",
FunctionType::new(type_row![BIT], type_row![BIT]).into(),
)?;
let mut f_build =
FunctionBuilder::new("main", FunctionType::new(type_row![BIT], type_row![BIT]))?;

let [i1] = f_build.input_wires_arr();
let noop = f_build.add_dataflow_op(Noop { ty: BIT }, [i1])?;
Expand All @@ -354,10 +354,8 @@ pub(crate) mod test {

#[test]
fn error_on_linear_inter_graph_edge() -> Result<(), BuildError> {
let mut f_build = FunctionBuilder::new(
"main",
FunctionType::new(type_row![QB], type_row![QB]).into(),
)?;
let mut f_build =
FunctionBuilder::new("main", FunctionType::new(type_row![QB], type_row![QB]))?;

let [i1] = f_build.input_wires_arr();
let noop = f_build.add_dataflow_op(Noop { ty: QB }, [i1])?;
Expand Down Expand Up @@ -398,10 +396,8 @@ pub(crate) mod test {
let mut module_builder = ModuleBuilder::new();

let (dfg_node, f_node) = {
let mut f_build = module_builder.define_function(
"main",
FunctionType::new(type_row![BIT], type_row![BIT]).into(),
)?;
let mut f_build = module_builder
.define_function("main", FunctionType::new(type_row![BIT], type_row![BIT]))?;

let [i1] = f_build.input_wires_arr();
let dfg = f_build.add_hugr_with_wires(dfg_hugr, [i1])?;
Expand Down
7 changes: 3 additions & 4 deletions hugr-core/src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ mod test {
FunctionType::new(
vec![qubit_state_type.get_alias_type()],
vec![qubit_state_type.get_alias_type()],
)
.into(),
),
)?;
n_identity(f_build)?;
module_builder.finish_hugr(&EMPTY_REG)
Expand All @@ -220,11 +219,11 @@ mod test {

let mut f_build = module_builder.define_function(
"main",
FunctionType::new(type_row![NAT], type_row![NAT, NAT]).into(),
FunctionType::new(type_row![NAT], type_row![NAT, NAT]),
)?;
let local_build = f_build.define_function(
"local",
FunctionType::new(type_row![NAT], type_row![NAT, NAT]).into(),
FunctionType::new(type_row![NAT], type_row![NAT, NAT]),
)?;
let [wire] = local_build.input_wires_arr();
let f_id = local_build.finish_with_outputs([wire, wire])?;
Expand Down
4 changes: 1 addition & 3 deletions hugr-core/src/builder/tail_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ mod test {
let mut module_builder = ModuleBuilder::new();
let mut fbuild = module_builder.define_function(
"main",
FunctionType::new(type_row![BIT], type_row![NAT])
.with_extension_delta(PRELUDE_ID)
.into(),
FunctionType::new(type_row![BIT], type_row![NAT]).with_extension_delta(PRELUDE_ID),
)?;
let _fdef = {
let [b1] = fbuild
Expand Down
7 changes: 7 additions & 0 deletions hugr-core/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ pub enum ExtensionBuildError {
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ExtensionSet(BTreeSet<ExtensionId>);

/// A special ExtensionId which indicates that the delta of a non-Function
/// container node should be computed by extension inference. See [`infer_extensions`]
/// which lists the container nodes to which this can be applied.
///
/// [`infer_extensions`]: crate::hugr::Hugr::infer_extensions
pub const TO_BE_INFERRED: ExtensionId = ExtensionId::new_unchecked(".TO_BE_INFERRED");

impl ExtensionSet {
/// Creates a new empty extension set.
pub const fn new() -> Self {
Expand Down
Loading

0 comments on commit 6b9427e

Please sign in to comment.