- The file to run: Domino expects the file to have a default function that will trigger the execution.
-
A parameter list in a variety of data types, including:
- Text
- Drop-down list of options you can define, including multiple selection
- File upload
- Date selection
- Checkbox
Enable Snowflake access
Since your model uses a Domino Data Source to connect to Snowflake, you first need to set up permissions for your launcher to use it.Obtain the API Key
Follow the steps on the Get API key page to obtain your Domino API key. If you do not yet have an API key that you can copy, you can generate one.Store the API key as part of your project
To avoid including your API key in clear text as part of your code, store it as an environment variable in Domino.- From your project navigation menu, click on Settings.
- In the Project settings window, find the Environment variables area. This is where you will store the API key.
-
In the Name field, provide a variable a name, such as
launcher_api_key, and then paste the API key into the Value field. - Click Set Variable. Domino will store the value securely for future use.
- Save a copy of this key for later in the tutorial or return to this screen later to retrieve the key.
Write the Domino Launcher executable
Setup
- Launch a Domino Workspace with JupyterLab.
-
Once the workspace is launched, select
Python Filefrom theOthergroup in the Jupyterlab Launcher. -
When the file opens, save it as
predict_location.py.
Write the code
The code you will write will be roughly based on the work you did before to train your model.-
First import the necessary libraries:
-
Next, retrieve the API key and connect to the data source:
-
Structure the files as a collection of individual functions. The first function, that will also act as the entry point and orchestrator, is
predict_weather.The function takes two arguments, the station ID and number of days to forecast. In the body of the function you prepare the data, build the model using the data, and finally return the forecast. -
The next function should look similar to the code you used previously:
The function returns a dataframe shaped for the model to be created and with missing data interpolated.
-
The next function creates the predictive model:
-
Now use the model to forecast the weather:
-
Finally, output the results into a file:
This will save the results to a file inside the Domino
/mnt/resultsfolder. The file name will follow the format:<station name>-<year>-<month>-<date>-<time>.txt. -
Importantly, you need to add the block telling Python what the default function in the file is:
-
If you want to test the file, open a command line tab in JupyterLab and enter the following:
Set up the Domino Launcher
As mentioned, the launcher needs to call a file in order to process user requests for a weather forecast. The launcher form will accept two inputs:-
The station ID in a
textformat. -
The number of days to forecast the weather, as an integer between
1and7.
- From the project menu, click Launchers.
- In the screen that appears, click the New Launcher button.
-
The configuration form will appear. Complete the fields as follow:
- Name and Description: Give the launcher a descriptive name and describe its usage.
- Environment and Hardware Tier: Choose the same Domino Environment and hardware tier you used when you wrote and tested the launcher in your Domino Workspace.
-
Command to run: To configure the Domino Launcher, specify the name of the Python file you created (i.e.
predict_location.py). Domino will search for the file in the project’s root folder. Since we have two arguments to the function, click the Add Parameter button twice. You will see the form expanding and adding two new fields below. -
parameter0: The first parameter will be the station information. In the Default Value field, add one of the station IDs you used, e.g.
AU000005901, and in the Description field, addstation ID. -
parameter1: Click on
parameter1. This parameter will be used to specify how many days you want a forecast for. PickSelect (drop-down menu)as the Type (instead ofText). The form will now change and ask you to enter a comma-separated list of allowable values. Each value entered will become an option for the drop-down. In the Allowed Values field, enter1,2,3,4,5,6,7. Domino will use the literal value for each option in text form (e.g. a string1will be passed to the Python script as the value of the argument). Add a Description for the parameter, e.g.How many days should the launcher forecast?.
- Finally, click the Save and Preview button. Domino will save the launcher form and present you with a preview of the UI you just defined.
- If the form looks acceptable, click Back to All Launchers. Alternatively, if you want to make changes to the form, click Keep Editing.
- The launcher screen will now show the launcher you just created.
- Click the Run button - the form will appear as a popup layer.
-
In the popup window, you can modify the parameters if you like. Once you are satisfied with the parameters, click Run. Domino will do the following:
- Start a Kubernetes container using the hardware tier and environment you specified.
- Trigger Python to run the file you named and pass it the parameters you entered.
-
Since the above is how Domino Jobs work, and since Launchers act like Domino Job triggers, the screen will change to the Jobs screen in your project. You will see your job at the top of the Jobs list as the most recent execution, along with the job
STATUS. More information about this can be found on the Job states page.
-
When you click on the job, a job detail overlay will appear:
- The Logs tab in the overlay offers a variety of logs that will help you debug issues when they occur.
- Now switch to the Results tab. Domino will present links to the files created as an output of the Launcher’s job execution. You can also see a preview of the files if they are text-based. Here you can see that your Launcher worked and the prediction results for tomorrow was output to a file.
- Click on the file link. This will take you to a full-screen preview of the file that the job created.