ommx_openjij_adapter.adapter
============================

.. py:module:: ommx_openjij_adapter.adapter

.. autoapi-nested-parse::

   Direct OpenJij Adapter implementation.



Classes
-------

.. autoapisummary::

   ommx_openjij_adapter.adapter.OMMXOpenJijSAAdapter


Module Contents
---------------

.. py:class:: OMMXOpenJijSAAdapter(ommx_instance: ommx.Instance, *, beta_min: float | None = None, beta_max: float | None = None, num_sweeps: int | None = None, num_reads: int | None = None, schedule: list | None = None, initial_state: list | dict | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None)



   Implementation of :class:`ommx_openjij_adapter.OMMXOpenJijSAAdapter`.


   .. py:method:: check_applicability(ommx_instance: ommx.Instance) -> ommx.InstanceClassMembershipReport
      :classmethod:


      Check ``INPUT_CLASS`` membership without mutation.



   .. py:method:: decode(data: openjij.Response) -> ommx.Solution

      Decode sampler output and return its best feasible solution.



   .. py:method:: decode_to_samples(data: openjij.Response) -> ommx.Samples

      Convert `openjij.Response <https://openjij.github.io/OpenJij/reference/openjij/index.html#openjij.Response>`_ to :class:`ommx.Samples`

      There is a static method :meth:`decode_to_samples` that does the same thing.



   .. py:method:: decode_to_sampleset(data: openjij.Response) -> ommx.SampleSet


   .. py:method:: recommended_preparation_policy() -> ommx.PreparationPolicy
      :classmethod:


      Recommend the model changes commonly needed by OpenJij.

      The recommendation lowers every special-constraint family, converts the
      active objective to minimization, adds Integer slack while permitting an
      inequality to remain when exact equality conversion is unavailable,
      and log-encodes every used Integer variable. Both Integer slack ranges
      use 32.

      Fixed penalty magnitudes remain explicit caller parameters because
      sufficient values depend on the application. The shared ``Instance``
      owner operation validates their nonnegative-with-tolerance domain. Set
      ``fixed_penalty`` on the fresh returned policy when active constraints
      must be removed.



   .. py:method:: require_applicable(ommx_instance: ommx.Instance) -> ommx.InstanceClassMembershipReport
      :classmethod:


      Return the membership report or raise ``AdapterNotApplicableError``.



   .. py:method:: sample(ommx_instance: ommx.Instance, *, beta_min: float | None = None, beta_max: float | None = None, num_sweeps: int | None = None, num_reads: int | None = None, schedule: list | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None, diagnostics: ommx.adapter.DiagnosticsSink | None = None) -> ommx.SampleSet
      :classmethod:


      Prepare and sample an isolated copy of ``ommx_instance``.

      This obtains a fresh recommended policy. For a complete example with
      an explicit penalty weight, see
      :class:`ommx_openjij_adapter.OMMXOpenJijSAAdapter`.

      OpenJij ``initial_state`` values are defined against the solver-variable
      representation of an exact Adapter input, so they are accepted only by
      :meth:`sample_without_preparation`.



   .. py:method:: sample_without_preparation(ommx_instance: ommx.Instance, *, beta_min: float | None = None, beta_max: float | None = None, num_sweeps: int | None = None, num_reads: int | None = None, schedule: list | None = None, initial_state: list | dict | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None, diagnostics: ommx.adapter.DiagnosticsSink | None = None) -> ommx.SampleSet
      :classmethod:


      Sample an exact OpenJij Adapter input without preparing it.

      See :class:`ommx_openjij_adapter.OMMXOpenJijSAAdapter` for a complete
      example from an explicitly prepared constrained model to candidate
      evaluation and selection.

      ``initial_state`` is defined against this exact input's solver-variable
      representation.



   .. py:method:: solve(ommx_instance: ommx.Instance, *, beta_min: float | None = None, beta_max: float | None = None, num_sweeps: int | None = None, num_reads: int | None = None, schedule: list | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None, diagnostics: ommx.adapter.DiagnosticsSink | None = None) -> ommx.Solution
      :classmethod:


      Prepare, sample, and return the best feasible result.

      Selects from the obtained candidates and does not prove optimality.
      Raises :class:`ValueError` if no sampled candidate is feasible. Use
      :meth:`sample` to retain all candidates for inspection.

      OpenJij ``initial_state`` values are defined against the solver-variable
      representation of an exact Adapter input, so they are accepted only by
      :meth:`solve_without_preparation`.



   .. py:method:: solve_without_preparation(ommx_instance: ommx.Instance, *, beta_min: float | None = None, beta_max: float | None = None, num_sweeps: int | None = None, num_reads: int | None = None, schedule: list | None = None, initial_state: list | dict | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None, diagnostics: ommx.adapter.DiagnosticsSink | None = None) -> ommx.Solution
      :classmethod:


      Return the best feasible result from :meth:`sample_without_preparation`.

      Selection uses the reported objective and retained feasibility checks.
      It does not prove optimality and raises :class:`ValueError` when no
      feasible candidate was obtained. Use :meth:`sample_without_preparation`
      to inspect all candidates, as shown in
      :class:`ommx_openjij_adapter.OMMXOpenJijSAAdapter`.

      ``initial_state`` is defined against the exact Adapter input's
      solver-variable representation.



   .. py:attribute:: INPUT_CLASS
      :type:  ClassVar[ommx.InstanceClass]

      Required condition for an exact Adapter input.



   .. py:attribute:: MAX_OPENJIJ_VARIABLE_ID
      :type:  ClassVar[int]
      :value: 9223372036854775807



   .. py:attribute:: beta_max
      :type:  float | None
      :value: None


      maximum value of inverse temperature 



   .. py:attribute:: beta_min
      :type:  float | None
      :value: None


      minimal value of inverse temperature 



   .. py:attribute:: initial_state
      :type:  list | dict | None
      :value: None


      initial state (parameter only used if problem is QUBO)



   .. py:attribute:: num_reads
      :type:  int | None
      :value: None


      number of reads 



   .. py:attribute:: num_sweeps
      :type:  int | None
      :value: None


      number of sweeps 



   .. py:attribute:: ommx_instance
      :type:  ommx.Instance

      Isolated copy of the exact Adapter input used to evaluate returned samples.



   .. py:attribute:: reinitialize_state
      :type:  bool | None
      :value: None


      if true reinitialize state for each run (parameter only used if problem is QUBO)



   .. py:property:: sampler_input
      :type: dict[tuple[int, ...], float]



   .. py:attribute:: schedule
      :type:  list | None
      :value: None


      list of inverse temperature (parameter only used if problem is QUBO)



   .. py:attribute:: seed
      :type:  int | None
      :value: None


      seed for Monte Carlo algorithm 



   .. py:property:: solver_input
      :type: dict[tuple[int, ...], float]


      Expose :attr:`sampler_input` through the SolverAdapter interface.



   .. py:attribute:: sparse
      :type:  bool | None
      :value: None


      use sparse matrix or not (parameter only used if problem is QUBO)



   .. py:attribute:: updater
      :type:  str | None
      :value: None


      updater algorithm 



