Skip to content

Commit 6bcec20

Browse files
committed
Merge branch 'release-rs-v0.16.0' into feat/persistenthugr
2 parents 14f969a + 9a1b615 commit 6bcec20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6098
-1380
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hugr-core/src/hugr/patch/port_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum BoundaryPort<HostNode, P> {
2323
pub struct HostPort<N, P>(pub N, pub P);
2424

2525
/// A port in the replacement graph.
26-
#[derive(Debug, Clone, Copy, From)]
26+
#[derive(Debug, Clone, Copy, From, PartialEq, Eq, PartialOrd, Ord)]
2727
pub struct ReplacementPort<P>(pub Node, pub P);
2828

2929
impl<HostNode: Copy, P> BoundaryPort<HostNode, P> {

hugr-core/src/hugr/patch/simple_replace.rs

+67-3
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ pub(in crate::hugr::patch) mod test {
573573
DataflowSubContainer, HugrBuilder, ModuleBuilder,
574574
};
575575
use crate::extension::prelude::{bool_t, qb_t};
576-
use crate::hugr::patch::PatchVerification;
576+
use crate::hugr::patch::simple_replace::OutputBoundaryMap;
577+
use crate::hugr::patch::{PatchVerification, ReplacementPort};
577578
use crate::hugr::views::{HugrView, SiblingSubgraph};
578579
use crate::hugr::{Hugr, HugrMut, Patch};
579580
use crate::ops::dataflow::DataflowOpTrait;
@@ -584,7 +585,7 @@ pub(in crate::hugr::patch) mod test {
584585
use crate::std_extensions::logic::LogicOp;
585586
use crate::types::{Signature, Type};
586587
use crate::utils::test_quantum_extension::{cx_gate, h_gate};
587-
use crate::{IncomingPort, Node, OutgoingPort};
588+
use crate::{Direction, IncomingPort, Node, OutgoingPort, Port};
588589

589590
use super::SimpleReplacement;
590591

@@ -801,6 +802,17 @@ pub(in crate::hugr::patch) mod test {
801802
nu_inp,
802803
nu_out: nu_out.into(),
803804
};
805+
806+
// Check output boundary
807+
assert_eq!(
808+
r.map_host_output((h_outp_node, h_port_2)).unwrap(),
809+
ReplacementPort::from((r.get_replacement_io().unwrap()[1], n_port_2))
810+
);
811+
assert!(r
812+
.map_host_output((h_outp_node, OutgoingPort::from(0)))
813+
.is_none());
814+
815+
// Check invalidation set
804816
assert_eq!(
805817
HashSet::<_>::from_iter(r.invalidation_set()),
806818
HashSet::<_>::from_iter([h_node_cx, h_node_h0, h_node_h1, h_outp_node]),
@@ -1169,7 +1181,7 @@ pub(in crate::hugr::patch) mod test {
11691181
.nodes()
11701182
.find(|node: &Node| *h.get_optype(*node) == cx_gate().into())
11711183
.unwrap();
1172-
let s: Vec<Node> = vec![h_node_cx].into_iter().collect();
1184+
let s = vec![h_node_cx];
11731185
// 2. Construct a new DFG-rooted hugr for the replacement
11741186
let n: Hugr = dfg_hugr2;
11751187
// 3. Construct the input and output matchings
@@ -1209,6 +1221,58 @@ pub(in crate::hugr::patch) mod test {
12091221
assert_eq!(h.validate(), Ok(()));
12101222
}
12111223

1224+
#[rstest]
1225+
fn test_output_boundary_map(dfg_hugr2: Hugr) {
1226+
let [inp, out] = dfg_hugr2.get_io(dfg_hugr2.root()).unwrap();
1227+
let map = [
1228+
((inp, OutgoingPort::from(0)), IncomingPort::from(0)),
1229+
((inp, OutgoingPort::from(1)), IncomingPort::from(1)),
1230+
]
1231+
.into_iter()
1232+
.collect();
1233+
let map = OutputBoundaryMap::ByOutgoing(map);
1234+
1235+
// Basic check: map as just defined
1236+
assert_eq!(
1237+
map.get(inp, OutgoingPort::from(0)),
1238+
Some(IncomingPort::from(0))
1239+
);
1240+
assert_eq!(
1241+
map.get(inp, OutgoingPort::from(1)),
1242+
Some(IncomingPort::from(1))
1243+
);
1244+
1245+
// Now check the map in terms of incoming ports
1246+
assert!(map.get(out, IncomingPort::from(0)).is_none());
1247+
assert_eq!(
1248+
map.get_as_incoming(out, IncomingPort::from(0), &dfg_hugr2),
1249+
Some(IncomingPort::from(0))
1250+
);
1251+
1252+
// Finally, check iterators
1253+
assert_eq!(
1254+
map.iter().collect::<HashSet<_>>(),
1255+
HashSet::from_iter([
1256+
(
1257+
(inp, Port::new(Direction::Outgoing, 0)),
1258+
IncomingPort::from(0)
1259+
),
1260+
(
1261+
(inp, Port::new(Direction::Outgoing, 1)),
1262+
IncomingPort::from(1)
1263+
),
1264+
])
1265+
);
1266+
let h_gate = dfg_hugr2.output_neighbours(inp).nth(1).unwrap();
1267+
assert_eq!(
1268+
map.iter_as_incoming(&dfg_hugr2).collect::<HashSet<_>>(),
1269+
HashSet::from_iter([
1270+
((out, IncomingPort::from(0)), IncomingPort::from(0)),
1271+
((h_gate, IncomingPort::from(0)), IncomingPort::from(1)),
1272+
])
1273+
);
1274+
}
1275+
12121276
use crate::hugr::patch::replace::Replacement;
12131277
fn to_replace(h: &impl HugrView<Node = Node>, s: SimpleReplacement) -> Replacement {
12141278
use crate::hugr::patch::replace::{NewEdgeKind, NewEdgeSpec};

hugr-core/src/ops/constant.rs

+26
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ pub(crate) mod test {
585585
use crate::extension::PRELUDE;
586586
use crate::std_extensions::arithmetic::int_types::ConstInt;
587587
use crate::std_extensions::collections::array::{array_type, ArrayValue};
588+
use crate::std_extensions::collections::value_array::{value_array_type, VArrayValue};
588589
use crate::{
589590
builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr},
590591
extension::{
@@ -754,6 +755,11 @@ pub(crate) mod test {
754755
ArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
755756
}
756757

758+
#[fixture]
759+
fn const_value_array_bool() -> Value {
760+
VArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
761+
}
762+
757763
#[fixture]
758764
fn const_array_options() -> Value {
759765
let some_true = Value::some([Value::true_val()]);
@@ -762,17 +768,35 @@ pub(crate) mod test {
762768
ArrayValue::new(elem_ty.into(), [some_true, none]).into()
763769
}
764770

771+
#[fixture]
772+
fn const_value_array_options() -> Value {
773+
let some_true = Value::some([Value::true_val()]);
774+
let none = Value::none(vec![bool_t()]);
775+
let elem_ty = SumType::new_option(vec![bool_t()]);
776+
VArrayValue::new(elem_ty.into(), [some_true, none]).into()
777+
}
778+
765779
#[rstest]
766780
#[case(Value::unit(), Type::UNIT, "const:seq:{}")]
767781
#[case(const_usize(), usize_t(), "const:custom:ConstUsize(")]
768782
#[case(serialized_float(17.4), float64_type(), "const:custom:json:Object")]
769783
#[case(const_tuple(), Type::new_tuple(vec![usize_t(), bool_t()]), "const:seq:{")]
770784
#[case(const_array_bool(), array_type(2, bool_t()), "const:custom:array")]
785+
#[case(
786+
const_value_array_bool(),
787+
value_array_type(2, bool_t()),
788+
"const:custom:value_array"
789+
)]
771790
#[case(
772791
const_array_options(),
773792
array_type(2, SumType::new_option(vec![bool_t()]).into()),
774793
"const:custom:array"
775794
)]
795+
#[case(
796+
const_value_array_options(),
797+
value_array_type(2, SumType::new_option(vec![bool_t()]).into()),
798+
"const:custom:value_array"
799+
)]
776800
fn const_type(
777801
#[case] const_value: Value,
778802
#[case] expected_type: Type,
@@ -792,7 +816,9 @@ pub(crate) mod test {
792816
#[case(const_serialized_usize(), const_usize())]
793817
#[case(const_tuple_serialized(), const_tuple())]
794818
#[case(const_array_bool(), const_array_bool())]
819+
#[case(const_value_array_bool(), const_value_array_bool())]
795820
#[case(const_array_options(), const_array_options())]
821+
#[case(const_value_array_options(), const_value_array_options())]
796822
// Opaque constants don't get resolved into concrete types when running miri,
797823
// as the `typetag` machinery is not available.
798824
#[cfg_attr(miri, ignore)]

hugr-core/src/std_extensions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn std_reg() -> ExtensionRegistry {
2121
collections::array::EXTENSION.to_owned(),
2222
collections::list::EXTENSION.to_owned(),
2323
collections::static_array::EXTENSION.to_owned(),
24+
collections::value_array::EXTENSION.to_owned(),
2425
logic::EXTENSION.to_owned(),
2526
ptr::EXTENSION.to_owned(),
2627
]);

hugr-core/src/std_extensions/collections.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
pub mod array;
44
pub mod list;
55
pub mod static_array;
6+
pub mod value_array;

0 commit comments

Comments
 (0)