Commit efe4f295 authored by Zachary Parks's avatar Zachary Parks
Browse files

adding auto-install (with prompt) if xacc-vqe is not installed with trying to...


adding auto-install (with prompt) if xacc-vqe is not installed with trying to install VQE benchmark plugins
Signed-off-by: default avatarZachary Parks <1zp@ornl.gov>
parent 4f890c51
......@@ -48,8 +48,8 @@ else()
set_target_properties(_pyxacc PROPERTIES LINK_FLAGS "-shared")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/benchmark/manage.py.in
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/manage.py)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/benchmark/manage.py.in
# ${CMAKE_CURRENT_SOURCE_DIR}/benchmark/manage.py)
install(TARGETS _pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES xacc.py DESTINATION ${CMAKE_INSTALL_PREFIX})
......
......@@ -6,17 +6,24 @@ import os
import configparser
from shutil import copy
import xacc
import sysconfig
import importlib
import ast
import subprocess
import inspect
MASTER_DIRS = ['vqe']
MASTER_PACKAGES = {}
REQUIREMENTS = {}
TOP_PATH = os.path.dirname(os.path.realpath(__file__))
XACC_PYTHON_PLUGIN_PATH = "/root/.xacc/py-plugins/"
# XACC_PYTHON_PLUGIN_PATH = "/root/.xacc/py-plugins/"
PLUGIN_INSTALLATIONS = {}
def parse_args(args):
parser = argparse.ArgumentParser(description="Installation manager for XACC benchmark plugins.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
......@@ -30,10 +37,35 @@ def parse_args(args):
def install_package(install_name):
try:
xacc.info("Retrieving package and checking requirements..")
package_path = PLUGIN_INSTALLATIONS[install_name]
for k,v in MASTER_PACKAGES.items():
if install_name in v:
requirement = REQUIREMENTS[k]['module']
mdir = k
print(requirement)
importlib.import_module(requirement)
except KeyError as ex:
xacc.info("There is no '{}' XACC Python plugin package available.".format(install_name))
exit(1)
# this might have to change as more packages and their requirements get added
# for now, it works fine, and should work fine for any XACC requirement
# that needs to be git-cloned and built with cmake-make (vqe)
except ModuleNotFoundError as ex:
xacc.info("You do not have the required Python module `{}` to install and run the '{}' XACC Python plugin package.".format(requirement, install_name))
yn = input("Install requirements? ")
if yn == "y":
dest = os.path.dirname(inspect.getfile(xacc))
install_path = os.path.join(dest, REQUIREMENTS[mdir]['dir'])
build_path = os.path.join(install_path, 'build')
os.chdir(dest)
subprocess.run(['git', 'clone', '--recursive', '{}'.format(REQUIREMENTS[mdir]['repo'])])
os.makedirs(build_path)
os.chdir(build_path)
subprocess.run(['cmake', '..', '-DXACC_DIR={}'.format(dest), '-DPYTHON_INCLUDE_DIR={}'.format(sysconfig.get_paths()['include'])])
subprocess.run(['make', '-j2', 'install'])
else:
exit(1)
install_directive = os.path.join(package_path+"/install.ini") if os.path.isfile(package_path+"/install.ini") else None
plugin_files = []
......@@ -61,6 +93,11 @@ def read_install_directive(install_file, parent):
results = {}
packages_here = []
for section in config.sections():
if section == "Requirements":
for req in config.items(section):
name, require = req
REQUIREMENTS[name] = ast.literal_eval(require)
else:
for installation in config.items(section):
name, folder = installation
packages_here.append(name)
......
......@@ -6,17 +6,26 @@ import os
import configparser
from shutil import copy
import xacc
import sysconfig
import importlib
import ast
import subprocess
import inspect
MASTER_DIRS = ['vqe']
MASTER_PACKAGES = {}
REQUIREMENTS = {}
REQUIRED_INSTALLS = {'xaccvqe': ['https://github.com/ornl-qci/xacc-vqe.git', 'xacc-vqe']}
TOP_PATH = os.path.dirname(os.path.realpath(__file__))
XACC_PYTHON_PLUGIN_PATH = "${CMAKE_INSTALL_PREFIX}/py-plugins/"
PLUGIN_INSTALLATIONS = {}
def parse_args(args):
parser = argparse.ArgumentParser(description="Installation manager for XACC benchmark plugins.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
......@@ -30,10 +39,32 @@ def parse_args(args):
def install_package(install_name):
try:
xacc.info("Retrieving package and checking requirements..")
package_path = PLUGIN_INSTALLATIONS[install_name]
for k,v in MASTER_PACKAGES.items():
if install_name in v:
requirement = REQUIREMENTS[k]['module']
mdir = k
print(requirement)
importlib.import_module(requirement)
except KeyError as ex:
xacc.info("There is no '{}' XACC Python plugin package available.".format(install_name))
exit(1)
except ModuleNotFoundError as ex:
xacc.info("You do not have the required Python module `{}` to install and run the '{}' XACC Python plugin package.".format(requirement, install_name))
yn = input("Install requirements? ")
if yn == "y":
dest = os.path.dirname(inspect.getfile(xacc))
install_path = dest + "/{}".format(REQUIREMENTS[mdir]['dir'])
build_path = os.path.join(install_path, 'build')
os.chdir(dest)
subprocess.run(['git', 'clone', '--recursive', '{}'.format(REQUIREMENTS[mdir]['repo'])])
os.makedirs(build_path)
os.chdir(build_path)
subprocess.run(['cmake', '..', '-DXACC_DIR={}'.format(dest), '-DPYTHON_INCLUDE_DIR={}'.format(sysconfig.get_paths()['include'])])
subprocess.run(['make', '-j2', 'install'])
else:
exit(1)
install_directive = os.path.join(package_path+"/install.ini") if os.path.isfile(package_path+"/install.ini") else None
plugin_files = []
......@@ -61,6 +92,12 @@ def read_install_directive(install_file, parent):
results = {}
packages_here = []
for section in config.sections():
if section == "Requirements":
for req in config.items(section):
name, require = req
REQUIREMENTS[name] = ast.literal_eval(require)
else:
for installation in config.items(section):
name, folder = installation
packages_here.append(name)
......
......@@ -6,3 +6,11 @@
chemistry: /chemistry
chem-hams: /chemistry/hamiltonian_generators
chem-ansatze: /chemistry/ansatz_generators
[Requirements]
# Put the master dir name (VQE) and the name of
# the Python module required to use the plugins
vqe: {"module": "xaccvqe",
"repo": "https://github.com/ornl-qci/xacc-vqe.git",
"dir": "xacc-vqe"}
\ No newline at end of file
Markdown is supported
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