LpTranslator ¶
Utility class for converting between LP files and symbolic models.
LpTranslator
provides methods to:
- Convert an LP file into a symbolic Model
- Convert a Model
into an Lp file.
These conversions are especially useful when interacting with external solvers or libraries that operate on LP-based problem definitions.
Examples:
>>> from pathlib import Path
>>> from luna_quantum.translator import LpTranslator
>>> lp_filepath = Path("path/to/the/lp_file")
Convert it back to an LP file:
from_aq
staticmethod
¶
from_aq(model: Model, *, filepath: Path | None = ...) -> None
Convert a symbolic model to an LP file representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The symbolic model to convert. |
required |
file
|
Path
|
The filepath to write the model contents to. |
required |
Returns:
Type | Description |
---|---|
str
|
If no file to write to is given, i.e., the file is None. |
Raises:
Type | Description |
---|---|
TranslationError
|
If the translation fails for some reason. |
to_aq
staticmethod
¶
to_aq(file: str | Path) -> Model
Convert an LP file into a symbolic Model
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str | Path
|
An LP file representing a symbolic model, either given as a Path object to the LP file or its contents as a string. If you pass the path as a string, it will be interpreted as a model and thus fail to be parsed to a Model. |
required |
Returns:
Type | Description |
---|---|
Model
|
A symbolic model representing the given lp file structure. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
TranslationError
|
If the translation fails for a different reason. |