| { |
| "cells": [ |
| { |
| "cell_type": "code", |
| "execution_count": 1, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "import sys\n", |
| "import random\n", |
| "\n", |
| "from thrift.protocol import TBinaryProtocol\n", |
| "from thrift.transport import TSocket, TTransport, TSSLSocket\n", |
| "\n", |
| "from apache.airavata.api import Airavata\n", |
| "from apache.airavata.model.experiment.ttypes import ExperimentModel\n", |
| "from apache.airavata.model.scheduling.ttypes import ComputationalResourceSchedulingModel\n", |
| "from apache.airavata.model.experiment.ttypes import UserConfigurationDataModel\n", |
| "from apache.airavata.model.status.ttypes import ExperimentState\n", |
| "from apache.airavata.model.security.ttypes import AuthzToken\n", |
| "from apache.airavata.model.application.io.ttypes import InputDataObjectType, OutputDataObjectType\n", |
| "\n", |
| "from oauthlib.oauth2 import LegacyApplicationClient\n", |
| "from requests_oauthlib import OAuth2Session\n", |
| "from oauthlib.oauth2 import BackendApplicationClient" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Getting OAuth Access Code from IDP" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 2, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "client_id = r'XXXXXXXXXXX'\n", |
| "client_secret = r'XXXXXXXXXXXX'\n", |
| "\n", |
| "client = BackendApplicationClient(client_id=client_id)\n", |
| "oauth = OAuth2Session(client=client)\n", |
| "token = oauth.fetch_token(token_url='https://idp.scigap.org:9443/oauth2/token', client_id=client_id, client_secret=client_secret)\n", |
| "authzToken = AuthzToken(token[\"access_token\"])\n", |
| "\n", |
| "claimsMap = {\"userName\":\"admin\",\"gatewayID\": \"seagrid\"}\n", |
| "authzToken.claimsMap = claimsMap\n", |
| "\n", |
| "userName = \"admin\"\n", |
| "gatewayId = \"seagrid\"" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Creating Airavata Client" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 3, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "data": { |
| "text/plain": [ |
| "'0.16.0'" |
| ] |
| }, |
| "execution_count": 3, |
| "metadata": {}, |
| "output_type": "execute_result" |
| } |
| ], |
| "source": [ |
| "transport = TSSLSocket.TSSLSocket(\"gw56.iu.xsede.org\",9930, validate=False)\n", |
| "transport = TTransport.TBufferedTransport(transport)\n", |
| "protocol = TBinaryProtocol.TBinaryProtocol(transport)\n", |
| "airavataClient = Airavata.Client(protocol)\n", |
| "transport.open()\n", |
| "\n", |
| "#Testing the Airavata Client\n", |
| "airavataClient.getAPIVersion(authzToken)" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## List User Projects" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 4, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "TestProject487543_b6ba13ff-4af5-4cf1-a5d4-9a7908cd338e\n", |
| "TestProject0398576_bb39d722-e136-41d2-89fd-a2e60e15c841\n", |
| "TestProject984752_9d011ce9-24ea-41a7-a40c-0192cbdb475f\n", |
| "TestProject81724_f4dde490-2e23-4308-b2c7-0cc2454520f0\n", |
| "TestProj5_e8b872d9-17ed-4f13-9007-40cd71df6450\n", |
| "TestProj4_ca7b95df-dd56-41b5-b112-d58b2748fc46\n", |
| "TestProj3_3ff3b1fc-70e0-4cfc-8581-b915209786a5\n", |
| "TheTestProj_397ccd77-0cb3-4c86-ba74-fb1954548085\n", |
| "TestProj_733ada60-2e88-4f52-a4f4-789c2795fc3e\n", |
| "testeroonius_61d70e07-78fc-4b82-a26b-24d37b2bd294\n", |
| "testeroonius_0e20b332-c694-4b90-9443-8403d46a1fcc\n", |
| "testeroonius_21e5f9aa-9fef-406d-9ff2-315ed7312efe\n", |
| "testeroonius_b31b789e-c61a-4eeb-828d-35edc2fcaa4b\n", |
| "testerooni_4a655ef7-b04b-4f6f-8481-216ebdb8437b\n", |
| "DefaultProject_9f56c72c-51ef-461e-bad8-6595af42b8de\n" |
| ] |
| } |
| ], |
| "source": [ |
| "projects = airavataClient.getUserProjects(authzToken, gatewayId, userName, -1, 0)\n", |
| "for p in projects:\n", |
| " print(p.projectID)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 5, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "selectedProjId = \"TestProj3_3ff3b1fc-70e0-4cfc-8581-b915209786a5\"" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## List of Applications Available in the Gateway" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 6, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "Echo_3f480d1f-ea86-4018-94bb-015423d66a1c\n", |
| "Amber_Sander_27b68571-b9c0-4bd5-bd70-e29435fa81bd\n", |
| "Gaussian_377feede-4d67-4065-984f-284d05c7d32d\n", |
| "Gromacs_c56857f1-c5d5-491b-b5ac-3f8165fdfc7a\n", |
| "Abinit_69939a97-17b8-472c-bdf3-81a41de57b74\n", |
| "AutoDock_6140eb97-af55-458d-a610-0e6cfee82487\n", |
| "CP2K_e9f82e52-dd78-4733-81ef-e163443efae5\n", |
| "CPMD_2038f63a-42a2-45df-b5fb-8916c1df8fc8\n", |
| "DDSCat_7911e731-2a8f-47fa-9ec2-e97f94ddbe7a\n", |
| "DFTB+_3b6232a4-3584-42bd-a0fb-452e56fc1c97\n", |
| "Gamess_9014bed7-f6a9-4bf6-8903-3531fce6adfe\n", |
| "Gamess_BR2_4a9a65dd-d9ea-45ff-a752-44614cf78dce\n", |
| "Gamess_Stampede_b8e90ce5-81ab-42ab-be57-304f2cdeb69e\n", |
| "Gromacs_CrayMPI_579f6463-10bb-4f06-9b6c-2e43589aaed3\n", |
| "Lammps_09de4f61-45b8-4c24-90c6-ebe718958728\n", |
| "Lammps_BR2_090f5f20-bb8e-4b96-a0fa-85cea7aec2f1\n", |
| "Molcas_89d5feb0-b1f1-437a-baef-9f353debd145\n", |
| "NWChem_e21df4ce-0c8e-422b-9e79-e0e7d56fad1f\n", |
| "Qchem_5e2f490a-25da-4631-a96d-d6f428e77ad5\n", |
| "Quantum_Espresso_fa1c5f04-bc52-4e91-8fd7-dbd1bcb1e39b\n", |
| "Tinker_Monte_1afae7f3-7c02-4fc6-8c67-8378c65a88b3\n", |
| "Abaqus_dcf7df79-5564-46db-88c4-837207882fdb\n", |
| "NEK5000_8ca957b3-6037-4535-9e02-005eb7dafd2d\n", |
| "Test-Application-Interface_39f9229d-c3b6-4251-90ec-c76265aafde8\n", |
| "Tes-App-Int_3efc89dc-d03a-4abb-af33-d7f242e9c656\n", |
| "TestAppInt1_2776c902-3200-4363-ab1e-ff99adc643cf\n", |
| "Test1_9c82fb1e-54da-42e8-87ae-6e3e1b1b8951\n", |
| "AutoDock_Vina_dcb6a898-fef3-4bed-b2d3-9aad45b42131\n", |
| "TestAppInt2_458c30d2-5f29-45b9-acd8-953315c6a730\n", |
| "Phasta_P_61030007-7243-4c6c-b13c-e7287670a847\n", |
| "Vina_Multiple_85771219-f188-48da-8dfe-422eea72c1ff\n", |
| "Vina_Optional_Ligands_a32ee927-f205-49a1-9a6f-c03e4a24aefc\n", |
| "Trinity_33a4a5ab-8d69-4477-a72d-0bd0cd7f3926\n" |
| ] |
| } |
| ], |
| "source": [ |
| "appInterfaces = airavataClient.getAllApplicationInterfaces(authzToken, gatewayId)\n", |
| "for interface in appInterfaces:\n", |
| " print(interface.applicationInterfaceId)" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Listing all Compute Resource with Echo App Enabled" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 7, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "selectedInterfaceId = \"Echo_3f480d1f-ea86-4018-94bb-015423d66a1c\"\n", |
| "availableCompRes = airavataClient.getAvailableAppInterfaceComputeResources(authzToken, selectedInterfaceId)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 8, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "bigred2.uits.iu.edu_ac140dca-3c88-46d8-b9ed-875d96ea6908 bigred2.uits.iu.edu\n" |
| ] |
| } |
| ], |
| "source": [ |
| "for k in availableCompRes:\n", |
| " print(k + \" \" + availableCompRes[k])" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 9, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "selectedCompResId = \"bigred2.uits.iu.edu_ac140dca-3c88-46d8-b9ed-875d96ea6908\"" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Creating the Experiment Object" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 10, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "experiment = ExperimentModel()\n", |
| "experiment.experimentName = \"Simple Echo Experiment \" + str(random.random())\n", |
| "experiment.projectId = selectedProjId\n", |
| "experiment.gatewayId = gatewayId\n", |
| "experiment.userName = userName\n", |
| "experiment.description = \"Simple Echo Experiment\"\n", |
| "experiment.executionId = selectedInterfaceId" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 11, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "echoInterface = airavataClient.getApplicationInterface(authzToken, selectedInterfaceId)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 12, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "inputs = echoInterface.applicationInputs\n", |
| "inputs[0].value = \"Hello World\"\n", |
| "\n", |
| "experiment.experimentInputs = inputs\n", |
| "experiment.experimentOutputs = echoInterface.applicationOutputs" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 13, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "compResource = airavataClient.getComputeResource(authzToken, selectedCompResId)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 14, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "data": { |
| "text/plain": [ |
| "[BatchQueue(maxJobsInQueue=0, maxNodes=128, maxRunTime=2880, maxMemory=0, queueDescription='The routing queue for all \"production\" jobs; each job is routed, based on its resource requirements, to one of the execution queues (normal, serial, or long)', maxProcessors=4096, queueName='cpu'),\n", |
| " BatchQueue(maxJobsInQueue=0, maxNodes=21824, maxRunTime=0, maxMemory=0, queueDescription='GPU queue', maxProcessors=1364, queueName='gpu')]" |
| ] |
| }, |
| "execution_count": 14, |
| "metadata": {}, |
| "output_type": "execute_result" |
| } |
| ], |
| "source": [ |
| "compResource.batchQueues" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 15, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "queueName = \"cpu\"\n", |
| "\n", |
| "computationalRS = ComputationalResourceSchedulingModel()\n", |
| "computationalRS.resourceHostId = selectedCompResId\n", |
| "computationalRS.totalCPUCount = 16\n", |
| "computationalRS.nodeCount = 1\n", |
| "computationalRS.numberOfThreads = 1\n", |
| "computationalRS.queueName = queueName\n", |
| "computationalRS.wallTimeLimit = 10\n", |
| "computationalRS.totalPhysicalMemory = 1\n", |
| "\n", |
| "userConfig = UserConfigurationDataModel()\n", |
| "userConfig.airavataAutoSchedule = True\n", |
| "userConfig.overrideManualScheduledParams = False\n", |
| "userConfig.computationalResourceScheduling = computationalRS\n", |
| "\n", |
| "experiment.userConfigurationData = userConfig" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Create & Launch Experiment" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 16, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "Experiment Id is SimpleEchoExperiment0.666940363066_ed483ef9-f87f-402d-a25c-881b1d6cc6ac\n" |
| ] |
| } |
| ], |
| "source": [ |
| "transport.open()\n", |
| "expId = airavataClient.createExperiment(authzToken, gatewayId, experiment)\n", |
| "print (\"Experiment Id is \" + expId)\n", |
| "airavataClient.launchExperiment(authzToken, expId, gatewayId)" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Retreiving Experiment Status" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 17, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "LAUNCHED\n" |
| ] |
| } |
| ], |
| "source": [ |
| "transport.open()\n", |
| "status = airavataClient.getExperimentStatus(authzToken, expId)\n", |
| "print(ExperimentState._VALUES_TO_NAMES[status.state])" |
| ] |
| } |
| ], |
| "metadata": { |
| "kernelspec": { |
| "display_name": "Python 2", |
| "language": "python", |
| "name": "python2" |
| }, |
| "language_info": { |
| "codemirror_mode": { |
| "name": "ipython", |
| "version": 2 |
| }, |
| "file_extension": ".py", |
| "mimetype": "text/x-python", |
| "name": "python", |
| "nbconvert_exporter": "python", |
| "pygments_lexer": "ipython2", |
| "version": "2.7.12" |
| } |
| }, |
| "nbformat": 4, |
| "nbformat_minor": 0 |
| } |