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

feat(tket2-hseries): make result operation internals public #542

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
28 changes: 20 additions & 8 deletions tket2-hseries/src/extension/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ pub enum ResultOpDef {
}

impl ResultOpDef {
fn arg_type(&self) -> Type {
/// Type of the argument to the result operation.
pub fn arg_type(&self) -> Type {
match self {
Self::Bool => BOOL_T,
Self::Int | Self::UInt => int_tv(1),
Expand Down Expand Up @@ -133,7 +134,8 @@ impl ResultOpDef {
}
}

fn type_params(&self) -> Vec<TypeParam> {
/// Type parameters for result operation.
pub fn type_params(&self) -> Vec<TypeParam> {
match self {
Self::Bool | Self::F64 => vec![],
Self::Int | Self::UInt => vec![LOG_WIDTH_TYPE_PARAM],
Expand All @@ -145,7 +147,8 @@ impl ResultOpDef {
}
}

fn instantiate(&self, args: &[TypeArg]) -> Result<ResultOp, OpLoadError> {
/// Instantiate the result operation with the given type arguments.
pub fn instantiate(&self, args: &[TypeArg]) -> Result<ResultOp, OpLoadError> {
let parsed_args = concrete_result_op_type_args(args)?;

match (parsed_args, self) {
Expand Down Expand Up @@ -214,23 +217,32 @@ impl MakeOpDef for ResultOpDef {
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
enum SimpleArgs {
/// Type arguments to a numeric result operation (not an array).
pub enum SimpleArgs {
/// No type arguments, simple result type.
Basic,
/// Integer type argument, specifying bit width.
Int(u8),
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
enum ResultArgs {
/// Arguments to a "tket2.result" operation.
pub enum ResultArgs {
/// Simple result type, not an array.
Simple(SimpleArgs),
/// Argument for array result type, with inner type arguments and array size.
Array(SimpleArgs, u64),
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
/// Concrete instantiation of a "tket2.result" operation.
pub struct ResultOp {
tag: String,
result_op: ResultOpDef,
args: ResultArgs,
/// Static string tag for the result.
pub tag: String,
/// The result operation definition.
pub result_op: ResultOpDef,
/// Type arguments for the result operation.
pub args: ResultArgs,
}

impl ResultOp {
Expand Down
Loading