From eda84945c6374bcb2b5fbc00aea2beb9fb4b59cc Mon Sep 17 00:00:00 2001 From: gsilvi Date: Tue, 13 Sep 2022 11:00:13 +0200 Subject: [PATCH] updated ReadMe --- .gitignore | 1 + QLMtools/package_installer.py | 77 ----------------------------------- QLMtools/uploader_library.py | 25 +----------- README.md | 19 +++++---- 4 files changed, 13 insertions(+), 109 deletions(-) delete mode 100644 QLMtools/package_installer.py diff --git a/.gitignore b/.gitignore index 5850373..2f4ce0f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ env/ .vscode/ misc/notebooks/Figs_august/* misc/notebooks/Figures/* +QLMtools/package_installer.py diff --git a/QLMtools/package_installer.py b/QLMtools/package_installer.py deleted file mode 100644 index bdf7cda..0000000 --- a/QLMtools/package_installer.py +++ /dev/null @@ -1,77 +0,0 @@ -from qat.qlmaas.upload import MetaLocalPlugin -# package intalled: qiskit==0.30.0 numpy myqlm-interop[qiskit_binder] qiskit_nature==0.2.0 sympy==1.8 psutil - - - -#install --user -class PackageInstaller(metaclass=MetaLocalPlugin): - """ - A remote plugin that uploads code to the remote QLM. - - """ - - def __init__(self, args): - print(f"Remotely executing: python3 -m pip {' '.join(args)}") - self.args = args - - def install_packages(self): - """ - Install the packages via pip - """ - import os - fout = os.path.expanduser("~/pip_log_out") - ferr = os.path.expanduser("~/pip_log_err") - os.system(f"python3 -m pip {' '.join(self.args)} > {fout} 2> {ferr}") - #install without looking into main folder for libraries - #os.system(f"""export PYTHONPATH="/usr/lib/python3.9/site-packages:/home_nfs/gsilvi/.local/lib/python3.9/site-packages/" ; python3 -m pip {' '.join(self.args)} > {fout} 2> {ferr}""") - #os.system(f"""export PYTHONPATH=$PYTHONPATH+":/home_nfs/gsilvi/.local/lib/python3.9/site-packages/" ;echo $PYTHONPATH > {fout} 2> {ferr}""") - #os.system(f'echo "__all__ = [\"interop\", \"core\", \"plugins\",\"qlmaas\",\"qpus\"]" >> /home_nfs/gsilvi/.local/lib/python3.9/site-packages/qat/__init__.py > {fout} 2> {ferr}') - #os.system(f"""ls ~/custom_qlm_code/qiskit_mod/qiskit_ter> {fout} 2> {ferr}""") - #os.system(f"""python3 -c 'import os; import qat; print(os.path.abspath(qat.__file__))' > {fout} 2> {ferr}""") - #os.system(f"""python3 -c 'import os;import sys;sys.path.remove("/usr/local/lib64/python3.9/site-packages");sys.path.remove("/usr/local/lib/python3.9/site-packages");sys.path.remove("/usr/lib64/python3.9/site-packages");sys.path.append(os.path.expanduser("/home_nfs/gsilvi/.local/lib/python3.9/site-packages/"));from importlib import import_module; print(import_module("qat.interop"))' > {fout} 2> {ferr}""") - #os.system(f"""python3 -c 'import os;import sys;import importlib.util; spec = importlib.util.spec_from_file_location("qat.interop.qiskit","/home_nfs/gsilvi/.local/lib/python3.9/site-packages/qat/interop/qiskit/__init__.py",submodule_search_locations=['']);module = importlib.util.module_from_spec(spec);spec.loader.exec_module(module); print(module, module.__file__); print(module.qiskit_to_qlm)' > {fout} 2> {ferr}""") - #### qiskit version below - # os.system(f"""python3 -c 'import os;import sys;\ - # sys.path.remove("/usr/local/lib64/python3.9/site-packages");\ - # sys.path.remove("/usr/local/lib/python3.9/site-packages");\ - # sys.path.remove("/usr/lib64/python3.9/site-packages");\ - # sys.path.append(os.path.expanduser("/home_nfs/gsilvi/.local/lib/python3.9/site-packages/"));\ - # import qat;\ - # print(os.path.abspath(qat.__file__))' > {fout} 2> {ferr}""") - #os.system(f"""python3 -c 'import sys; import os;sys.path.append(os.path.expanduser("/home_nfs/gsilvi/.local/lib/python3.9/site-packages/")); import qiskit; print(qiskit.__qiskit_version__)' > {fout} 2> {ferr}""") - #os.system(f"cp /usr/lib64/python3.9/zipfile.py /home_nfs/gsilvi/.local/lib/python3.9/site-packages/zipfile.py > {fout} 2> {ferr}") - data_out = "" - data_err = "" - with open(fout, 'r') as fin: - data_out = fin.read() - - with open(ferr, 'r') as fin: - data_err = fin.read() - return data_out, data_err - - def compile(self, _batch, _specs): - """ - """ - out, err = self.install_packages() - _batch.meta_data = {"out": out, "err": err} - return _batch - - def install_remotely(self): - """ - Install the packages remotely - """ - from qlmaas.plugins import UploadedPlugin - from qat.core import Batch, HardwareSpecs - plugin = UploadedPlugin(plugin=self) - - result = plugin.compile(Batch(), HardwareSpecs()) - result = result.join() - print(result.meta_data['out']) - print(result.meta_data['err']) - - -if __name__ == "__main__": - import sys - installer = PackageInstaller(sys.argv[1:]) - installer.install_packages() - installer.install_remotely() \ No newline at end of file diff --git a/QLMtools/uploader_library.py b/QLMtools/uploader_library.py index b85f52b..d8acf5c 100644 --- a/QLMtools/uploader_library.py +++ b/QLMtools/uploader_library.py @@ -57,25 +57,7 @@ def upload(self): print("Starting upload and updating the remote configuration") result = plugin.compile(Batch(), HardwareSpecs()) # Compile the plugin, this will trigger the copy of the files print("Updating remote configuration (to publish the code)...") - # connection = QLMaaSConnection() # Create the connection - # new_paths = [self.path] # Create the new paths - # new_modules = [] # Create the new modules - # for fname in self.files: # For each file - # module_name = fname.replace(".py", "").replace("./", "") # Get the module name, removing the extension - # new_modules.append(module_name) # Add the module name to the list - # print(">> uploading new configuration") - # connection.update_config(new_paths, new_modules, False) # Update the configuration, this will publish the code - # print("Checking if the upload finished") - # result.join() # Wait for the upload to finish - # print("Done!") - # config = connection.get_config() # Get the configuration - # new_paths = list(set(config.paths)) # Get the new paths - # new_modules = list(set(config.modules)) # Get the new modules - # connection.update_config(new_paths, new_modules, True) # Update the configuration, this will publish the code - # import os - # # os.system("python3 -m pip list") - # # os.system("python3 --version") - # print(f"The new configuration is:\n{connection.get_config()}") + import os import itertools @@ -83,10 +65,7 @@ def upload(self): path2 = "../qiskit_mod/qiskit_ter/" paths = [path1, path2] -# for (dirpath, dirnames, filenames) in itertools.chain.from_iterable(os.walk(path) for path in paths): -# print(dirpath) -# filenames = [dirpath + s for s in filenames] -# f.extend(filenames) + for path in paths: f = [] for item in os.listdir(path): diff --git a/README.md b/README.md index 66b2b3a..8aed36b 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,16 @@ This repositorycollects Python scripts and Jupyter notebooks that allow the user that are built upon Qiskit libraries. The repository is organized as follows: -- 'misc' folder contain the notebooks and scripts that showcase the variational algorithms -- 'qiskit_mod' contains our custom functions that are built upon Qiskit libraries as well as the QLM custom junction and helpers: - - 'qiskit_nat' the customize function built upon qiskit_nature - - 'qiskit_ter' the customize function built upon qiskit_terra - - 'my_junction.py' the QLM custom junction used to run the variational algorithms with QLM backends - - 'uploader_junction.py' helper to upload the junction to QLMaaS server, so that it can be found in the remote library - - 'wrapper2myqlm.py' helper to wrap the variational algorithms using QLM stack -- 'tests' unit tests for the variational algorithms - +- **misc** contain the notebooks and scripts that showcase the variational algorithms +- **qiskit_mod** contains our custom functions that are built upon Qiskit libraries as well as the QLM custom junction and helpers: + - **qiskit_nat** the customize function built upon qiskit_nature + - **qiskit_ter** the customize function built upon qiskit_terra + - *my_junction.py* the QLM custom junction used to run the variational algorithms with QLM backends + - *uploader_junction.py* helper to upload the junction to QLMaaS server, so that it can be found in the remote library + - *wrapper2myqlm.py* helper to wrap the variational algorithms using QLM stack +- **tests** unit tests for the variational algorithms +- **QLMtools** additional tools to upload qiskit_mod to QLMaaS server + - *uploader_library.py* helper to upload the qiskit_mod library to QLMaaS server ## Licence The `LICENCE` file contains the default licence statement as specified in the proposal and partner agreement.