ommx_openjij_adapter
====================

.. py:module:: ommx_openjij_adapter


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/ommx_openjij_adapter/adapter/index


Exceptions
----------

.. autoapisummary::

   ommx_openjij_adapter.OpenJijPreparationError


Classes
-------

.. autoapisummary::

   ommx_openjij_adapter.OMMXOpenJijSAAdapter
   ommx_openjij_adapter.OpenJijPreparation
   ommx_openjij_adapter.OpenJijPreparationConfig
   ommx_openjij_adapter.OpenJijPreparationFailure
   ommx_openjij_adapter.OpenJijPreparationReport
   ommx_openjij_adapter.OpenJijPreparationSourceCheck
   ommx_openjij_adapter.OpenJijPreparationStep


Functions
---------

.. autoapisummary::

   ommx_openjij_adapter.decode_to_samples


Package Contents
----------------

.. py:exception:: OpenJijPreparationError(report: OpenJijPreparationReport)



   Raised when explicit OpenJij preparation cannot produce an input.


   .. py:attribute:: report
      :type:  OpenJijPreparationReport


.. 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)



   Sample an applicable Binary polynomial input with OpenJij simulated annealing.

   The direct Adapter input must use only Binary decision variables, have
   no active regular or special constraints, and be a minimization problem.
   Arbitrary polynomial objective degree is supported through OpenJij's QUBO
   and Binary-HUBO paths.

   Integer encoding, sense reversal, slack introduction, and finite constraint
   penalties are explicit preparation operations, not part of the declared
   input class. Pass :attr:`OpenJijPreparation.input` back to this Adapter
   as a separate :class:`ommx.Instance` value.


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


      Inspect applicability without mutating or preparing ``ommx_instance``.

      Adapter-specific preconditions run only after at least one complete
      input-class clause contains the instance. The hook receives an isolated
      copy so it cannot mutate the caller's instance. Any explicitly
      transformed value is a different input and must be checked separately.



   .. py:method:: check_preparation(ommx_instance: ommx.Instance, *, config: ommx_openjij_adapter._preparation.OpenJijPreparationConfig | None = None) -> ommx_openjij_adapter._preparation.OpenJijPreparationReport
      :classmethod:


      Dry-run the complete explicit preparation without mutating the input.

      This is intentionally separate from :meth:`check_applicability`, which
      checks only the Binary, unconstrained minimization Adapter input. The
      53-bit log-encoding limit describes availability of that preparation
      operation, not an OpenJij input-class condition and not an
      ``ommx.v2.Feature``. A model proven infeasible while preparing integer
      slack raises :class:`~ommx.InfeasibleDetected`. Approximate integer
      slack is disabled unless the supplied
      :class:`OpenJijPreparationConfig` enables it.



   .. py:method:: decode(data: openjij.Response) -> ommx.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:`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:: prepare(ommx_instance: ommx.Instance, *, config: ommx_openjij_adapter._preparation.OpenJijPreparationConfig | None = None) -> ommx_openjij_adapter._preparation.OpenJijPreparation
      :classmethod:


      Produce a separate Adapter input and an auditable preparation report.

      Raises :class:`~ommx.InfeasibleDetected` when variable bounds
      prove an inequality infeasible. Other preparation failures raise
      :class:`OpenJijPreparationError`. Approximate integer slack is used only
      when the supplied :class:`OpenJijPreparationConfig` enables it.



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


      Return the report or raise :class:`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, 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 the exact applicable ``ommx_instance`` passed to the Adapter.



   .. 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, 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 sample from :meth:`sample`.



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


   .. 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, Ellipsis], 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, Ellipsis], float]



   .. 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 



.. py:class:: OpenJijPreparation

   A separate Adapter input together with source-state reevaluation.

   Values are created by :meth:`OMMXOpenJijSAAdapter.prepare`; callers cannot
   pair an arbitrary input with unrelated preparation evidence.


   .. py:method:: evaluate_source(sample_set: ommx.SampleSet) -> ommx.SampleSet

      Reevaluate input-side sample states against the source Instance.

      ``sample_set`` must have been evaluated against this preparation's
      :attr:`input`, which populates irrelevant and dependent source variables.



   .. py:property:: input
      :type: ommx.Instance


      Return an isolated copy of the Binary, unconstrained minimization input.



   .. py:attribute:: report
      :type:  OpenJijPreparationReport


.. py:class:: OpenJijPreparationConfig

   User-selected settings for one OpenJij preparation operation.

   The two penalty modes are mutually exclusive. Every configured penalty
   weight must be finite and positive, every per-constraint key must be a
   valid unsigned 64-bit constraint ID, the integer slack range must fit a
   positive unsigned 64-bit integer, and the per-constraint mapping is
   snapshotted so that reports remain auditable after construction.


   .. py:attribute:: allow_approximate_integer_slack
      :type:  bool
      :value: False



   .. py:attribute:: inequality_integer_slack_max_range
      :type:  int
      :value: 32



   .. py:attribute:: penalty_weights
      :type:  collections.abc.Mapping[int, float] | None
      :value: None



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



.. py:class:: OpenJijPreparationFailure

   One failure discovered while materializing an accepted source.


   .. py:attribute:: constraint_refs
      :type:  frozenset[ommx.adapter.ConstraintRef]


   .. py:attribute:: description
      :type:  str


   .. py:attribute:: expected
      :type:  PreparationDiagnosticValue
      :value: None



   .. py:attribute:: observed
      :type:  PreparationDiagnosticValue
      :value: None



   .. py:attribute:: operation
      :type:  str


   .. py:attribute:: reason
      :type:  str


   .. py:attribute:: variable_ids
      :type:  frozenset[int]


.. py:class:: OpenJijPreparationReport

   The Config used and four outcomes of one preparation attempt.

   ``config`` is the immutable settings audit. The outcome fields separately
   record the source check, applied steps, materialization failures, and
   produced-input applicability.


   .. py:attribute:: config
      :type:  OpenJijPreparationConfig


   .. py:attribute:: input_applicability
      :type:  ommx.adapter.AdapterApplicabilityReport | None
      :value: None



   .. py:property:: is_successful
      :type: bool



   .. py:attribute:: preparation_failures
      :type:  tuple[OpenJijPreparationFailure, Ellipsis]
      :value: ()



   .. py:attribute:: source_check
      :type:  OpenJijPreparationSourceCheck


   .. py:attribute:: steps
      :type:  tuple[OpenJijPreparationStep, Ellipsis]


.. py:class:: OpenJijPreparationSourceCheck

   Structural membership evidence for a preparation source.


   .. py:property:: conditions_hold
      :type: bool



   .. py:attribute:: source_membership
      :type:  ommx.InstanceClassMembershipReport


.. py:class:: OpenJijPreparationStep

   One OpenJij-specific operation recorded for preparation auditing.

   This record is not a composed mathematical guarantee. The common guarantee
   and policy contracts are tracked separately in OMMX issue #1111.


   .. py:attribute:: constraint_refs
      :type:  frozenset[ommx.adapter.ConstraintRef]


   .. py:attribute:: description
      :type:  str


   .. py:attribute:: operation
      :type:  str


   .. py:attribute:: variable_ids
      :type:  frozenset[int]


.. py:function:: decode_to_samples(response: openjij.Response) -> ommx.Samples

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


