Skip to main content
Ctrl+K
Qamomile Documentation - Home
  • Qamomileへようこそ

Switch Language

  • English

Getting Started

  • Qamomileクイックスタートガイド

Basic Usage of the Library

  • ライブラリの基本的な使い方
    • 量子回路の構築
    • ハミルトニアンを代数的に記述する
    • QamomileにおけるQiskitTranspilerの使用方法
    • QamomileにおけるQuriPartsTranspilerの使用方法
    • QamomileにおけるPennyLaneTranspilerの使用
    • QamomileにおけるQuTiPTranspilerの使用方法
    • 中性原子量子コンピュータ上の単位円グラフを用いたQUBO/イジング問題の解法

Solving Problems with QAOA

  • QAOA による問題解決
    • 量子近似最適化アルゴリズム (QAOA)
    • Max-Cut問題
    • グラフ分割問題
    • 頂点被覆問題
    • 2色のマルチカー塗装工場問題
    • 巡回セールスマン問題
    • グラフ彩色問題

Advanced techniques for Quantum Optimization

  • 量子最適化のための高度な手法
    • Quantum Alternating Operator Ansatzによるグラフ彩色問題
    • Maxcut 問題に対する量子ランダムアクセス最適化(QRAO)

Quantum Chemistry

  • 量子化学
    • 水素分子のための変分量子固有値ソルバー(VQE)

API Reference

  • API Reference
    • udm
      • udm.copyline
      • udm.core
      • udm.mwis_solver
      • udm.transpiler
      • udm.utils
    • core
      • core.ansatz
        • core.ansatz.efficient_su2
      • core.bitssample
      • core.circuit
        • core.circuit.circuit
        • core.circuit.drawer
        • core.circuit.parameter
      • core.converters
        • core.converters.converter
        • core.converters.qaoa
        • core.converters.qrao
        • core.converters.utils
      • core.ising_qubo
      • core.modeler
        • core.modeler.hamiltonian_expr
        • core.modeler.pauli_expr
      • core.operator
      • core.post_process
        • core.post_process.local_search
      • core.transpiler
    • cudaq
      • cudaq.exceptions
      • cudaq.parameter_converter
      • cudaq.transpiler
    • qutip
      • qutip.exceptions
      • qutip.transpiler
    • qiskit
      • qiskit.exceptions
      • qiskit.parameter_converter
      • qiskit.transpiler
    • pennylane
      • pennylane.exceptions
      • pennylane.transpiler
    • quri_parts
      • quri_parts.exceptions
      • quri_parts.parameter_converter
      • quri_parts.transpiler
  • Repository
  • Open issue
  • .rst

core.post_process.local_search

Contents

  • Classes
  • Module Contents
    • IsingMatrix
      • IsingMatrix.quad
      • IsingMatrix.linear
      • IsingMatrix.to_ising_matrix()
      • IsingMatrix.calc_E_diff()
      • IsingMatrix.to_ising_matrix()
      • IsingMatrix.calc_E_diff()
    • LocalSearch
      • LocalSearch.converter
      • LocalSearch.ising
      • LocalSearch.decode()
      • LocalSearch.first_improvement()
      • LocalSearch.best_improvement()
      • LocalSearch.run()
      • LocalSearch.converter
      • LocalSearch.ising
      • LocalSearch.decode()
      • LocalSearch.first_improvement()
      • LocalSearch.best_improvement()
      • LocalSearch.run()

core.post_process.local_search#

qamomile/core/post_process.py

This module provides functionality for Local Search Algorithm. Local Search Algorithm is one of the simplest heuristic algorithms for the optimization problem. You can apply the local search to the following Ising Hamiltonian.

\[\begin{split}\sum_{ij} J_{ij} z_i z_j + \sum_i h_i z_i, \\ \text{s.t.}~z_i \in \{-1, 1\}\end{split}\]

Key Features:

  • Implementation of first- and best-improvement local search algorithms

  • Construction of cost Hamiltonians for the Ising model

  • Conversion of Ising interactions from dictionary format to matrix form

Classes#

IsingMatrix

A class to represent the Ising model in matrix form.

LocalSearch

A class to perform local search algorithms on Ising models.

Module Contents#

class IsingMatrix(quad: numpy.ndarray | None = None, linear: numpy.ndarray | None = None)#

A class to represent the Ising model in matrix form.

quad#

The interaction terms between spin variables in the Ising model.

Type:

np.ndarray

linear#

The external magnetic fields or self-interaction applied to each spin in the Ising model

Type:

np.ndarray

to_ising_matrix()#

Converts an Ising model into its corresponding matrix form.

calc_E_diff()#

Calculates the change in energy if a specific bit is flipped.

Initializes an IsingMatrix instance.

Parameters:
  • quad (Optional[np.ndarray]) – Quadratic term matrix representing the interaction term.

  • linear (Optional[np.ndarray]) – Linear term vector representing the self-interaction term.

to_ising_matrix(ising: qamomile.core.ising_qubo.IsingModel) → IsingMatrix#

Converts an IsingModel into matrix form with quadratic and linear components.

Parameters:

ising (IsingModel) – The Ising model to be converted.

Returns:

The converted Ising model in matrix form.

Return type:

IsingMatrix

calc_E_diff(state: numpy.ndarray, l: int) → float#

Calculates the energy difference when flipping a bit in the Ising state.

Parameters:
  • state (np.ndarray) – The current state of the Ising model.

  • l (int) – Index of the bit to be flipped.

Returns:

The difference in energy due to flipping the specified bit.

Return type:

float

class LocalSearch(converter: qamomile.core.converters.converter.QuantumConverter)#

A class to perform local search algorithms on Ising models.

converter#

The converter should be an implementation of the QuantumConverter abstract class, allowing the optimization problem to be encoded as an Ising model.

Type:

QuantumConverter

ising#

The encoded Ising model to be optimized.

Type:

IsingModel

decode()#

Decodes the final solution from Ising spin state to jijmodeling SampleSet.

first_improvement()#

Performs first-improvement local search.

best_improvement()#

Performs best-improvement local search.

run()#

Runs the local search algorithm with a specified method.

Initializes a LocalSearch instance with a quantum converter.

Parameters:

converter (QuantumConverter) – A converter used to encode optimization problems to Ising form.

converter#
ising#
decode(result) → ommx.v1.SampleSet#

Decodes the result obtained from a local search into a jijmodeling SampleSet.

Parameters:

result (np.ndarray) – The final state of the Ising model after local search.

Returns:

The decoded results.

Return type:

ommx.v1.SampleSet

first_improvement(ising_matrix: IsingMatrix, current_state: numpy.ndarray, N: int) → numpy.ndarray#

Performs first-improvement local search on the Ising model.

The first-improvement local search method iteratively examines each bit in the current state of the Ising model to determine if flipping that bit will reduce the system’s energy. If a bit flip results in an energy decrease, the flip is accepted immediately, and the algorithm moves to the next bit. This process continues until all bits have been evaluated once.

Parameters:
  • ising_matrix (IsingMatrix) – The Ising matrix representation of the problem.

  • current_state (np.ndarray) – The current state of the Ising model.

  • N (int) – Number of bits in the state.

Returns:

The updated state after attempting to find an improving move.

Return type:

np.ndarray

best_improvement(ising_matrix: IsingMatrix, current_state: numpy.ndarray, N: int) → numpy.ndarray#

Performs best-improvement local search on the Ising model.

The best-improvement local search method examines all possible bit flips in the current state of the Ising model to determine which single bit flip would result in the greatest decrease in energy. It then flips the bit that leads to the most significant energy reduction, provided there is at least one such improvement. If no flip results in a reduction in energy, the state remains unchanged.

Parameters:
  • ising_matrix (IsingMatrix) – The Ising matrix representation of the problem.

  • current_state (np.ndarray) – The current state of the Ising model.

  • N (int) – Number of bits in the state.

Returns:

The updated state after attempting to find the best improving move.

Return type:

np.ndarray

run(initial_state: numpy.ndarray, max_iter: int = -1, local_search_method: str = 'best_improvement') → ommx.v1.SampleSet#

Runs the local search algorithm until convergence or until a maximum number of iterations.

Parameters:
  • initial_state (np.ndarray) – The initial state to start the local search from.

  • max_iter (int) – Maximum number of iterations to run the local search. Defaults to -1 (no limit).

  • local_search_method (str) – Method of local search (“best_improvement” or “first_improvement”). Defaults to “best_improvement”.

Returns:

The decoded solution after the local search.

Return type:

ommx.v1.SampleSet

previous

core.post_process

next

core.transpiler

Contents
  • Classes
  • Module Contents
    • IsingMatrix
      • IsingMatrix.quad
      • IsingMatrix.linear
      • IsingMatrix.to_ising_matrix()
      • IsingMatrix.calc_E_diff()
      • IsingMatrix.to_ising_matrix()
      • IsingMatrix.calc_E_diff()
    • LocalSearch
      • LocalSearch.converter
      • LocalSearch.ising
      • LocalSearch.decode()
      • LocalSearch.first_improvement()
      • LocalSearch.best_improvement()
      • LocalSearch.run()
      • LocalSearch.converter
      • LocalSearch.ising
      • LocalSearch.decode()
      • LocalSearch.first_improvement()
      • LocalSearch.best_improvement()
      • LocalSearch.run()

By Jij Inc.

© Copyright 2023.