Search…
Create a Job
In this section, we will see how you can schedule a simulation aka a job, on Pollination cloud from your Pollination app. A Job on Pollination can be created using the Pollination credentials, job inputs,and recipe inputs.

Step-1: Pollination Credentials

API key: A user of your app can find a Pollination API key in the "Developer Settings" section under the "Settings" tab of their profile on Pollination. If they don't have a key, they can generate one by entering any name for the key and clicking on the "+" button. Once they have this key, they can copy it to the clipboard and paste it back to the Pollination-app.
Owner Name: The owner name is the username of the user who is scheduling this job on Pollination. This username too can be found in the "Profile Settings" section of the "Settings" tab on Pollination. The username is typically followed by a "@" on the "Profile Settings".

Step-2: Job Inputs

Project: The project name is name of the project the scheduled job will go into. A user can create a project on Pollination by clicking on the "+" button on the navigation bar at the top. If a project already exists, the user can use that project's name.
Job name: Any text to name the job.
Job description: Any text to describe the job.

Step-3: Recipe Selection

A recipe needs to be selected and added to the project before it can be used. A recipe can be added to the project by going to the "Recipes" on the "Settings" tab of the project.
Recipe owner: The owner of the recipe. You will find several public recipes developed by the ladybug tools team on Pollination. If you develop and deploy a recipe, the owner name here will be your username.
Recipe name: Name of the recipe you want to use for the job.
Recipe tag: The version tag of the recipe you want to use for the job.

Step-4: Recipe Inputs

Visit any recipe on Pollination to find out the inputs for the recipe

Step-5: Scheduling a Job

We will create a job on Pollination to run the daylight-factor recipe on the gridbased model that ships with Ladybug Tools.
Install the following libraries first
1
pip install streamlit pollination-streamlit
Copied!
Importing necessary libraries
1
import streamlit as st
2
from pathlib import Path
3
from pollination_streamlit.api.client import ApiClient
4
from pollination_streamlit.interactors import NewJob, Recipe
Copied!
Helper function to add a recipe to a job
1
def add_recipe_to_job(new_job, recipe_arguments, recipe_artifacts) -> NewJob:
2
"""Add recipe arguments and artifacts to a job.
3
4
args:
5
new_job: A NewJob object.
6
recipe_arguments: A dictionary of recipe arguments.
7
recipe_artifacts: A dictionary of recipe artifacts where each items is a
8
dictionary where the key is the name of the input on the recipe and the
9
values are the paths to artifact and the path to the target folder on
10
Pollination.
11
12
returns:
13
A NewJob object with the recipe arguments and artifacts added.
14
"""
15
16
for key, val in recipe_artifacts.items():
17
item = new_job.upload_artifact(
18
val['file_path'], val['pollination_target_path'])
19
recipe_arguments[key] = item
20
21
new_job.arguments = [recipe_arguments]
22
23
return new_job
Copied!
Create a Streamlit form to collect inputs from the user and submit the job
1
with st.form('daylight-factor-job'):
2
3
st.markdown('Pollination credentials')
4
api_key = st.text_input(
5
'Enter Pollination API key', type='password')
6
owner = st.text_input('Project Owner')
7
st.markdown('---')
8
9
st.markdown('Job inputs')
10
project = st.text_input('Project Name')
11
job_name = st.text_input('Job Name')
12
job_description = st.text_input('Job Description')
13
st.markdown('---')
14
15
st.markdown('Recipe selection')
16
recipe_owner = st.text_input('Recipe Owner', value='ladybug-tools')
17
recipe_name = st.text_input('Recipe Name', value='daylight-factor')
18
recipe_tag = st.text_input('Recipe Version', value='latest')
19
st.markdown('---')
20
21
st.markdown('Recipe inputs')
22
# TODO: This will change based on the recipe you select
23
cpu_count = st.number_input('CPU Count', value=50)
24
grid_filter = st.text_input('Grid Filter', value='*')
25
min_sensor_count = st.number_input('Min Sensor Count', value=200)
26
hbjson_data = st.file_uploader('Upload HBJSON')
27
rad_parameters = st.text_input('Rad Parameters',
28
value='-ab 2 -aa 0.1 -ad 2048 -ar 64')
29
# TODO: change ends
30
31
submit_button = st.form_submit_button(
32
label='Submit')
33
34
if submit_button:
35
# create HBJSON file path
36
hbjson_file = Path('.', 'model.hbjson')
37
# write HBJSON file
38
hbjson_file.write_bytes(hbjson_data.read())
39
40
# recipe inputs
41
# TODO: This will change based on the recipe you select
42
arguments = {
43
'cpu-count': cpu_count,
44
'grid-filter': grid_filter,
45
'min-sensor-count': min_sensor_count,
46
'radiance-parameters': rad_parameters,
47
}
48
49
# recipe inputs where a file needs to be uploaded
50
artifacts = {
51
'model': {'file_path': hbjson_file, 'pollination_target_path': ''}
52
}
53
# TODO: change ends
54
55
api_client = ApiClient(api_token=api_key)
56
recipe = Recipe(recipe_owner, recipe_name, recipe_tag, api_client)
57
new_job = NewJob(owner, project, recipe, name=job_name,
58
description=job_description, client=api_client)
59
new_job = add_recipe_to_job(new_job, arguments, artifacts)
60
job = new_job.create()
Copied!
The above code will render the following Streamlit form that can be used to submit a job on Pollination to run the daylight-factor recipe.
A job submitted using this form can be accessed here.