Skip to content

Update prog_server notebook #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 81 additions & 45 deletions examples/10_Prognostics Server.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,38 @@
"source": [
"# Prognostics Server (prog_server)\n",
"\n",
"The ProgPy Server (prog_server) is a simplified implementation of a Service-Oriented Architecture (SOA) for performing prognostics (estimation of time until events and future system states) of engineering systems. prog_server is a wrapper around the ProgPy package, allowing one or more users to access the features of these packages through a REST API. The package is intended to be used as a research tool to prototype and benchmark Prognostics As-A-Service (PaaS) architectures and work on the challenges facing such architectures, including Generality, Communication, Security, Environmental Complexity, Utility, and Trust.\n",
"The ProgPy Server (`prog_server`) is a simplified implementation of a Service-Oriented Architecture (SOA) for performing prognostics (estimation of time until events and future system states) of engineering systems. `prog_server` is a wrapper around the ProgPy package, allowing one or more users to access the features of these packages through a REST API. The package is intended to be used as a research tool to prototype and benchmark Prognostics As-A-Service (PaaS) architectures and work on the challenges facing such architectures, including Generality, Communication, Security, Environmental Complexity, Utility, and Trust.\n",
"\n",
"The ProgPy Server is actually two packages, prog_server and prog_client. The prog_server package is a prognostics server that provides the REST API. The prog_client package is a python client that provides functions to interact with the server via the REST API.\n",
"\n",
"**TODO(CT): IMAGE- server with clients**\n",
"The ProgPy Server is actually two packages, `prog_server` and `prog_client`. The `prog_server` package is a prognostics server that provides the REST API. The `prog_client` package is a python client that provides functions to interact with the server via the REST API.\n",
"\n",
"**TODO(CT): IMAGE- server with clients**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of Contents\n",
"* [Installing](#Installing)\n",
"* [Starting prog_server](#Starting-prog_server)\n",
" * [Command Line](#Command-Line)\n",
" * [Programmtically](#Programatically)\n",
"* [Using prog_server with prog_client](#Using-prog_server-with-prog_client)\n",
" * [Online Prognostics Example](#Online-Prognostics-Example)\n",
" * [Option Scoring Example](#Option-scoring-example)\n",
"* [Using prog_server with REST Interface](#Using-prog_server-with-REST-Interface)\n",
"* [Custom Models](#Custom-Models)\n",
"* [Closing prog_server](#Closing-prog_server)\n",
"* [Conclusion](#Conclusion)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installing\n",
"\n",
"prog_server can be installed using pip\n",
"`prog_server` can be installed using pip\n",
"\n",
"```console\n",
"$ pip install prog_server\n",
Expand All @@ -32,15 +55,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"prog_server can be started 2 ways. Through command line or programatically (i.e., in a python script). Once the server is started it will take a short time to initialize, then it will start receiving requests for sessions from clients using prog_client, or interacting directly using the REST interface."
"`prog_server` can be started through the command line or programatically (i.e., in a python script). Once the server is started, it will take a short time to initialize. Then, it will start receiving requests for sessions from clients using `prog_client`, or interacting directly using the REST interface."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Starting prog_server in command line\n",
"Generally, you can start the prog_server by running the module, like this:\n",
"### Command Line\n",
"Generally, you can start `prog_server` by running the module, like this:\n",
"\n",
"```console\n",
"$ python -m prog_server\n",
Expand All @@ -53,8 +76,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Starting prog_server programatically\n",
"There are two methods to start the prog_server in python. The first, below, is non-blocking allowing users to perform other functions while the server is running."
"### Programatically\n",
"There are two methods to start the `prog_server` programatically in python. The first, below, is non-blocking and allows users to perform other functions while the server is running."
]
},
{
Expand All @@ -64,20 +87,21 @@
"outputs": [],
"source": [
"import prog_server\n",
"\n",
"prog_server.start()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When starting a server, users can also provide arguments to customize the way the server runs. Here are the main arguments used by \n",
"When starting a server, users can also provide arguments to customize the way the server runs. Here are the main arguments used:\n",
"\n",
"* host (str): Server host address. Defaults to ‘127.0.0.1’\n",
"* port (int): Server port address. Defaults to 8555\n",
"* debug (bool): If the server is to be started in debug mode\n",
"* `host` (str): Server host address. Defaults to ‘127.0.0.1’\n",
"* `port` (int): Server port address. Defaults to 8555\n",
"* `debug` (bool): If the server is to be started in debug mode\n",
"\n",
"Now prog_server is ready to start receiving session requests from users. The server can also be stopped using the stop() function"
"Now `prog_server` is ready to start receiving session requests from users. The server can also be stopped using the `stop()` function"
]
},
{
Expand All @@ -93,24 +117,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"prog_server can also be started in blocked mode using the following command:\n",
"`prog_server` can also be started in blocked mode using the following command:\n",
"\n",
"```python\n",
">>> prog_server.run()\n",
"```\n",
"\n",
"We will not execute it here, because it would block execution in this notebook until force quit.\n",
"We will not execute it here, because it would block execution in this notebook until we force quit.\n",
"\n",
"For details on all supported arguments see [API Doc](https://nasa.github.io/progpy/api_ref/prog_server/prog_server.html#prog_server.start)\n",
"For details on all supported arguments, see the [API Doc](https://nasa.github.io/progpy/api_ref/prog_server/prog_server.html#prog_server.start).\n",
"\n",
"The basis of prog_server is the session. Each user creates one or more session. These sessions are each a request for prognostic services. Then the user can interact with the open session. You'll see examples of this in the future sections."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's restart the server (so it can be used with the below examples)"
"The basis of `prog_server` is the session. Each user creates one or more session. These sessions are each a request for prognostic services. Then the user can interact with the open session. You'll see examples of this in the future sections.\n",
"\n",
"Let's restart the server again so it can be used with the below examples."
]
},
{
Expand All @@ -127,9 +146,10 @@
"metadata": {},
"source": [
"## Using prog_server with prog_client\n",
"For users using python, prog_server can be interacted with using the prog_client package distributed with progpy. This section describes a few examples using prog_client and prog_server together.\n",
"\n",
"Before using prog_client import the package:"
"For users using python, `prog_server` can be interacted with using the `prog_client` package distributed with ProgPy. This section describes a few examples using `prog_client` and `prog_server` together.\n",
"\n",
"We will first import the needed package."
]
},
{
Expand All @@ -145,10 +165,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example: Online Prognostics\n",
"### Online Prognostics Example\n",
"This example creates a session with the server to run prognostics for a Thrown Object, a simplified model of an object thrown into the air. Data is then sent to the server and a prediction is requested. The prediction is then displayed.\n",
"\n",
"**Note: before running this example, make sure prog_server is running**\n",
"**Note: before running this example, make sure `prog_server` is running.**\n",
"\n",
"The first step is to open a session with the server. This starts a session for prognostics with the ThrownObject model, with default parameters. The prediction configuration is updated to have a save frequency of every 1 second."
]
Expand All @@ -171,7 +191,7 @@
"\n",
"Next, we need to prepare the data we will use for this example. The data is a dictionary, and the keys are the names of the inputs and outputs in the model with format (time, value).\n",
"\n",
"Note: in an actual application, the data would be received from a sensor or other source. The structure below is used to emulate the sensor."
"Note that in an actual application, the data would be received from a sensor or other source. The structure below is used to emulate the sensor."
]
},
{
Expand Down Expand Up @@ -214,7 +234,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can start sending the data to the server, checking periodically to see if there is a completed prediction."
"Now, we can start sending the data to the server, checking periodically to see if there is a completed prediction."
]
},
{
Expand Down Expand Up @@ -271,7 +291,7 @@
"source": [
"Notice that the prediction wasn't updated every time step. It takes a bit of time to perform a prediction.\n",
"\n",
"*Note*: You can also get the model from prog_server to work with directly."
"Note that we can also get the model from `prog_server` to work with directly."
]
},
{
Expand All @@ -281,19 +301,19 @@
"outputs": [],
"source": [
"model = session.get_model()\n",
"\n",
"print(model)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example: Option Scoring\n",
"This example creates a session with the server to run prognostics for a BatteryCircuit. Three options with different loading profiles are compared by creating a session for each option and comparing the resulting prediction metrics.\n",
"### Option Scoring Example\n",
"\n",
"First step is to prepare load profiles to compare. Each load profile has format `Array[Dict]`. Where each dict is in format {TIME: LOAD}, where TIME is the start of that loading in seconds. LOAD is a dict with keys corresponding to model.inputs.\n",
"This example creates a session with the server to run prognostics for a `BatteryCircuit` model. Three options with different loading profiles are compared by creating a session for each option and comparing the resulting prediction metrics.\n",
"\n",
"Note: Dict must be in order of increasing time\n",
"First step is to prepare load profiles to compare. Each load profile has format `Array[Dict]`. Where each dict is in format `{TIME: LOAD}`, where `TIME` is the start of that loading in seconds. `LOAD` is a dict with keys corresponding to model.inputs. Note that the dict must be in order of increasing time.\n",
"\n",
"Here we introduce 3 load profiles to be used with simulation:"
]
Expand Down Expand Up @@ -379,7 +399,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's wait for prognostics to complete"
"Now let's wait for prognostics to be complete."
]
},
{
Expand Down Expand Up @@ -421,7 +441,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's compare results. First let's look at the mean Time to Event (ToE):"
"Now let's compare results. Let's look at the mean Time to Event (`ToE`):"
]
},
{
Expand All @@ -446,7 +466,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As a second metric, let's look at the SOC at our point of interest (2000 seconds)"
"As a second metric, let's look at the `SOC` at our point of interest (2000 seconds)"
]
},
{
Expand All @@ -471,16 +491,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Other metrics can be used as well, like probability of mission success given a certain mission time, uncertainty in ToE estimate, final state at end of mission, etc. "
"Other metrics can be used as well, like probability of mission success given a certain mission time, uncertainty in `ToE` estimate, final state at end of mission, among others."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using prog_server - REST Interface\n",
"## Using prog_server with REST Interface\n",
"\n",
"Communication with ProgPy is through a rest interface. The RestAPI is described here: [Rest API](https://app.swaggerhub.com/apis-docs/teubert/prog_server/).\n",
"Communication with ProgPy is through a REST interface. The REST API is described here: [prog_server REST API](https://app.swaggerhub.com/apis-docs/teubert/prog_server/).\n",
"\n",
"Most programming languages have a way of interacting with REST APIs (either native or through a package/library). `curl` requests can also be used by command line or apps like Postman."
]
Expand All @@ -490,14 +510,14 @@
"metadata": {},
"source": [
"## Custom Models\n",
"**A version of this section will be added in release v1.8** "
"**A version of this section will be added in release v1.9** "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Closing\n",
"## Closing prog_server\n",
"When you're done using prog_server, make sure you turn off the server."
]
},
Expand All @@ -509,6 +529,22 @@
"source": [
"prog_server.stop()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conclusion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we have demonstrated how to use the ProgPy server, including `prog_server` and `prog_client`. This is the last notebook in the ProgPy tutorial series.\n",
"\n",
"For more information about ProgPy in general, check out the __[00 Intro](00_Intro.ipynb)__ notebook and [ProgPy documentation](https://nasa.github.io/progpy/index.html)."
]
}
],
"metadata": {
Expand Down
Loading