Skip to content
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

Alternative start to automatically including extension-reqs #674

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/builder/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,22 @@ mod test {
test::{build_main, NAT, QB},
Dataflow, DataflowSubContainer, Wire,
},
extension::prelude::BOOL_T,
extension::{
prelude::{BOOL_T, PRELUDE_ID},
ExtensionSet,
},
ops::{custom::OpaqueOp, LeafOp},
type_row,
types::FunctionType,
utils::test_quantum_extension::{cx_gate, h_gate, measure},
utils::test_quantum_extension::{self, cx_gate, h_gate, measure},
};

#[test]
fn simple_linear() {
let build_res = build_main(
FunctionType::new(type_row![QB, QB], type_row![QB, QB]).pure(),
FunctionType::new(type_row![QB, QB], type_row![QB, QB]).with_input_extensions(
ExtensionSet::from_iter([PRELUDE_ID, test_quantum_extension::EXTENSION_ID]),
),
|mut f_build| {
let wires = f_build.input_wires().collect();

Expand Down Expand Up @@ -184,7 +189,10 @@ mod test {
.into(),
);
let build_res = build_main(
FunctionType::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T]).pure(),
FunctionType::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T])
.with_input_extensions(ExtensionSet::singleton(
&test_quantum_extension::EXTENSION_ID,
)),
|mut f_build| {
let [q0, q1, angle]: [Wire; 3] = f_build.input_wires_arr();

Expand Down
11 changes: 8 additions & 3 deletions src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ pub(crate) mod test {
use crate::hugr::validate::InterGraphEdgeError;
use crate::ops::{handle::NodeHandle, LeafOp, OpTag};

use crate::std_extensions::logic;
use crate::std_extensions::logic::test::and_op;
use crate::types::Type;
use crate::utils::test_quantum_extension::h_gate;
use crate::utils::test_quantum_extension::{self, h_gate};
use crate::{
builder::{
test::{n_identity, BIT, NAT, QB},
Expand All @@ -239,7 +240,10 @@ 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]).pure(),
FunctionType::new(type_row![NAT, QB], type_row![NAT, QB])
.with_input_extensions(ExtensionSet::singleton(
&test_quantum_extension::EXTENSION_ID,
)),
)?;

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

let f_build = module_builder.define_function(
"main",
FunctionType::new(type_row![BOOL_T], type_row![BOOL_T, BOOL_T]).pure(),
FunctionType::new(type_row![BOOL_T], type_row![BOOL_T, BOOL_T])
.with_input_extensions(ExtensionSet::singleton(&logic::EXTENSION_ID)),
)?;

f(f_build)?;
Expand Down
6 changes: 2 additions & 4 deletions src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ impl OpDef {
}
};

let res = pf.instantiate(args, exts)?;
// TODO bring this assert back once resource inference is done?
// https://github.com/CQCL-DEV/hugr/issues/425
// assert!(res.contains(self.extension()));
let mut res = pf.instantiate(args, exts)?;
res.extension_reqs.insert(self.extension());
Ok(res)
}

Expand Down
Loading