Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7d9b457
feat: pytket EncodedCircuit struct that keeps links back to the Hugr
aborgna-q Oct 2, 2025
a3a7f5b
docs
aborgna-q Oct 8, 2025
1dbdd5e
Add IntoIterator trait impls
aborgna-q Oct 8, 2025
618e702
More structured definition of a barrier payload, better encode errors
aborgna-q Oct 13, 2025
09c8664
fix docs
aborgna-q Oct 13, 2025
1d11e10
Some post-review fixes
aborgna-q Oct 16, 2025
dce67b2
Merge both opaque hugr TKET opgroups
aborgna-q Oct 17, 2025
25d0452
Rename Standalone payloads to Inline
aborgna-q Oct 17, 2025
dc01f00
Globally unique SubgraphIds without hashing
aborgna-q Oct 17, 2025
9217a12
Rename UnsupportedSubgraph -> OpaqueSubgraph
aborgna-q Oct 17, 2025
2eee6fe
feat!: Add original circuit/subgraphs in pytket DecoderCtx
aborgna-q Oct 13, 2025
70044b1
wip: Decode unsupported subgraphs
aborgna-q Oct 13, 2025
f385e6c
Make subgraphs refer to nodes in the _hugr being constructed_
aborgna-q Oct 24, 2025
7bc5c47
Address review comments
aborgna-q Oct 27, 2025
962c70e
fix docs
aborgna-q Oct 27, 2025
06a2c8d
feat: reassemble_inline reads subgraphs from target hugr
aborgna-q Oct 28, 2025
bf39546
Actually replant the external subgraphs
aborgna-q Oct 29, 2025
755b165
Green light?
aborgna-q Oct 29, 2025
a6adaf4
Test standalone circ roundtrip with unsupported graph, and test errors
aborgna-q Oct 30, 2025
619def5
more tests
aborgna-q Oct 30, 2025
29f4d1a
more tests
aborgna-q Oct 30, 2025
fc08dfc
more tests, and fixes
aborgna-q Oct 30, 2025
52ced5a
Mark LoadConstant of unsupported types as unsupported
aborgna-q Oct 31, 2025
1cb90f7
Update links in TODOs
aborgna-q Oct 31, 2025
6bd243f
Add integration test in tket1-passes
aborgna-q Oct 31, 2025
3ab8a7c
Post-rebase fix
aborgna-q Oct 31, 2025
ce5a9a2
Multithreaded opt in integration test
aborgna-q Oct 31, 2025
19afa3f
Some attribute tests
aborgna-q Oct 31, 2025
4512452
Review comments
aborgna-q Nov 4, 2025
ab41eb2
clippy
aborgna-q Nov 4, 2025
c31b6af
Merge remote-tracking branch 'origin/main' into ab/encoded-circuit
aborgna-q Nov 4, 2025
5fe1846
Read `extra_subgraph` and some more code cleanups
aborgna-q Nov 4, 2025
76c8cef
Enable extra_subgraph test, add another to-be-fixed test
aborgna-q Nov 4, 2025
c78a23d
review comments
aborgna-q Nov 5, 2025
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tket/src/passes/pytket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hugr::algorithms::untuple::{UntupleError, UntupleRecursive};
use hugr::algorithms::{ComposablePass, UntuplePass};
use hugr::{HugrView, Node};

use crate::serialize::pytket::OpConvertError;
use crate::serialize::pytket::PytketEncodeOpError;
use crate::Circuit;

/// Try to lower a circuit to a form that can be encoded as a pytket legacy circuit.
Expand All @@ -33,7 +33,7 @@ pub enum PytketLoweringError {
/// An error occurred during the conversion of an operation.
#[display("operation conversion error: {_0}")]
#[from]
OpConversionError(OpConvertError),
OpConversionError(PytketEncodeOpError),
/// The circuit is not fully-contained in a region.
/// Function calls are not supported.
#[display("Non-local operations found. Function calls are not supported.")]
Expand Down
43 changes: 16 additions & 27 deletions tket/src/serialize/pytket.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
//! Serialization and deserialization of circuits using the `pytket` JSON format.

mod circuit;
mod config;
pub mod decoder;
pub mod encoder;
mod error;
pub mod extension;
pub mod opaque;
mod options;

pub use circuit::EncodedCircuit;
pub use config::{
default_decoder_config, default_encoder_config, PytketDecoderConfig, PytketEncoderConfig,
TypeTranslatorSet,
};
pub use encoder::PytketEncoderContext;
pub use error::{OpConvertError, PytketDecodeError, PytketDecodeErrorInner, PytketEncodeError};
pub use error::{
PytketDecodeError, PytketDecodeErrorInner, PytketEncodeError, PytketEncodeOpError,
};
pub use extension::PytketEmitter;
pub use options::{DecodeInsertionTarget, DecodeOptions, EncodeOptions};

use hugr::hugr::hugrmut::HugrMut;
use hugr::ops::handle::NodeHandle;
use hugr::{Hugr, Node};

#[cfg(test)]
mod tests;

Expand All @@ -31,9 +35,8 @@ use std::{fs, io};
use tket_json_rs::circuit_json::SerialCircuit;
use tket_json_rs::register::{Bit, ElementId, Qubit};

use crate::circuit::Circuit;

use self::decoder::PytketDecoderContext;
use crate::circuit::Circuit;

pub use crate::passes::pytket::lower_to_pytket;

Expand Down Expand Up @@ -114,7 +117,11 @@ impl TKETDecode for SerialCircuit {

fn decode(&self, options: DecodeOptions) -> Result<Circuit, Self::DecodeError> {
let mut hugr = Hugr::new();
let main_func = self.decode_inplace(&mut hugr, DecodeInsertionTarget::Function, options)?;
let main_func = self.decode_inplace(
&mut hugr,
DecodeInsertionTarget::Function { fn_name: None },
options,
)?;
hugr.set_entrypoint(main_func);
Ok(hugr.into())
}
Expand All @@ -125,32 +132,14 @@ impl TKETDecode for SerialCircuit {
target: DecodeInsertionTarget,
options: DecodeOptions,
) -> Result<Node, Self::DecodeError> {
let config = options
.config
.unwrap_or_else(|| default_decoder_config().into());

let mut decoder = PytketDecoderContext::new(
self,
hugr,
target,
options.fn_name,
options.signature,
options.input_params,
config,
)?;
decoder.run_decoder(&self.commands)?;
let mut decoder = PytketDecoderContext::new(self, hugr, target, options, None)?;
decoder.run_decoder(&self.commands, None)?;
Ok(decoder.finish()?.node())
}

fn encode(circuit: &Circuit, options: EncodeOptions) -> Result<Self, Self::EncodeError> {
let config = options
.config
.unwrap_or_else(|| default_encoder_config().into());
let region = circuit.parent();
let mut encoder = PytketEncoderContext::new(circuit, region, config)?;
encoder.run_encoder(circuit, region)?;
let (serial, _) = encoder.finish(circuit, region)?;
Ok(serial)
let mut encoded = EncodedCircuit::new_standalone(circuit, options)?;
Ok(std::mem::take(&mut encoded[circuit.parent()]))
}
}

Expand Down
Loading
Loading