Skip to content
Open
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
1,292 changes: 1,262 additions & 30 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ large_enum_variant = "allow"
[patch.crates-io]

# Uncomment to use unreleased versions of hugr
# hugr = { git = "https://github.com/CQCL/hugr", branch = "ss/push-xvxtzqlwkvux" }
# hugr-core = { git = "https://github.com/CQCL/hugr", branch = "ss/push-xvxtzqlwkvux" }
# hugr-passes = { git = "https://github.com/CQCL/hugr", branch = "ss/push-xvxtzqlwkvux" }
# hugr-cli = { git = "https://github.com/CQCL/hugr", branch = "ss/push-xvxtzqlwkvux" }


hugr = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
hugr-core = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
hugr-passes = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
hugr-cli = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
# portgraph = { git = "https://github.com/CQCL/portgraph", rev = "68b96ac737e0c285d8c543b2d74a7aa80a18202c" }
[workspace.dependencies]

# Make sure to run `just recompile-eccs` if the hugr serialisation format changes.
hugr = "0.20.2"
hugr-core = "0.20.2"
hugr-cli = "0.20.2"
# hugr = "0.20.1"
# hugr-core = "0.20.1"
# hugr-cli = "0.20.1"
hugr = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
hugr-core = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
hugr-cli = { git = "https://github.com/CQCL/hugr", rev = "544759f4f472ddc4620c6679e11fe7551b46624c" }
Comment on lines +52 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set the "patch" above if setting a rev here.

Will this work with hugr 0.21 once released?

portgraph = "0.14.1"
pyo3 = ">= 0.23.4, < 0.26"
itertools = "0.14.0"
Expand Down
Binary file added test_files/6cz.hugr
Binary file not shown.
78 changes: 78 additions & 0 deletions test_files/perhugr1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"state_space": {
"graph": {
"nodes": {
"8be885340a6343a4": {
"value": {
"Replacement": {
"subgraph": {
"nodes": [
["1f2468564499672f", 9],
["1f2468564499672f", 10]
],
"inputs": [
[
[
["1f2468564499672f", 9],
{
"index": 0
}
]
],
[
[
["1f2468564499672f", 9],
{
"index": 1
}
]
],
[
[
["1f2468564499672f", 10],
{
"index": 0
}
]
]
],
"outputs": [
[
["1f2468564499672f", 9],
{
"index": 0
}
],
[
["1f2468564499672f", 10],
{
"index": 0
}
],
[
["1f2468564499672f", 10],
{
"index": 1
}
]
]
},
"replacement": "HUGRiHJv?@{\"modules\":[{\"version\":\"live\",\"nodes\":[{\"parent\":0,\"op\":\"Module\"},{\"parent\":0,\"op\":\"FuncDefn\",\"name\":\"main\",\"signature\":{\"params\":[],\"body\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]}}},{\"parent\":1,\"op\":\"Input\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":1,\"op\":\"Output\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":1,\"op\":\"DFG\",\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Input\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":4,\"op\":\"Output\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}}],\"edges\":[[[2,0],[4,0]],[[2,1],[4,1]],[[2,2],[4,2]],[[4,0],[3,0]],[[4,1],[3,1]],[[4,2],[3,2]],[[5,0],[8,1]],[[5,1],[7,0]],[[5,2],[7,1]],[[7,0],[8,0]],[[7,1],[6,1]],[[8,0],[6,2]],[[8,1],[6,0]]],\"metadata\":[null,null,null,null,null,null,null,null,null],\"encoder\":\"hugr-rs v0.20.2\",\"entrypoint\":4}],\"extensions\":[]}"
}
},
"incoming": [["1f2468564499672f", null]]
},
"1f2468564499672f": {
"value": {
"Base": "HUGRiHJv?@{\"modules\":[{\"version\":\"live\",\"nodes\":[{\"parent\":0,\"op\":\"Module\"},{\"parent\":0,\"op\":\"FuncDefn\",\"name\":\"main\",\"signature\":{\"params\":[],\"body\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]}}},{\"parent\":1,\"op\":\"Input\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":1,\"op\":\"Output\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":1,\"op\":\"DFG\",\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Input\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":4,\"op\":\"Output\",\"types\":[{\"t\":\"Q\"},{\"t\":\"Q\"},{\"t\":\"Q\"}]},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}},{\"parent\":4,\"op\":\"Extension\",\"extension\":\"tket2.quantum\",\"name\":\"CZ\",\"args\":[],\"signature\":{\"input\":[{\"t\":\"Q\"},{\"t\":\"Q\"}],\"output\":[{\"t\":\"Q\"},{\"t\":\"Q\"}]}}],\"edges\":[[[2,0],[4,0]],[[2,1],[4,1]],[[2,2],[4,2]],[[4,0],[3,0]],[[4,1],[3,1]],[[4,2],[3,2]],[[5,0],[7,0]],[[5,1],[7,1]],[[5,2],[8,1]],[[7,0],[8,0]],[[7,1],[9,0]],[[8,0],[10,0]],[[8,1],[9,1]],[[9,0],[11,1]],[[9,1],[10,1]],[[10,0],[11,0]],[[10,1],[12,1]],[[11,0],[6,0]],[[11,1],[12,0]],[[12,0],[6,1]],[[12,1],[6,2]]],\"metadata\":[null,null,null,null,null,null,null,null,null,null,null,null,null],\"encoder\":\"hugr-rs v0.20.2\",\"entrypoint\":4}],\"extensions\":[]}"
},
"incoming": []
}
},
"resolver_id": {
"id": "SerdeHashResolver"
}
},
"base_commit": "1f2468564499672f"
}
}
2 changes: 1 addition & 1 deletion tket1-passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde_json.workspace = true
tket-json-rs.workspace = true

[build-dependencies]
cc = "1.2"
cc = "1.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by: Can you move the explicit dependency versions in this file to the workspace toml?

bindgen = "0.72"
conan2 = "0.1.7"

Expand Down
2 changes: 1 addition & 1 deletion tket2-hseries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["compilers"]

[features]
default = ["cli"]
cli = ["dep:clap", "dep:hugr-cli"]
cli = ["dep:clap", "dep:hugr-cli", "dep:anyhow"]
llvm = ["tket2/llvm", "dep:anyhow"]

[[bin]]
Expand Down
7 changes: 5 additions & 2 deletions tket2-hseries/src/bin/tket2-hseries.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! CLI for tket2-hseries

use anyhow::Result;
use clap::Parser as _;
use hugr::extension::ExtensionRegistry;
use tket2_hseries::cli::CliArgs;

fn main() {
fn main() -> Result<()> {
match CliArgs::parse() {
CliArgs::GenExtensions(args) => {
let reg = ExtensionRegistry::new([
Expand All @@ -20,11 +21,13 @@ fn main() {
tket2_hseries::extension::wasm::EXTENSION.to_owned(),
]);

args.run_dump(&reg);
args.run_dump(&reg)?;
}
_ => {
eprintln!("Unknown command");
std::process::exit(1);
}
};

Ok(())
}
2 changes: 1 addition & 1 deletion tket2-hseries/src/extension/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl HasConcrete for FutureOpDef {

fn instantiate(&self, type_args: &[TypeArg]) -> Result<Self::Concrete, OpLoadError> {
match type_args {
[TypeArg::Type { ty }] => Ok(FutureOp {
[TypeArg::Runtime(ty)] => Ok(FutureOp {
op: *self,
typ: ty.clone(),
}),
Expand Down
6 changes: 3 additions & 3 deletions tket2-hseries/src/extension/qsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ impl MakeOpDef for RuntimeBarrierDef {

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
PolyFuncType::new(
[TypeParam::max_nat()],
[TypeParam::max_nat_type()],
Signature::new_endo(
array_type_parametric(TypeArg::new_var_use(0, TypeParam::max_nat()), qb_t())
array_type_parametric(TypeArg::new_var_use(0, TypeParam::max_nat_type()), qb_t())
.unwrap(),
),
)
Expand Down Expand Up @@ -534,7 +534,7 @@ pub(crate) fn runtime_barrier_ext_op(
) -> Result<ExtensionOp, hugr::extension::SignatureError> {
ExtensionOp::new(
EXTENSION.get_op(&RUNTIME_BARRIER_NAME).unwrap().clone(),
[TypeArg::BoundedNat { n: array_size }],
[TypeArg::BoundedNat(array_size)],
)
}

Expand Down
34 changes: 14 additions & 20 deletions tket2-hseries/src/extension/qsystem/barrier/barrier_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ impl BarrierOperationFactory {
Self::WRAPPED_BARRIER,
Default::default(),
PolyFuncTypeRV::new(
vec![TypeParam::new_list(TypeBound::Any)],
vec![TypeParam::new_list_type(TypeBound::Any)],
FuncValueType::new_endo(TypeRV::new_row_var_use(0, TypeBound::Any)),
),
ext_ref,
)
.unwrap();
let array_unpack_sig = PolyFuncTypeRV::new(
vec![
TypeParam::max_nat(),
TypeParam::Type { b: TypeBound::Any },
TypeParam::new_list(TypeBound::Any),
TypeParam::max_nat_type(),
TypeParam::RuntimeType(TypeBound::Any),
TypeParam::new_list_type(TypeBound::Any),
],
FuncValueType::new(
array_type_parametric(
TypeArg::new_var_use(0, TypeParam::max_nat()),
TypeArg::new_var_use(0, TypeParam::max_nat_type()),
Type::new_var_use(1, TypeBound::Any),
)
.unwrap(),
Expand All @@ -157,9 +157,9 @@ impl BarrierOperationFactory {
let tuple_unpack_sig = PolyFuncTypeRV::new(
vec![
// incoming tuple row
TypeParam::new_list(TypeBound::Any),
TypeParam::new_list_type(TypeBound::Any),
// unpacked row
TypeParam::new_list(TypeBound::Any),
TypeParam::new_list_type(TypeBound::Any),
],
FuncValueType::new(
Type::new_tuple(TypeRV::new_row_var_use(0, TypeBound::Any)),
Expand Down Expand Up @@ -289,15 +289,15 @@ impl BarrierOperationFactory {
) -> Result<hugr::builder::handle::Outputs, BuildError> {
let size = qubit_wires.len();
let qb_row = vec![qb_t(); size];
let args = [TypeArg::Sequence {
elems: qb_row.clone().into_iter().map(Into::into).collect(),
}];
let args = [TypeArg::List(
qb_row.clone().into_iter().map(Into::into).collect(),
)];

self.apply_cached_operation(
builder,
&Self::WRAPPED_BARRIER,
args,
&[TypeArg::BoundedNat { n: size as u64 }],
&[TypeArg::BoundedNat(size as u64)],
qubit_wires,
|_, func_b| func_b.build_wrapped_barrier(func_b.input_wires()),
)
Expand Down Expand Up @@ -346,9 +346,7 @@ impl BarrierOperationFactory {
let args = [
size.into(),
elem_ty.clone().into(),
TypeArg::Sequence {
elems: row.into_iter().map(Into::into).collect(),
},
TypeArg::List(row.into_iter().map(Into::into).collect()),
];
Some(args)
}
Expand Down Expand Up @@ -403,12 +401,8 @@ impl BarrierOperationFactory {
.unpack_type(&Type::new_tuple(tuple_row.to_vec()))?;

let args = [
TypeArg::Sequence {
elems: tuple_row.iter().cloned().map(Into::into).collect(),
},
TypeArg::Sequence {
elems: unpacked_row.into_iter().map(Into::into).collect(),
},
TypeArg::List(tuple_row.iter().cloned().map(Into::into).collect()),
TypeArg::List(unpacked_row.into_iter().map(Into::into).collect()),
];

Some(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn array_args(ext: &CustomType) -> Option<(u64, &Type)> {
.check_custom(ext)
.ok()
.and_then(|_| match ext.args() {
[TypeArg::BoundedNat { n }, TypeArg::Type { ty: elem_ty }] => Some((*n, elem_ty)),
[TypeArg::BoundedNat(n), TypeArg::Runtime(elem_ty)] => Some((*n, elem_ty)),
_ => None,
})
}
Expand Down
18 changes: 8 additions & 10 deletions tket2-hseries/src/extension/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl ResultOpDef {
Self::Bool | Self::F64 => vec![],
Self::Int | Self::UInt => vec![LOG_WIDTH_TYPE_PARAM],
_ => [
vec![TypeParam::max_nat()],
vec![TypeParam::max_nat_type()],
self.simple_type_op().type_params(),
]
.concat(),
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ResultOpDef {

fn result_signature(&self) -> SignatureFunc {
PolyFuncType::new(
[vec![TypeParam::String], self.type_params()].concat(),
[vec![TypeParam::StringType], self.type_params()].concat(),
Signature::new(self.arg_type(), type_row![]),
)
.into()
Expand All @@ -171,7 +171,7 @@ impl ResultOpDef {

fn array_arg_type(inner_t: Type) -> Type {
collections::array::array_type_parametric(
TypeArg::new_var_use(1, TypeParam::max_nat()),
TypeArg::new_var_use(1, TypeParam::max_nat_type()),
inner_t,
)
.unwrap()
Expand Down Expand Up @@ -306,13 +306,11 @@ fn concrete_result_op_type_args(
) -> Result<(String, Option<u64>, Option<u64>), OpLoadError> {
let err = || hugr::extension::SignatureError::InvalidTypeArgs.into();
match args {
[TypeArg::String { arg }] => Ok((arg.to_owned(), None, None)),
[TypeArg::String(arg)] => Ok((arg.to_owned(), None, None)),

[TypeArg::String { arg }, TypeArg::BoundedNat { n }] => {
Ok((arg.to_owned(), Some(*n), None))
}
[TypeArg::String(arg), TypeArg::BoundedNat(n)] => Ok((arg.to_owned(), Some(*n), None)),

[TypeArg::String { arg }, TypeArg::BoundedNat { n }, TypeArg::BoundedNat { n: m }] => {
[TypeArg::String(arg), TypeArg::BoundedNat(n), TypeArg::BoundedNat(m)] => {
Ok((arg.to_owned(), Some(*n), Some(*m)))
}

Expand Down Expand Up @@ -348,14 +346,14 @@ impl MakeExtensionOp for ResultOp {
match self.args {
ResultArgs::Simple(_) => {}
ResultArgs::Array(_, size) => {
type_args.push(TypeArg::BoundedNat { n: size });
type_args.push(TypeArg::BoundedNat(size));
}
}

match self.args {
ResultArgs::Simple(SimpleArgs::Int(width))
| ResultArgs::Array(SimpleArgs::Int(width), _) => {
type_args.push(TypeArg::BoundedNat { n: width as u64 });
type_args.push(TypeArg::BoundedNat(width as u64));
}
_ => {}
}
Expand Down
Loading
Loading