...
 
Commits (64)
variables:
GIT_STRATEGY: none
stages:
- build
- doc
westpy_build:
tags: [rcc,docker,node-01]
stage: build
image: ubuntu:latest
before_script:
- echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
- apt-get update > /dev/null
- apt-get install -qq apt-utils > /dev/null
- apt-get install -qq dialog apt-utils -y > /dev/null
- apt-get install -qq build-essential > /dev/null
- apt-get install -qq pkg-config > /dev/null
- apt-get install -qq libpng-dev > /dev/null
- apt-get install -qq pandoc > /dev/null
- apt-get install -qq wget git > /dev/null
- export PY_DIR="/opt/anaconda"
- cd /opt
- wget https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
- /bin/bash /opt/Anaconda3-5.2.0-Linux-x86_64.sh -b -p $PY_DIR
- export PATH=$PY_DIR/bin:$PATH
- conda upgrade conda
- conda upgrade scipy numpy matplotlib scikit-learn
- conda update --prefix $PY_DIR anaconda
- which python
script:
- git clone -b $CI_COMMIT_REF_NAME $CI_REPOSITORY_URL westpy
- cd westpy
- git describe
- make
westpy_doc_build:
tags: [rcc,docker,node-01]
stage: doc
image: debian:7
before_script:
- echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
- apt-get update > /dev/null
- apt-get install -qq build-essential > /dev/null
- apt-get install -qq apt-utils > /dev/null
- apt-get install -qq wget git > /dev/null
- apt-get -qq install vim > /dev/null
- apt-get -qq install zlib1g-dev > /dev/null
- apt-get -qq install libssl-dev > /dev/null
- export TZ="US/Central"
- rm -f /etc/localtime
- cp /usr/share/zoneinfo/$TZ /etc/localtime
- apt-get install -qq texlive-latex-base > /dev/null
- apt-get install -qq latex2html > /dev/null
- apt-get install -qq pandoc > /dev/null
- cd /opt
- export PY_VERSION="3.5.4"
- wget https://www.python.org/ftp/python/$PY_VERSION/Python-$PY_VERSION.tgz
- tar -xzf Python-$PY_VERSION.tgz
- cd Python-$PY_VERSION
- export PY_DIR="/opt/python"
- ./configure --prefix $PY_DIR
- make
- make install
- ln -s $PY_DIR/bin/python3.5 $PY_DIR/bin/python
- export PATH=$PY_DIR/bin:$PATH
- wget https://bootstrap.pypa.io/get-pip.py
- which python
- python get-pip.py
- pip install nbsphinx
- pip install sphinx_rtd_theme
- pip install ipython
script:
- git clone -b $CI_COMMIT_REF_NAME $CI_REPOSITORY_URL westpy
- cd westpy
- git describe
- cd doc
- make html
- ls _build/html
# Project Leads
- Marco Govoni (Argonne National Laboratory and University of Chicago)
## Developers
- He Ma (University of Chicago)
- Aditya Tanikanti (University of Chicago)
- Han Yang (University of Chicago)
- Huihuo Zheng (Argonne National Laboratory)
......@@ -15,5 +15,6 @@ Developers
----------
- He Ma (University of Chicago)
- Aditya Tanikanti (University of Chicago)
- Han Yang (University of Chicago)
- Huihuo Zheng (Argonne National Laboratory)
......@@ -64,7 +64,7 @@ author = u'Marco Govoni'
# built documents.
#
# The short X.Y version.
version = '3.1.0'
version = '3.1.1'
# The full version, including alpha/beta/rc tags.
release = version
......
......@@ -10,6 +10,7 @@ The software is tested for python version 3.x and has the following dependencies
- ``numpy``
- ``scipy``
- ``matplotlib``
- ``pyyaml``
- ``datetime``
- ``requests``
- ``mendeleev``
......
......@@ -61,3 +61,11 @@ Electronic Structure
:members:
:undoc-members:
:show-inheritance:
Session
-------
.. automodule:: westpy.session
:members:
:undoc-members:
:show-inheritance:
......@@ -13,3 +13,4 @@ Contents:
tutorials/westpy_100.ipynb
tutorials/westpy_101.ipynb
tutorials/westpy_200.ipynb
tutorials/westpy_300.ipynb
......@@ -47,8 +47,8 @@
" | | __/ | \n",
" |_| |___/ \n",
" \n",
"WEST version : 3.1.0\n",
"Today : 2018-06-29 15:23:25.768394\n"
"WEST version : 3.1.1\n",
"Today : 2018-09-19 15:21:13.244247\n"
]
}
],
......@@ -395,7 +395,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.0"
}
},
"nbformat": 4,
......
......@@ -47,8 +47,8 @@
" | | __/ | \n",
" |_| |___/ \n",
" \n",
"WEST version : 3.1.0\n",
"Today : 2018-06-29 15:23:42.948747\n"
"WEST version : 3.1.1\n",
"Today : 2018-09-19 15:21:57.535713\n"
]
}
],
......@@ -259,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.0"
}
},
"nbformat": 4,
......
This diff is collapsed.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.0 RESTful Tutorials"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will show here how to interact with the remote server where the `pw.x`, `wstat.x` and `wfreq.x` are already installed."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We start by importing WESTPy and generating a ground state input file for methane. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" \n",
" _ _ _____ _____ _____ \n",
"| | | | ___/ ___|_ _| \n",
"| | | | |__ \\ `--. | |_ __ _ _ \n",
"| |/\\| | __| `--. \\ | | '_ \\| | | | \n",
"\\ /\\ / |___/\\__/ / | | |_) | |_| | \n",
" \\/ \\/\\____/\\____/ \\_/ .__/ \\__, | \n",
" | | __/ | \n",
" |_| |___/ \n",
" \n",
"WEST version : 3.1.1\n",
"Today : 2018-09-19 15:33:45.581889\n"
]
}
],
"source": [
"from westpy import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"geom = Geometry()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"geom.setCell((25,0,0),(0,25,0),(0,0,25))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"geom.addAtomsFromOnlineXYZ( \"http://www.west-code.org/doc/training/methane/CH4.xyz\" )"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"geom.addSpecies( \"C\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf\")\n",
"geom.addSpecies( \"H\", \"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"gs = GroundState(geom,xc=\"PBE\",ecut=40.0)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Generated file: pw.in\n"
]
}
],
"source": [
"gs.generateInputPW()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now create a session on the remote server."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Check the inbox/spam folder of your email and click on the link to activate the session\n"
]
}
],
"source": [
"session = Session(\"your.email@domain.edu\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Active': 'True', 'Time Left': '59 minutes'}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"session.status()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requested to run executable pw on server imedevel.uchicago.edu\n",
"Generated pw.out\n"
]
}
],
"source": [
"download = [\"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf\",\"http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf\"]\n",
"pw_output = session.run(\"pw\",\"pw.in\",\"pw.out\",download,3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now generate the input for `wstat.x`."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"File written : wstat.in\n"
]
}
],
"source": [
"data = {}\n",
"data[\"input_west\"] = {}\n",
"data[\"input_west\"][\"qe_prefix\"] = \"calc\"\n",
"data[\"input_west\"][\"west_prefix\"] = \"calc\"\n",
"data[\"input_west\"][\"outdir\"] = \"./\"\n",
"data[\"wstat_control\"] = {}\n",
"data[\"wstat_control\"][\"wstat_calculation\"] = \"S\"\n",
"data[\"wstat_control\"][\"n_pdep_eigen\"] = 5\n",
"\n",
"writeJsonFile(\"wstat.in\",data)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requested to run executable wstat on server imedevel.uchicago.edu\n",
"Generated wstat.out\n"
]
}
],
"source": [
"wstat_output = session.run(\"wstat\",\"wstat.in\",\"wstat.out\",download,3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now generate the input for `wfreq.x`."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"File written : wfreq.in\n"
]
}
],
"source": [
"data[\"wfreq_control\"] = {}\n",
"data[\"wfreq_control\"][\"wfreq_calculation\"] = \"XWGQ\"\n",
"data[\"wfreq_control\"][\"n_pdep_eigen_to_use\"] = 5\n",
"data[\"wfreq_control\"][\"qp_bandrange\"] = [1,5]\n",
"data[\"wfreq_control\"][\"n_refreq\"] = 300\n",
"data[\"wfreq_control\"][\"ecut_refreq\"] = 2.0\n",
"\n",
"writeJsonFile(\"wfreq.in\",data)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requested to run executable wfreq on server imedevel.uchicago.edu\n",
"Generated wfreq.out\n"
]
}
],
"source": [
"wfreq_output = session.run(\"wfreq\",\"wfreq.in\",\"wfreq.out\",download,3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now stop the session."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Success': 'Session removed and cleared'}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"session.stop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
from setuptools import setup
from setuptools import find_packages
with open("README.md", "r") as fh:
long_description = fh.read()
setup(name='westpy',
version='3.1.0',
packages=['westpy'],
version='3.1.1',
packages=find_packages(),
description='Python analysis tools for WEST',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/west-code-development/westpy.git',
author='Marco Govoni',
author_email='mgovoni@anl.gov',
......@@ -12,10 +18,16 @@ setup(name='westpy',
'numpy',
'scipy',
'matplotlib',
'pyyaml',
'datetime',
'requests',
'mendeleev',
'signac'
'mendeleev',
'signac',
'setuptools',
'urllib3',
'prompt-toolkit<2.0.0',
'sphinx',
'sphinx_rtd_theme'
],
python_requires='>=2.7, >=3.0, !=3.0.*, !=3.1.*, !=3.2.*, <4',
zip_safe=True)
......@@ -7,8 +7,9 @@ from westpy.geometry import *
from westpy.groundState import *
from westpy.dataContainer import *
from westpy.electronicStructure import *
from westpy.session import *
__version__ = '3.1.0'
__version__ = '3.1.1'
def header() :
"""Prints welcome header."""
......
from __future__ import print_function
import requests
import json
from ast import literal_eval
class GroundState() :
"""Class for representing a ground state calculation with DFT.
......@@ -33,7 +36,7 @@ class GroundState() :
self.nempty = 0
self.kmesh = "gamma"
self.isolated = False
self.spin = {}
self.spin = {}
#
def setNempty(self,nempty) :
"""Sets the number of empty bands.
......@@ -258,4 +261,4 @@ class GroundState() :
.. note:: You can use this method to add either upf or xml pseudopotentials. However it is forbidded to mix them.
"""
self.geom.addSpecies(symbol,url)
self.geom.addSpecies(symbol,url)
from __future__ import print_function
class Session(object):
"""Class for setting up a session, connected to a remove server via rest APIs.
:Example:
>>> from westpy import *
>>> session = Session("your.email@domain.edu")
"""
def __init__(self,emailId) :
self.token = None
self.emailId = str(emailId)
#
# --- CONFIGURABLE PARAMETERS ---
self.serverName = "imedevel.uchicago.edu"
self.restAPIinit = "http://imedevel.uchicago.edu:8000/init"
self.restAPIrun = "http://imedevel.uchicago.edu:8000/run"
self.restAPIstop = "http://imedevel.uchicago.edu:8000/stop"
self.restAPIstatus = "http://imedevel.uchicago.edu:8000/status"
self.maxSessionTime = 3600 # seconds
self.maxWaitTime = 1800 # seconds
self.maxNumberOfCores = 4
self.allowedExecutables = ["pw","wstat","wfreq"]
# -------------------------------
#
data = {'emailId': self.emailId ,'sessionTime':str(self.maxSessionTime)}
#
import requests
import json
#
response = None
try:
output = requests.post(self.restAPIinit, data=json.dumps(data))
response = json.loads(output.text)
except Exception as e:
print('The server is not responding.',e)
if response:
if "Error" in response:
print("Server failed with the following error \n",response['Error'])
return None
else:
print("Check the inbox/spam folder of your email and click on the link to activate the session")
self.token = response["token"]
else:
print('The server is not responding.')
def getToken(self):
"""Returns the token of the session.
:Example:
>>> from westpy import *
>>> session = Session("your.email@domain.edu")
>>> token = session.getToken()
>>> print(token)
"""
if self.token :
return self.token
else:
raise ValueError("Cannot find output.")
def stop(self):
"""Stops the session and clears the remote workspace.
:Example:
>>> from westpy import *
>>> session = Session("your.email@domain.edu")
>>> session.stop()
"""
import requests
import json
#
headers = {'Content-Type':'application/json; charset=utf-8','emailId':self.emailId,'token':self.token}
try:
response = requests.get(self.restAPIstop, headers=headers, timeout=None)
except Exception as e:
print('The server is not responding.',e)
return json.loads(response.text)
def status(self):
"""Returns whether the session is active and time left.
:Example:
>>> from westpy import *
>>> session = Session("your.email@domain.edu")
>>> session.status()
"""
import requests
import json
#
headers = {'Content-Type':'application/json; charset=utf-8','emailId':self.emailId,'token':self.token}
try:
response = requests.get(self.restAPIstatus, headers=headers, timeout=None)
except Exception as e:
print('The server is not responding.',e)
return json.loads(response.text)
def run(self,executable=None,inputFile=None,outputFile=None,downloadUrl=[],number_of_cores=2) :
"""Runs the executable on the remote server.
:param executable: name of executable
:type executable: string
:param inputFile: name of input file
:type inputFile: string
:param outputFile: name of output file
:type outputFile: string
:param downloadUrl: URLs to be downloaded
:type downloadUrl: list of string
:param number_of_cores: number of cores
:type number_of_cores: int
:Example:
>>> from westpy import *
>>> session = Session("your.email@domain.edu")
>>> session.run( "pw", "pw.in", "pw.out", ["http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf"] , 2 )
>>> session.stop()
"""
#
import json
#
assert( number_of_cores <= self.maxNumberOfCores )
#
output_dict = {}
if executable in self.allowedExecutables :
# set inputs
if inputFile is None:
inputFile = str(executable)+".in"
if outputFile is None:
outputFile = str(executable)+".out"
try:
output = self.__runExecutable(executable,inputFile,downloadUrl,number_of_cores)
output_json = json.loads(output)
if "Error" in output_json:
print("Server failed with the following error \n",output_json['Error'])
return None
elif "JOB DONE." not in str(output_json['output']).strip():
print("MPI execution failed with the following error: \n"+str(output))
return None
output_data = str(output_json['output']).strip()
if "pw" in executable:
output_dict = json.loads(output_json['output_dict'])
else:
output_dict = output_json['output_dict']
# write the output file
with open(outputFile, "w") as file :
file.write(str(output_data))
except Exception as e:
print("Session Expired! Invalid Request sent, Please recreate session and recheck your input. \n"+ str(e))
return None
else:
raise ValueError("Invalid executable name")
#
print("Generated ",outputFile)
return output_dict
def __runExecutable(self,executable,input_file,download_urls,number_of_cores) :
"""Runs remotely the executable using a REST api.
"""
#
import requests
import json
# suck in the input file
try:
file_content = ""
with open(input_file,'r') as f :
for line in f :
file_content = file_content + line + "\\n"
except FileNotFoundError:
error = "Could not find "+ input_file + ". \n Generate input file "+ input_file +" and try again."
print(error)
return None
body = {'urls':download_urls,'file':file_content,'cmd_timeout':str(self.maxWaitTime),'script_type':str(executable),'no_of_cores':str(number_of_cores)}
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes
headers = {'Content-Type':'application/json; charset=utf-8','emailId':self.emailId,'token':self.token}
response = ""
print("Requested to run executable", executable, "on server", self.serverName)
try:
response = requests.post(self.restAPIrun, data = jsondataasbytes, headers=headers, timeout=None)
return response.text
except Exception as e:
print('The server is not responding.',e)
return None
return None
......@@ -126,6 +126,27 @@ def readJsonFile(fname):
print("File read : ", fname )
return data
def convertYaml2Json(fyml,fjson):
"""Converts the file from YAML to JSON.
:param fyml: Name of YAML file
:type fyml: string
:param fjson: Name of JSON file
:type fjson: string
:Example:
>>> from westpy import *
>>> convertYaml2Json("file.yml","file.json")
.. note:: The file fjon will be created, fyml will not be overwritten.
"""
#
import yaml, json
from westpy import writeJsonFile
#
data = yaml.load(open(fyml))
writeJsonFile(fjson,data)
def listLinesWithKeyfromOnlineText(url,key):
"""List lines from text file located at url, with key.
......