From 886744be7f33c8da32c7176de8c495d72057c8ef Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Tue, 11 Nov 2025 12:34:27 +0000 Subject: [PATCH] Treat LoadConstant as transparent only if Const encoded --- tket/src/serialize/pytket/encoder.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tket/src/serialize/pytket/encoder.rs b/tket/src/serialize/pytket/encoder.rs index e2e4b93d3..6c294e834 100644 --- a/tket/src/serialize/pytket/encoder.rs +++ b/tket/src/serialize/pytket/encoder.rs @@ -885,19 +885,21 @@ impl PytketEncoderContext { } } OpType::LoadConstant(constant) => { - // If we are loading a supported type, emit a transparent node - // by reassigning the input values to the new outputs. - // - // Otherwise, if we're loading an unsupported type, this node - // should be part of an unsupported subgraph. + let cst = circ + .hugr() + .single_linked_output(node, constant.constant_port()) + .expect("LoadConstant must have a linked Const"); + // Check if the Const was successfully encoded if self - .config() - .type_to_pytket(constant.constant_type()) + .values + .peek_wire_values(Wire::new(cst.0, cst.1)) .is_some() { self.emit_transparent_node(node, circ, |ps| ps.input_params.to_owned())?; return Ok(EncodeStatus::Success); } + // Otherwise (inc. if we're loading an unsupported type), this node + // should be part of an unsupported subgraph. } OpType::Const(op) => { let config = Arc::clone(&self.config);