core.converters.converter#
qamomile/core/converter.py
This module defines the QuantumConverter abstract base class for converting between different problem representations and quantum models in Qamomile.
The QuantumConverter class provides a framework for encoding classical optimization problems into quantum representations (e.g., Ising models) and decoding quantum computation results back into classical problem solutions.
Key Features:
Conversion between classical optimization problems and Ising models.
Abstract methods for generating cost Hamiltonians and decoding results.
Integration with QuantumSDKTranspiler for SDK-specific result handling.
Usage:
Developers implementing specific quantum conversion strategies should subclass QuantumConverter and implement the abstract methods. The class is designed to work with jijmodeling for problem representation and various quantum SDKs through the QuantumSDKTranspiler interface.
Example
class QAOAConverter(QuantumConverter):
def get_cost_hamiltonian(self) -> qm_o.Hamiltonian:
# Implementation for generating QAOA cost Hamiltonian
...
Attributes#
Classes#
Abstract base class for quantum problem converters in Qamomile. |
Functions#
|
Decode binary results into a SampleSet. |
Module Contents#
- ResultType#
- class QuantumConverter(compiled_instance, relax_method: jijmodeling_transpiler.core.pubo.RelaxationMethod = jmt.pubo.RelaxationMethod.AugmentedLagrangian, normalize_model: bool = False, normalize_ising: Literal['abs_max', 'rms'] | None = None)#
Bases:
abc.ABC
Abstract base class for quantum problem converters in Qamomile.
This class provides methods for encoding classical optimization problems into quantum representations (e.g., Ising models) and decoding quantum computation results back into classical problem solutions.
- compiled_instance#
The compiled instance of the optimization problem.
- pubo_builder#
The PUBO (Polynomial Unconstrained Binary Optimization) builder.
- _ising#
Cached Ising model representation.
- Type:
Optional[IsingModel]
- get_ising()#
Retrieve or compute the Ising model representation.
- ising_encode()#
Encode the problem into an Ising model.
- get_cost_hamiltonian()#
Abstract method to get the cost Hamiltonian.
- decode()#
Decode quantum computation results into a SampleSet.
- decode_bits_to_sampleset()#
Abstract method to convert BitsSampleSet to SampleSet.
Initialize the QuantumConverter.
This method initializes the converter with the compiled instance of the optimization problem
- Parameters:
compiled_instance – The compiled instance of the optimization problem.
relax_method (jmt.pubo.RelaxationMethod) – The relaxation method for PUBO conversion. Defaults to AugmentedLagrangian.
normalize_model (bool) – The objective function and the constraints are normalized using the maximum absolute value of the coefficients contained in each. Defaults to False
normalize_ising (Literal["abs_max", "rms"] | None) – The normalization method for the Ising Hamiltonian. Available options: - “abs_max”: Normalize by absolute maximum value - “rms”: Normalize by root mean square Defaults to None.
- compiled_instance#
- pubo_builder#
- int2varlabel: dict[int, str]#
- normalize_ising = None#
- get_ising() qamomile.core.ising_qubo.IsingModel #
Get the Ising model representation of the problem.
- Returns:
The Ising model representation.
- Return type:
- ising_encode(multipliers: dict[str, float] | None = None, detail_parameters: dict[str, dict[tuple[int, Ellipsis], tuple[float, float]]] | None = None) qamomile.core.ising_qubo.IsingModel #
Encode the problem to an Ising model.
This method converts the problem from QUBO (Quadratic Unconstrained Binary Optimization) to Ising model representation.
- Parameters:
multipliers (Optional[dict[str, float]]) – Multipliers for constraint terms.
detail_parameters (Optional[dict[str, dict[tuple[int, ...], tuple[float, float]]]]) – Detailed parameters for the encoding process.
- Returns:
The encoded Ising model.
- Return type:
- abstract get_cost_hamiltonian() qamomile.core.operator.Hamiltonian #
Abstract method to get the cost Hamiltonian for the quantum problem.
This method should be implemented in subclasses to define how the cost Hamiltonian is constructed for specific quantum algorithms.
- Returns:
The cost Hamiltonian for the quantum problem.
- Return type:
qm_o.Hamiltonian
- Raises:
NotImplementedError – If the method is not implemented in the subclass.
- decode(transpiler: qamomile.core.transpiler.QuantumSDKTranspiler[ResultType], result: ResultType) jijmodeling.experimental.SampleSet #
Decode quantum computation results into a SampleSet.
This method uses the provided transpiler to convert SDK-specific results into a BitsSampleSet, then calls decode_bits_to_sampleset to produce the final SampleSet.
- Parameters:
transpiler (QuantumSDKTranspiler[ResultType]) – The transpiler for the specific quantum SDK.
result (ResultType) – The raw result from the quantum computation.
- Returns:
The decoded results as a SampleSet.
- Return type:
jm.experimental.SampleSet
- decode_bits_to_sampleset(bitssampleset: qamomile.core.bitssample.BitsSampleSet) jijmodeling.experimental.SampleSet #
Decode a BitArraySet to a SampleSet.
This method converts the quantum computation results (bitstrings) into a format that represents solutions to the original optimization problem.
- Parameters:
bitarray_set (qm_c.BitArraySet) – The set of bitstring results from quantum computation.
- Returns:
The decoded results as a SampleSet.
- Return type:
jm.experimental.SampleSet
- decode_from_dict_binary_result(samples: Iterable[dict[int, int | float]], binary_encoder, compiled_model: jijmodeling_transpiler.core.CompiledInstance) jijmodeling.SampleSet #
Decode binary results into a SampleSet.
- Parameters:
samples – Iterable of sample dictionaries.
binary_encoder – Binary encoder from jijmodeling_transpiler.
compiled_model – Compiled instance of the optimization problem.
- Returns:
Decoded sample set.
- Return type:
jm.SampleSet