loom.executor.eka_circuit_to_cudaq_converter

Copyright (c) Entropica Labs Pte Ltd 2025.

Use, distribution and reproduction of this program in its source or compiled form is prohibited without the express written consent of Entropica Labs Pte Ltd.

class loom.executor.eka_circuit_to_cudaq_converter.Converter[source]

Bases: ABC

!!! This class is meant to be replaced by some similar construction when refactoring Executor !!!

Abstract base class for converting EKA circuits to a specific format. This class defines the required quantum operations and provides a method to validate that the converter supports all the required operations. Subclasses must implement the abstract methods to provide the actual conversion logic.

Properties

q_op_single_qbit_gatedict

Mapping of single qubit gate operations.

q_op_two_qbit_gatedict

Mapping of two qubit gate operations.

q_op_resetdict

Mapping of reset operations.

q_op_measdict

Mapping of measurement operations.

q_op_miscdict

Miscellaneous quantum operations that do not fit into the other categories.

quantum_operations_mapdict

Unified operations map from all categories, excluding classically controlled operations.

classically_controlled_operationsdict

Combined classically controlled operations from both single and two qubit gates.

operations_mapdict

A unified operations map from all categories, combining single qubit gates, two qubit gates, reset operations, measurement operations, and miscellaneous operations.

raises TypeError:

If the mapping is not a dict.

raises ValueError:

If the mapping is missing any of the required keys.

Ensure that the converter support all the required quantum operations

REQUIRED_CLASSICALLY_CONTROLLED_OPERATIONS = {'classically_controlled_cnot', 'classically_controlled_cx', 'classically_controlled_cy', 'classically_controlled_cz', 'classically_controlled_h', 'classically_controlled_i', 'classically_controlled_phase', 'classically_controlled_phaseinv', 'classically_controlled_reset', 'classically_controlled_reset_+', 'classically_controlled_reset_+i', 'classically_controlled_reset_-', 'classically_controlled_reset_-i', 'classically_controlled_reset_0', 'classically_controlled_reset_1', 'classically_controlled_swap', 'classically_controlled_x', 'classically_controlled_y', 'classically_controlled_z'}
REQUIRED_Q_OP_MEAS = {'measure_x', 'measure_y', 'measure_z', 'measurement'}
REQUIRED_Q_OP_MISC = {}
REQUIRED_Q_OP_RESET = {'reset', 'reset_+', 'reset_+i', 'reset_-', 'reset_-i', 'reset_0', 'reset_1'}
REQUIRED_Q_OP_SINGLE_QBIT_GATE = {'h', 'i', 'phase', 'phaseinv', 'x', 'y', 'z'}
REQUIRED_Q_OP_TWO_QBIT_GATE = {'cnot', 'cx', 'cy', 'cz', 'swap'}
abstract property classically_controlled_operations: dict[str, Any]

Mapping of classically controlled two qubit gate operations

abstractmethod convert(input)[source]

Convert and InterpretationStep.

Return type:

Any

abstractmethod convert_circuit(input)[source]

Convert a Circuit.

Return type:

Any

property operations_map: dict[str, Any]

Unified operations map from all categories, including classically controlled operations.

abstract property q_op_meas: dict[str, Callable]

Mapping of measurement operations

abstract property q_op_misc: dict[str, Callable]

Miscellaneous quantum operations that do not fit into the other categories.

abstract property q_op_reset: dict[str, tuple[Callable, ...]]

Mapping of reset operations

abstract property q_op_single_qbit_gate: dict[str, Callable]

Mapping of single qubit gate operations

abstract property q_op_two_qbit_gate: dict[str, Callable]

Mapping of two qubit gate operations

property quantum_operations_map: dict[str, Callable]

Unified operations map from all categories.

class loom.executor.eka_circuit_to_cudaq_converter.EkaToCudaqConverter[source]

Bases: Converter

Converter for EKA circuits to cudaq kernels.

Ensure that the converter support all the required quantum operations

KernelCallable

alias of Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]

property classically_controlled_operations: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Mapping of classically controlled two qubit gate operations, which includes single qubit gates, two qubit gates, reset operations, measurement operations, and miscellaneous operations. The first given classical channel is the control channel, and the rest are forwarded as the target channels.

convert(input)[source]

Convert an InterpretationStep to a cudaq kernel. For now it just calls convert_circuit on the final circuit of the InterpretationStep.

Return type:

Tuple[kernel, dict[str, QuakeValue], dict[str, QuakeValue | None]]

convert_circuit(input)[source]

Convert a Circuit to a cudaq kernel. :type input: Circuit :param input: The input circuit to convert. :type input: Circuit

Return type:

tuple[kernel, dict[str, QuakeValue], dict[str, QuakeValue | None]]

Returns:

  • cudaq.kernel – The converted cudaq kernel.

  • dict[str, cudaq.QuakeValue] – A dictionary mapping quantum channel IDs to their allocated registers.

  • dict[str, cudaq.QuakeValue | None] – A dictionary mapping classical channel IDs to their allocated registers. If a classical channel is not allocated, its value will be None.

Raises:
  • TypeError – If the input is not a Circuit.

  • ValueError – If the input circuit is empty or does not contain any quantum channels.

static get_outcomes_parity(cbits, simulation_output)[source]

Get the parity of the outcomes of multiple measurements from the simulation output. The parity is the xor of all outcomes.

Parameters:
  • cbits (List[Cbit]) – The list of cbits to get the outcomes for.

  • simulation_output (cudaq.SampleResult) – The simulation output containing the measurement results.

  • shot_idx (int, optional) – The index of the shot to get the outcome for. If None, a list with outcomes for all shots is returned.

Returns:

The parity of the outcomes for each shot of the simulation output.

Return type:

list[int]

property q_op_meas: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Mapping of measurement operations

property q_op_misc: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Miscellaneous quantum operations that do not fit into the other categories.

property q_op_reset: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Mapping of reset operations

property q_op_single_qbit_gate: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Mapping of single qubit gate operations

property q_op_two_qbit_gate: dict[str, Callable[[PyKernel, list[tuple[str, str, QuakeValue]], list[tuple[str, str, QuakeValue]]], Any]]

Mapping of two qubit gate operations