Purpose of this file is for the integration of Radical Pilot with AdaptiveMD workflow.


In [1]:
import os

#mongodb_address = "mongodb://rp:rp@ds015335.mlab.com:15335/rp"
#mongodb_address = "mongodb://localhost:27017/rp"

In [2]:
print(os.environ['RP_ENABLE_OLD_DEFINES'])
print(os.environ['RADICAL_PILOT_DBURL'])


True
mongodb://localhost:27017/rp

In [3]:
# Maybe don't work due to outside call of RP in the env
#os.environ.update({"RP_ENABLE_OLD_DEFINES": "True"})
#os.environ.update({"RADICAL_PILOT_DBURL": mongodb_address})

In [4]:
from adaptivemd import Project, File#, Configuration
from adaptivemd.mongodb import MongoDBStorage
from adaptivemd.engine.openmm import OpenMMEngine
from adaptivemd.analysis.pyemma import PyEMMAAnalysis
from adaptivemd.rp.client import Client


/home/johnrobot/myenv/local/lib/python2.7/site-packages/radical/utils/atfork/stdlib_fixer.py:63: UserWarning: logging module already imported before fixup.
  warnings.warn('logging module already imported before fixup.')

In [11]:
#Project.set_dblocation("user:user@ds159013.mlab.com", 59013)
#Project.set_dblocation("user:user@two.radical-project.org", 32769)
print(MongoDBStorage._db_url)
project_name = 'rp_compat42'
configuration_file = 'rp_compat.cfg'


mongodb://localhost:27017/

In [6]:
Project.delete(project_name)
#[Project.delete(p) for p in Project.list()]
Project.list()


Out[6]:
[u'rp_compat',
 u'rp_testing',
 u'rp_testing_3',
 u'rp_testing_X1',
 u'rp_testing_modeller_1']

In [7]:
project = Project(project_name)

In [8]:
c=project.configurations.one

In [9]:
[g.__dict__ for g in project.generators]


Out[9]:
[]

In [12]:
#project = Project(project_name)

# Configuration is not a user class
#   view instances via the project
#
# refer to individual configurations
#cfg = project.configurations.one
#cfg_ornl_1 = project.configurations["ornl.1"]
#
# if there is a configuration file stored in the
# default locations with project_name, initialize
# will automatically find and read it.
#project.initialize()
#
# else if there is a configuration file in a
# different location or different name
#project.initialize('path/to/config.cfg')
#
# else must do this after project.initialize():
#project.read_configurations('path/to/config.cfg')

#project.initialize(configuration_file, default_configuration)
project.initialize(configuration_file)#default_configuration='ornl')

In [14]:
project.configurations.all.name
#print(project.resources._set.content_class)
#print(project.generators._set.content_class)
#print(project.configurations._set.content_class)


Out[14]:
['local.1', 'titan.1']

In [13]:
# sweet!
Project.list()


Out[13]:
[u'rp_compat',
 u'rp_compat42',
 u'rp_testing',
 u'rp_testing_3',
 u'rp_testing_X1',
 u'rp_testing_modeller_1']

In [13]:
# This is not necessary for executing with RP
#pdb_file = File('file://../files/alanine/alanine.pdb').named('initial_pdb').load()
#system_file = File('file://../files/alanine/system.xml').load()
#integrator_file = File('file://../files/alanine/integrator.xml').load()
pdb_file = File('file://../files/alanine/alanine.pdb').named('initial_pdb')#.load()
system_file = File('file://../files/alanine/system.xml')#.load()
integrator_file = File('file://../files/alanine/integrator.xml')#.load()

In [14]:
engine = OpenMMEngine(
    pdb_file=pdb_file,
    system_file=system_file,
    integrator_file=integrator_file,
    args='-r --report-interval 1 -p CPU'
).named('openmm')

engine.add_output_type('master', 'master.dcd', stride=10)
engine.add_output_type('protein', 'protein.dcd', stride=1, selection='protein')

modeller = PyEMMAAnalysis(
    engine=engine,
    outtype='protein',
    features={'add_inverse_distances': {'select_Backbone': None}}
).named('pyemma')

margs = dict(tica_stride=1, tica_lag=5, tica_dim=2,
    clust_stride=1, msm_states=10, msm_lag=5)

In [15]:
project.generators.add(engine)
project.generators.add(modeller)

In [16]:
project.set_current_configuration('local')

In [16]:
project._current_configuration.wrapper.prepend()


Out[16]:
<bound method DummyTask.prepend of <adaptivemd.task.DummyTask object at 0x7f8762f4e850>>

In [18]:
project.read_configurations('rp_compat.cfg')


Current configuration pattern must match a single item
Arbitrarily selecting the last matching entry: Configuration.name==local

In [19]:
#g = project.storage.generators
#[g.cache[idx].__dict__ for idx in g.index]
#og = g.cache[idx]
[c.__dict__ for c in project.storage.configurations]
#[c.cache[idx].__dict__ for idx in c.index]
#oc = c.cache[idx]


Out[19]:
[{'__store__': store.configurations[Configuration] : 3 object(s),
  '__time__': 1505156084,
  '__uuid__': 228372803867653500094771312464540729396L,
  'allocation': None,
  'cores_per_node': None,
  'current': True,
  'name': 'local',
  'queues': [None],
  'resource_name': 'local.localhost',
  'shared_path': '$HOME/adaptivemd/',
  'wrapper': <adaptivemd.task.DummyTask at 0x7fccbf347210>},
 {'__store__': store.configurations[Configuration] : 3 object(s),
  '__time__': 1505156092,
  '__uuid__': 228372803867653500094771312464540729452L,
  'allocation': None,
  'cores_per_node': None,
  'current': False,
  'name': 'local.1',
  'queues': [None],
  'resource_name': 'local.localhost',
  'shared_path': '$HOME/adaptivemd/',
  'wrapper': <adaptivemd.task.DummyTask at 0x7fccbd901050>},
 {'__store__': store.configurations[Configuration] : 3 object(s),
  '__time__': 1505156092,
  '__uuid__': 228372803867653500094771312464540729456L,
  'allocation': 'bip149',
  'cores_per_node': 16,
  'current': False,
  'name': 'titan.1',
  'queues': ['batch'],
  'resource_name': 'ornl.titan',
  'shared_path': '$ADMD_DATA',
  'wrapper': <adaptivemd.task.DummyTask at 0x7fccbd901090>}]

In [20]:
# TODO have this return resource so it can be given directly
#      to the queueing function, and keep the option of using
#      the resource name as well
project.request_resource(total_cpus=2, total_time=10, destination='local')
#project.request_resource(2,30, destination='ornl.titan')

In [21]:
project.configurations.all.name


Out[21]:
['local', 'local.1', 'titan.1']

In [22]:
project.resources.first.__dict__


Out[22]:
{'__store__': store.resources[Resource] : 1 object(s),
 '__time__': 1505156094,
 '__uuid__': 228372803867653500094771312464540729460L,
 'destination': 'local',
 'name': None,
 'total_cpus': 2,
 'total_gpus': 0,
 'total_time': 10}

In [23]:
tasks=list(project.tasks)

In [24]:
ta=tasks[-1]
print ta.stdout
print ta.description


None
Task: DummyTask
<pre>
</pre>
<main />
<post>
</post>

In [25]:
#filter(lambda c: getattr(c, 'name').find('titan') >= 0, list(project.configurations))
#c=cs[1c=project.configurations.last]
#c.name
#c.allocation

In [26]:
trajectories = project.new_trajectory(engine['pdb_file'], 100, engine, 4)
project.queue(trajectories, resource_name="local.localhost")

In [27]:
trajectories = project.new_ml_trajectory(engine, 500, 4)
project.queue(trajectories)

In [17]:
#client = Client('mongodb://user:user@two.radical-project.org:32769/', project_name)
client = Client('mongodb://localhost:27017/', project_name)
#import os
#os.environ['RADICAL_PILOT_DBURL'] = 'mongodb://rp:rp@ds015335.mlab.com:15335/rp'
#os.system('export RP_ENABLE_OLD_DEFINES=True')
client.start()


Resource local.localhost
new session: [rp.session.johnrobot-HP-ENVY-TS-17-Notebook-PC.johnrobot.017418.0000]
        \
database   : [mongodb://localhost:27017/rp]                                   ok
create pilot manager                                                          ok
submit 1 pilot(s)
        .                                                                     ok
2017-09-09 14:32:58,008: radical.saga        : pmgr.launching.0                : MainThread     : ERROR   : BadParameter: 'JobDescription.Project' (none) is not supported by adaptor saga.adaptor.shell_job
2017-09-09 14:32:58,012: resource_manager.rp : Process-1                       : pmgr.0000.subscriber._state_sub_cb: ERROR   : Pilot has failed
2017-09-09 14:32:58,087: resource_manager.rp : Process-1                       : MainThread     : ERROR   : Resource request submission failed
Traceback (most recent call last):
  File "/home/johnrobot/myenv/local/lib/python2.7/site-packages/adaptivemd/rp/resource_manager.py", line 285, in submit_resource_request
    raise Exception
Exception

2017-09-09 14:32:58,090: client.rp           : Process-1                       : MainThread     : ERROR   : Client process failed, error: Error: Resource request submission failed
Traceback (most recent call last):
  File "/home/johnrobot/myenv/local/lib/python2.7/site-packages/adaptivemd/rp/client.py", line 103, in _runme
    self._rmgr.submit_resource_request()
  File "/home/johnrobot/myenv/local/lib/python2.7/site-packages/adaptivemd/rp/resource_manager.py", line 303, in submit_resource_request
    raise Error(msg='Resource request submission failed')
Error: Error: Resource request submission failed

wait for 1 pilot(s)
        O39m39m                                                                     ok
closing session rp.session.johnrobot-HP-ENVY-TS-17-Notebook-PC.johnrobot.017418.0000
        \
close pilot manager                                                            \
wait for 1 pilot(s)
        O39m                                                                timeout
                                                                              ok
session lifetime: 6.8s                                                        ok
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/home/johnrobot/myenv/local/lib/python2.7/site-packages/adaptivemd/rp/client.py", line 140, in _runme
    raise Error(msg=ex)
Error: Error: Error: Resource request submission failed

In [14]:
client.stop()

In [39]:
mixedbag = project.new_ml_trajectory(engine, 1000, 3)
mtask = modeller.execute(list(project.trajectories), **margs)
mixedbag.append(mtask)
project.queue(mixedbag)#, resource_name='local.localhost')


supering from pythontask

In [13]:
f = lambda: len(project.trajectories) == 4
project.wait_until(f)

In [ ]:
#project.execution_manager.stop()

In [40]:
project.models.__len__()
m=project.models.last

In [69]:
[' '.join(['{0:.2f}'.format(v) for v in row]) for row in m.data['msm']['P']]


Out[69]:
['0.80 0.00 0.01 0.00 0.00 0.00 0.07 0.07 0.00 0.05',
 '0.00 0.84 0.02 0.03 0.00 0.00 0.03 0.00 0.08 0.00',
 '0.01 0.01 0.83 0.00 0.00 0.00 0.02 0.00 0.07 0.06',
 '0.00 0.06 0.00 0.79 0.05 0.00 0.10 0.00 0.00 0.00',
 '0.00 0.00 0.00 0.12 0.85 0.02 0.01 0.00 0.00 0.00',
 '0.02 0.00 0.00 0.00 0.03 0.95 0.00 0.00 0.00 0.00',
 '0.07 0.03 0.03 0.06 0.00 0.00 0.80 0.00 0.00 0.00',
 '0.08 0.00 0.00 0.00 0.00 0.00 0.00 0.85 0.00 0.07',
 '0.00 0.09 0.10 0.00 0.00 0.00 0.00 0.00 0.81 0.00',
 '0.04 0.00 0.09 0.00 0.00 0.00 0.00 0.04 0.00 0.83']

In [14]:
for ta in project.tasks:
    print ta.description[:55]


Task: TrajectoryGenerationTask(OpenMMEngine) [created]

Task: TrajectoryGenerationTask(OpenMMEngine) [created]

Task: TrajectoryGenerationTask(OpenMMEngine) [created]

Task: TrajectoryGenerationTask(OpenMMEngine) [created]


In [70]:
project.workers.all.execute('shutdown')


Out[70]:
[None]

In [ ]: