loom.executor.converter

Copyright 2024 Entropica Labs Pte Ltd

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str
class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str
class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str
class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str
class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str
class loom.executor.converter.Converter(**data)[source]

Bases: ABC, BaseModel, Generic[TargetType, TargetRunResultType]

Abstract base class for converting Eka circuits and experiments to a specific format.

This class defines the structure for converters that can transform Eka operations into a target language or format. Subclasses must implement the abstract methods to provide the actual conversion logic. And functions to evaluate the output format in terms of Eka language.

SUPPORTED_OPERATIONS

A set of all supported quantum operations.

Type:

list[OpSignature]

ALLOW_ERROR_MODELS

Flag indicating whether the converter allows error models to be passed during conversion.

Type:

bool

Properties
----------
operations_map

A mapping of the supported operations to their corresponding implementation functions in the target language.

Type:

dict[OpSignature, OpAndTargetToInstrCallable]

eka_op_by_name

A mapping of operation names to corresponding OpSignature objects.

Type:

dict[str, OpSignature]

convert(interpreted_eka: InterpretationStep) Any[source]

Convert the input interpretation step to a specific format.

convert_circuit(input_circuit: Circuit) Any[source]

Convert a Circuit to a specific format.

parse_target_run_outcome(run_output: TargetRunResultType) dict[str, list[int]][source]

Parse the run output of the target language into a dictionary mapping the Eka channel labels to integer values measured at each shot.

emit_circuit_program(

input_circuit: Circuit, q_register: dict[str, Any], c_register: dict[str, Any],

) -> str

Emit the full program string for a given circuit, given some quantum and classical register mappings.

emit_init_instructions(

circuit: Circuit

) -> tuple[str, dict[str, Any], dict[str, Any]]

Provide the code to initialize the quantum and classical registers, and return the mapping from Eka channel id to register.

emit_leaf_circuit_instruction(

circuit: Circuit, quantum_channel_map: dict[str, Any], classical_channel_map: dict[str, Any],

) -> str

Provide the code to emit an Eka instruction in the target language.

Raises:
  • TypeError – If the mapping is not a dict.

  • ValueError – If the mapping is missing any of the required keys.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

ALLOW_ERROR_MODELS: bool
SUPPORTED_OPERATIONS: frozenset[OpSignature]
convert(interpreted_eka)[source]

Convert a InterpretationStep. By default, it converts the final circuit of the step. This can differ from convert_circuit for converters that support detector and observable objects (like Stim).

Return type:

TypeVar(TargetType)

abstractmethod convert_circuit(input_circuit)[source]

Convert a Circuit into a program in the target language.

Return type:

TypeVar(TargetType)

emit_circuit_program(input_circuit, q_register, c_register)[source]

Emit the full program string for a given circuit, given some quantum and classical register mappings.

This method process the circuit in a depth-first manner, handling nested circuits and control flow constructs (if-else) appropriately. It uses a stack to keep track of circuits to process, and maintains an indentation level for formatting the output.

Parameters:
  • input_circuit (Circuit) – The input circuit to emit the program for.

  • q_register (dict[str, str]) – The mapping from eka quantum channel ids to target quantum register names.

  • c_register (dict[str, str | None]) – The mapping from eka classical channel ids to target classical register names.

Returns:

The emitted program as a string.

Return type:

str

abstractmethod emit_init_instructions(circuit)[source]

Provide the python code (as a string) to initializes the quantum and classical registers, and return the mapping from eka channel id to register.

Return type:

tuple[str, dict[str, Any], dict[str, Any]]

abstractmethod emit_leaf_circuit_instruction(circuit, quantum_channel_map, classical_channel_map)[source]

Provide the python code (as a string) to emit an Eka instruction in the target language.

Return type:

str

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ALLOW_ERROR_MODELS': FieldInfo(annotation=bool, required=False, default=False), 'SUPPORTED_OPERATIONS': FieldInfo(annotation=frozenset[OpSignature], required=True), 'separator_for_else_in_condition': FieldInfo(annotation=str, required=False, default=', is_else=', description='The separator string used in the description for else conditions.', frozen=True, init=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property op_by_eka_name: dict[str, OpSignature]

Map of operation names to corresponding OpSignature objects.

abstract property operations_map: dict[str, Callable[[list[str], list[str], str | None], str]]

Returns a mapping of the supported operations to their corresponding instructions in the target language.

abstractmethod static parse_target_run_outcome(run_output)[source]

Parse the run output of the target language into a dictionary mapping the eka channel labels to values measured at each shot.

Return type:

dict[str, int | list[int]]

separator_for_else_in_condition: str