Commit 797baf35 authored by Adam Fekete's avatar Adam Fekete
Browse files

more testing of mongodb

parent 4b9f7460
%% Cell type:markdown id:metallic-supervisor tags:
# Fireworks (Five-minute quickstart)
%% Cell type:markdown id:australian-firewall tags:
Testing mongodb connection:
%% Cell type:code id:referenced-routine tags:
``` python
import pymongo
client = pymongo.MongoClient(
%% Cell type:markdown id:gorgeous-curve tags:
## Start FireWorks
If not already running, start MongoDB (if your MongoDB is hosted and maintained externally, follow the note below regarding lpad init):
%% Cell type:code id:electronic-essex tags:
``` python
# !lpad init
%% Cell type:code id:increasing-context tags:
``` python
!cat my_launchpad.yaml
%% Cell type:markdown id:white-owner tags:
Reset/Initialize the FireWorks database (the LaunchPad):
%% Cell type:code id:entertaining-scotland tags:
``` python
# !lpad reset
%% Cell type:code id:increasing-context tags:
``` python
!cat my_launchpad.yaml
! echo 'y' | lpad reset
%% Cell type:markdown id:numerous-regard tags:
## Add a Workflow
There are many ways to add Workflows to the database, including a Python API. Let’s start with an extremely simple example that can be added via the command line:
%% Cell type:code id:square-primary tags:
``` python
!lpad add_scripts 'echo "hello"' 'echo "goodbye"' -n hello goodbye -w test_workflow
%% Cell type:markdown id:manufactured-bernard tags:
This added a two-job linear workflow. The first jobs prints hello to the command line, and the second job prints goodbye. We gave names (optional) to each step as “hello” and “goodbye”. We named the workflow overall (optional) as “test_workflow”.
%% Cell type:markdown id:mounted-audio tags:
Let’s look at our test workflow:
%% Cell type:code id:identical-international tags:
``` python
!lpad get_wflows -n test_workflow -d more
%% Cell type:markdown id:fuzzy-intellectual tags:
We get back basic information on our workflows. The second step “goodbye” is waiting for the first one to complete; it is not ready to run because it depends on the first job.
%% Cell type:markdown id:useful-reviewer tags:
## Run all Workflows
You can run jobs one at a time (“singleshot”) or all at once (“rapidfire”). Let’s run all jobs:
%% Cell type:code id:excess-chosen tags:
``` python
!rlaunch --silencer rapidfire
%% Cell type:markdown id:dedicated-commerce tags:
Clearly, both steps of our workflow ran in the correct order.
%% Cell type:markdown id:joined-antique tags:
Let’s again look at our workflows:
%% Cell type:code id:conditional-henry tags:
``` python
!lpad get_wflows -n test_workflow -d more
%% Cell type:markdown id:lucky-failing tags:
FireWorks automatically created launcher_ directories for each step in the Workflow and ran them. We see that both steps are complete. Note that there exist options to choose where to run jobs, as well as to tear down empty directories after running jobs.
%% Cell type:markdown id:forward-client tags:
## Launch the web GUI
If you have a web browser, you can launch the web GUI to see your results:
%% Cell type:code id:anticipated-patrol tags:
``` python
# !lpad webgui
%% Cell type:markdown id:civic-sauce tags:
Note that there are options to run the web site in a server mode, try lpad webgui -h to see all the options.
open: http://localhost:8888/proxy/5000
%% Cell type:markdown id:explicit-denial tags:
## Python code
The following Python code achieves the same behavior:
%% Cell type:code id:cutting-modification tags:
``` python
from fireworks import Firework, Workflow, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import rapidfire
# set up the LaunchPad and reset it
launchpad = LaunchPad(host='mongo')
launchpad.reset('', require_password=False)
# create the individual FireWorks and Workflow
fw1 = Firework(ScriptTask.from_str('echo "hello"'), name="hello")
fw2 = Firework(ScriptTask.from_str('echo "goodbye"'), name="goodbye")
wf = Workflow([fw1, fw2], {fw1:fw2}, name="test workflow")
# store workflow and launch it locally
%% Cell type:markdown id:allied-lesson tags:
In the code above, the `{fw1:fw2}` argument to Workflow is adding a dependency of fw2 to fw1. You could instead define this dependency when defining your FireWorks:
%% Cell type:code id:interstate-intervention tags:
``` python
fw1 = Firework(ScriptTask.from_str('echo "hello"'), name="hello")
fw2 = Firework(ScriptTask.from_str('echo "goodbye"'), name="goodbye", parents=[fw1])
wf = Workflow([fw1, fw2], name="test workflow")
%% Cell type:code id:speaking-institution tags:
``` python
%% Cell type:code id:devoted-treat tags:
``` python
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment