qaekwy.engine
Module Reference
The qaekwy.engine
module provides classes and utilities for interacting with the optimization engine.
Overview
The qaekwy.engine
module defines classes that encapsulate various actions that can be performed on the
optimization engine, including sending requests, retrieving responses, and interacting with the engine’s
functionality. It also includes utilities for handling responses and model submissions.
This module also defines the ClusterEngine
class, which extends the Engine
class to interact with a
cluster-based optimization engine. Additionally, the DirectEngine
class is available to interact with a
Cloud-hosted optimization engine.
DirectEngine
Class representing the Cloud optimization engine for direct model submission and solution retrieval.
The DirectEngine
has a limitation of ~5Mo JSon input size.
- Methods:
echo() -> EchoResponse
: Send an ’echo’ request to the engine and retrieve the echo response.version() -> VersionResponse
: Request the version information of the engine.model(model: Modeller) -> SolutionResponse
: Submit a model and retrieve the solution.
Engine
(available soon)
Class representing the optimization engine and providing methods for interaction.
- Methods:
echo() -> EchoResponse
: Send an ’echo’ request to the engine and retrieve the echo response.version() -> VersionResponse
: Request the version information of the engine.reset() -> StatusResponse
: Reset the engine’s state.stop() -> AbstractResponse
: Stop the engine.status() -> StatusResponse
: Check the status of the engine.model(model: Modeller) -> ModelJSonResponse
: Submit a model for optimization.current_model() -> ModelJSonResponse
: Retrieve the current model from the engine.solution() -> SolutionResponse
: Retrieve the solution from the engine.
ClusterEngine
(available soon)
Class extending Engine
to interact with a cluster-based optimization engine.
- Methods:
explain_current() -> ExplanationResponse
: Retrieve the current explanation.explain(model: Modeller) -> ExplanationResponse
: Request an explanation for a model.clean() -> StatusResponse
: Clean the engine’s environment.status() -> ClusterStatusResponse
: Check the cluster’s health status.remove_node(identifier: str) -> StatusResponse
: Remove a node from the cluster.enable_node(identifier: str) -> StatusResponse
: Enable a disabled node in the cluster.disable_node(identifier: str) -> StatusResponse
: Disable a node in the cluster.
Responses
AbstractResponse
: Base class for defining responses received from the optimization engine.EchoResponse
: Class representing the response received from the ’echo’ request.VersionResponse
: Class representing the response received from the ‘version’ request.StatusResponse
: Class representing the response received from status-related requests.ModelJSonResponse
: Class representing the response received after submitting a model.SolutionResponse
: Class representing the response received containing solution information.
NodeStatus
This class represents the status of a cluster node in the optimization engine.
Attributes:
identifier
: A unique identifier for the node.url
: The URL of the node.is_enabled
: A boolean indicating if the node is enabled.message
: A message associated with the node’s status.is_busy
: A boolean indicating if the node is currently busy.number_of_solutions
: The number of solutions found by the node.is_failed
: A boolean indicating if the node has failed.is_awake
: A boolean indicating if the node is awake.
EchoResponse
Represents a response containing an echoed message from the optimization engine. Inherits from AbstractResponse.
get_status()
: Always returns an empty string.is_status_ok()
: Always returns True.get_message()
: Retrieves the echoed message from the response.get_content()
: Retrieves the content of the response (the echoed message).
ModelJSonResponse
Represents a response containing a JSON representation of a model.
StatusResponse
Represents a response containing status information from the optimization engine.
Methods:
get_type()
: Retrieves the type of the status response.get_code()
: Retrieves the code associated with the status response.is_busy()
: Checks if the engine is currently busy.get_number_of_solution_found()
: Retrieves the number of solutions found by the engine.
SolutionResponse
Represents a response containing solutions from the optimization engine.
Method:
get_solutions()
: Retrieves a list of Solution objects representing the solutions.
ExplanationResponse
Represents a response containing explanations from the optimization engine.
Method:
get_explanation()
: Retrieves an Explanation object containing explanations.
VersionResponse
Represents a response containing version information from the optimization engine.
Methods:
get_app()
: Retrieves the name of the application.get_author()
: Retrieves the author of the application.get_version()
: Retrieves the version of the application.get_version_major()
: Retrieves the major version number of the application.get_version_minor()
: Retrieves the minor version number of the application.get_version_build()
: Retrieves the build version number of the application.get_release()
: Retrieves the release information of the application.
ClusterStatusResponse
Represents a response containing cluster status information from the optimization engine.
Constructor takes response_content
as an argument.
Contains a list of NodeStatus instances representing the status of individual cluster nodes.
The constructor parses the response_content
and populates the node_status_list.
Example
Here’s how to use some of the classes and methods from the module:
from qaekwy.engine import DirectEngine
from qaekwy.model.modeller import Modeller
# Create an Engine client instance to connect to the optimization engine
engine = DirectEngine()
# Send an 'echo' request to the engine and print the result
print(engine.echo().get_message())
# Request the version information of the engine
version_response = engine.version()
print(version_response.get_version())
# Submit a model to the engine for optimization
model = Modeller()
# ...
# Submit a model and receive the solution
solution_response = engine.model(model)
#ย Get the list of solutions
list_of_solutions = solution_response.get_solutions()