NumpyTranslator ¶
Translate between numpy arrays and our solution format.
Utility class for converting between a result consisting of numpy arrays and our solution format.
NumpyTranslator
provides methods to:
- Convert a numpy-array result into our solution Solution
.
Examples:
>>> import luna_quantum as lq
>>> from numpy.typing import NDArray
>>> result: NDArray = ...
>>> energies: NDArray = ...
>>> aqs = lq.translator.NumpyTranslator.to_aq(result, energies)
to_aq
staticmethod
¶
to_aq(result: NDArray, energies: NDArray) -> Solution
to_aq(result: NDArray, energies: NDArray, *, env: Environment) -> Solution
to_aq(
result: NDArray, energies: NDArray, timing: Timing, *, env: Environment
) -> Solution
to_aq(
result: NDArray,
energies: NDArray,
timing: Timing | None = ...,
*,
env: Environment | None = ...,
) -> Solution
Convert a solution in the format of numpy arrays to our solution format.
Note that the optimization sense is always assumed to be minimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
NDArray
|
The samples as a 2D array where each row corresponds to one sample. |
required |
energies
|
NDArray
|
The energies of the single samples as a 1D array. |
required |
timing
|
Timing
|
The timing object produced while generating the result. |
...
|
env
|
Environment
|
The environment of the model for which the result is produced. |
...
|
Raises:
Type | Description |
---|---|
NoActiveEnvironmentFoundError
|
If no environment is passed to the method or available from the context. |
SolutionTranslationError
|
Generally if the solution translation fails. Might be specified by one of the two following errors. |
SampleIncorrectLengthError
|
If a solution's sample has a different number of variables than the model environment passed to the translator. |
ModelVtypeError
|
If the result's variable types are incompatible with the model environment's variable types. |