diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000000000000000000000000000000000..b0386a89b7d3359a7aba7d8fce707728858fbaeb --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include src/squic/*.so +include src/squic/*.dylib \ No newline at end of file diff --git a/README.md b/README.md index 4eaecea4cf638e589745abfc8d1e1af412183d3e..f9706894ccef6ae452c46c2c55f1d55b952df388 100644 --- a/README.md +++ b/README.md @@ -4,34 +4,36 @@ SQUIC is a second-order, L1-regularized maximum likelihood method for performant ## Installation -#### Step 1: +#### Step 1: Download the shared library libSQUIC from www.gitlab.ci.inf.usi.ch/SQUIC/libSQUIC, and follow its README instructions. The default and recommended location for libSQUIC is the home directory, i.e., ``~/``. -#### Step 2: +#### Step 2: Run the following command to install the library: ```angular2 -pip install SQUIC +pip install squic ``` -#### Step 3: +#### Step 3: +Export the variable ``SQUIC_LIB_PATH`` with the location of the library downloaded in Step1, example: +```angular2 +export SQUIC_LIB_PATH=~/SQUIC_LIB +``` +#### Step 3: Load the SQUIC package: ```angular2 -import SQUIC +import squic ``` -For further details type ``help(SQUIC)`` in the Python command line. +For further details type ``help(squic)`` in the Python command line. _Note: The number of threads used by SQUIC can be defined by setting the enviroment variable OMP_NUM_THREADS (e.g., ``base> export OMP_NUM_THREADS=12``). This may require a restart of the session)._ ## Example -To run a simple example : +To run a simple example : ```angular2 -import SQUIC +import squic import numpy as np -# set location of libSQUIC (set after importing package) -SQUIC.PATH_TO_libSQUIC('/path/to/squic') - # generate sample from tridiagonal precision matrix p = 1024 n = 100 @@ -46,5 +48,5 @@ iC_star = np.diag(a,-1) + np.diag(b,0) + np.diag(a,1) L = np.linalg.cholesky(iC_star) Y = np.linalg.solve(L.T,np.random.randn(p,n)) -[X,W,info_times,info_objective,info_logdetX,info_trSX] = SQUIC.run(Y,l) +[X,W,info_times,info_objective,info_logdetX,info_trSX] = squic.run(Y,l) ``` diff --git a/SQUIC_Py.pyc b/SQUIC_Py.pyc deleted file mode 100644 index 126014f27f3b37069a32ed482dfba34f85a97128..0000000000000000000000000000000000000000 Binary files a/SQUIC_Py.pyc and /dev/null differ diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/__pycache__/SQUIC_Py.cpython-39.pyc b/__pycache__/SQUIC_Py.cpython-39.pyc deleted file mode 100644 index 37cf9acc3ed6b3fd1f1317c662539acf3ef57b4e..0000000000000000000000000000000000000000 Binary files a/__pycache__/SQUIC_Py.cpython-39.pyc and /dev/null differ diff --git a/dist/SQUIC-1.0.0-py3-none-any.whl b/dist/SQUIC-1.0.0-py3-none-any.whl deleted file mode 100644 index d1793a9ef45f8b4b47023ef3c1f485e5be1f8175..0000000000000000000000000000000000000000 Binary files a/dist/SQUIC-1.0.0-py3-none-any.whl and /dev/null differ diff --git a/dist/SQUIC-1.0.0.tar.gz b/dist/SQUIC-1.0.0.tar.gz deleted file mode 100644 index 631eb48d8ffcdbc372661aba1296f4b7c7dfe6df..0000000000000000000000000000000000000000 Binary files a/dist/SQUIC-1.0.0.tar.gz and /dev/null differ diff --git a/setup.cfg b/setup.cfg index 9cc32056823eb760f1baa6bf906c5cd3c6e290c5..85e6e85e17b95044b12426860d0b67bbfbdee1da 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = SQUIC +name = squic version = 1.0.0 author = Aryan Eftekhari, Lisa Gaedke-Merzhaeuser, Dimosthenis Pasadakis, Matthias Bollhoefer, Simon Scheidegger, Olaf Schenk description = SQUIC is a second-order, L1-regularized maximum likelihood method for performant large-scale sparse precision matrix estimation. This repository contains the source code for the Python interface of SQUIC. @@ -20,6 +20,6 @@ python_requires = >=3.6 install_requires = numpy scipy - +include_package_data = True [options.packages.find] where = src diff --git a/setup.py b/setup.py index c1057cf5d658ec48813a07f313e27b0530024e5b..606849326a4002007fd42060b51e69a19c18675c 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,3 @@ -import setuptools +from setuptools import setup -setuptools.setup() \ No newline at end of file +setup() diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index e19a04cf930bd943e0497b3afdf6c6308591b544..0000000000000000000000000000000000000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/SQUIC.egg-info/PKG-INFO b/src/SQUIC.egg-info/PKG-INFO deleted file mode 100644 index 08b3b98162e9746c99a845f572ecc1cc537c02ed..0000000000000000000000000000000000000000 --- a/src/SQUIC.egg-info/PKG-INFO +++ /dev/null @@ -1,68 +0,0 @@ -Metadata-Version: 2.1 -Name: SQUIC -Version: 1.0.0 -Summary: SQUIC is a second-order, L1-regularized maximum likelihood method for performant large-scale sparse precision matrix estimation. This repository contains the source code for the Python interface of SQUIC. -Home-page: https://www.gitlab.ci.inf.usi.ch/SQUIC/SQUIC_Python -Author: Aryan Eftekhari, Lisa Gaedke-Merzhaeuser, Dimosthenis Pasadakis, Matthias Bollhoefer, Simon Scheidegger, Olaf Schenk -License: UNKNOWN -Platform: UNKNOWN -Classifier: Programming Language :: Python :: 3 -Classifier: Operating System :: POSIX :: Linux -Classifier: Operating System :: MacOS -Classifier: License :: OSI Approved :: GNU General Public License (GPL) -Requires-Python: >=3.6 -Description-Content-Type: text/markdown -License-File: LICENSE - -# SQUIC Python3 Interface Package - -SQUIC is a second-order, L1-regularized maximum likelihood method for performant large-scale sparse precision matrix estimation. This repository contains the source code for the Python(v3) interface of SQUIC. - -## Installation - -#### Step 1: -Download the shared library libSQUIC from www.gitlab.ci.inf.usi.ch/SQUIC/libSQUIC, and follow its README instructions. The default and recommended location for libSQUIC is the home directory, i.e., ``~/``. - -#### Step 2: -Run the following command to install the library: -```angular2 -pip install SQUIC -``` -#### Step 3: -Load the SQUIC package: -```angular2 -import SQUIC -``` -For further details type ``help(SQUIC)`` in the Python command line. - -_Note: The number of threads used by SQUIC can be defined by setting the enviroment variable OMP_NUM_THREADS (e.g., ``base> export OMP_NUM_THREADS=12``). This may require a restart of the session)._ - -## Example - -To run a simple example : - -```angular2 -import SQUIC -import numpy as np - -# set location of libSQUIC (set after importing package) -SQUIC.PATH_TO_libSQUIC('/path/to/squic') - -# generate sample from tridiagonal precision matrix -p = 1024 -n = 100 -l = .4 - -# generate a tridiagonal matrix -a = -0.5 * np.ones(p-1) -b = 1.25 * np.ones(p) -iC_star = np.diag(a,-1) + np.diag(b,0) + np.diag(a,1) - -# generate the data -L = np.linalg.cholesky(iC_star) -Y = np.linalg.solve(L.T,np.random.randn(p,n)) - -[X,W,info_times,info_objective,info_logdetX,info_trSX] = SQUIC.run(Y,l) -``` - - diff --git a/src/SQUIC.egg-info/SOURCES.txt b/src/SQUIC.egg-info/SOURCES.txt deleted file mode 100644 index 8c1661dc789de9c82ba686b31ef4c539f293a1a2..0000000000000000000000000000000000000000 --- a/src/SQUIC.egg-info/SOURCES.txt +++ /dev/null @@ -1,12 +0,0 @@ -LICENSE -README.md -pyproject.toml -setup.cfg -setup.py -src/SQUIC/SQUIC_Python.py -src/SQUIC/__init__.py -src/SQUIC.egg-info/PKG-INFO -src/SQUIC.egg-info/SOURCES.txt -src/SQUIC.egg-info/dependency_links.txt -src/SQUIC.egg-info/requires.txt -src/SQUIC.egg-info/top_level.txt \ No newline at end of file diff --git a/src/SQUIC.egg-info/dependency_links.txt b/src/SQUIC.egg-info/dependency_links.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/src/SQUIC.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/SQUIC.egg-info/requires.txt b/src/SQUIC.egg-info/requires.txt deleted file mode 100644 index 6bad10388ecb1eefd890a797d833976a5e631541..0000000000000000000000000000000000000000 --- a/src/SQUIC.egg-info/requires.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy -scipy diff --git a/src/SQUIC.egg-info/top_level.txt b/src/SQUIC.egg-info/top_level.txt deleted file mode 100644 index 04285ab2cf0b803b28ef7ebb49de104b366363b2..0000000000000000000000000000000000000000 --- a/src/SQUIC.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -SQUIC diff --git a/src/SQUIC_Python.egg-info/PKG-INFO b/src/SQUIC_Python.egg-info/PKG-INFO deleted file mode 100644 index 505d03f938d6a44eed13f60670d624f2572b1080..0000000000000000000000000000000000000000 --- a/src/SQUIC_Python.egg-info/PKG-INFO +++ /dev/null @@ -1,17 +0,0 @@ -Metadata-Version: 2.1 -Name: SQUIC-Python -Version: 0.0.3 -Summary: Sparse Quadratic Inverse Covariance Estimation -Home-page: https://github.com/aefty/SQUIC_Python -Author: Aryan Eftekhari, Lisa Gaedke-Merzhaeuser, Dimosthenis Pasadakis, Matthias Bollhoefer, Simon Scheidegger, Olaf Schenk -Author-email: author@example.com -License: UNKNOWN -Platform: UNKNOWN -Classifier: Programming Language :: Python :: 3 -Classifier: License :: OSI Approved :: MIT License -Classifier: Operating System :: OS Independent -Requires-Python: >=3.6 -Description-Content-Type: text/markdown - -UNKNOWN - diff --git a/src/SQUIC_Python.egg-info/SOURCES.txt b/src/SQUIC_Python.egg-info/SOURCES.txt deleted file mode 100644 index 3c230daabeb09e0490b1e920ced3f8ed1ceb0aae..0000000000000000000000000000000000000000 --- a/src/SQUIC_Python.egg-info/SOURCES.txt +++ /dev/null @@ -1,12 +0,0 @@ -README.md -pyproject.toml -setup.cfg -setup.py -src/SQUIC_Python/SQUIC_Python.py -src/SQUIC_Python/__init__.py -src/SQUIC_Python.egg-info/PKG-INFO -src/SQUIC_Python.egg-info/SOURCES.txt -src/SQUIC_Python.egg-info/dependency_links.txt -src/SQUIC_Python.egg-info/top_level.txt -src/SQUIC_Python/test/__init__.py -src/SQUIC_Python/test/test_squic.py \ No newline at end of file diff --git a/src/SQUIC_Python.egg-info/dependency_links.txt b/src/SQUIC_Python.egg-info/dependency_links.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/src/SQUIC_Python.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/SQUIC_Python.egg-info/top_level.txt b/src/SQUIC_Python.egg-info/top_level.txt deleted file mode 100644 index 78cede1047c58bb0ecce71721bef94d0b7114c9c..0000000000000000000000000000000000000000 --- a/src/SQUIC_Python.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -SQUIC_Python diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/SQUIC/__init__.py b/src/squic/__init__.py similarity index 98% rename from src/SQUIC/__init__.py rename to src/squic/__init__.py index cfab8d7971bb30e5e98f5a9d8b131f2900d86223..31733ebcb5455f22a5540c3163c11ab52e760567 100644 --- a/src/SQUIC/__init__.py +++ b/src/squic/__init__.py @@ -88,6 +88,5 @@ Y = np.linalg.solve(L.T,np.random.randn(p,n)) [X,W,info_times,info_objective,info_logdetX,info_trSX] = SQUIC.run(Y,l) """ -from .SQUIC_Python import PATH_TO_libSQUIC -from .SQUIC_Python import run +from .squic import * diff --git a/src/SQUIC/SQUIC_Python.py b/src/squic/squic.py similarity index 93% rename from src/SQUIC/SQUIC_Python.py rename to src/squic/squic.py index d087eeb1b90d7d44306de6288059d5ee4c109464..4531e9036a74487f5a6b86bc0ce6ce3f324111aa 100644 --- a/src/SQUIC/SQUIC_Python.py +++ b/src/squic/squic.py @@ -1,4 +1,4 @@ -# SQUIC_Python.py +# SQUIC # # Copyright (C) Aryan Eftekhari # @@ -15,44 +15,28 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. - +import os from ctypes import * import numpy as np import sys from scipy.sparse import csr_matrix, identity -dll = None +lib_custom_location = os.environ.get("SQUIC_LIB_PATH", os.path.dirname(__file__)) -def PATH_TO_libSQUIC(libSQUIC_path): - """ -################# -# Description: -################# -Set the path of libSQUIC. Require only once after importing. -See help(SQUIC) for further details. - -################# -# Usage : -################# -Arguments: - libSQUIC_path: path to libSQUIC; e.g., /User/bob. - - """ - - global dll - - libSQUIC_loc = libSQUIC_path - if sys.platform.startswith('darwin'): - libSQUIC_loc=libSQUIC_loc+"/libSQUIC.dylib" - elif sys.platform.startswith('linux'): - libSQUIC_loc=libSQUIC_loc+"/libSQUIC.so" - else: - raise Exception("#SQUIC: OS not supported."); - - dll = CDLL(libSQUIC_loc) - - return True +squic_libs = { + "darwin" : "libSQUIC.dylib", + "linux" : "libSQUIC.so" +} +dll = None +try: + dll = CDLL(os.path.join(lib_custom_location, squic_libs[sys.platform])) +except KeyError: + raise Exception("#SQUIC: OS not supported.") +except OSError as e: + print(e) + print("Squic library not found, please use SQUIC_LIB_PATH env variable!!") + exit(1) def run(Y, l, max_iter=100, tol=1e-3,verbose=1, M=None, X0=None, W0=None): """ @@ -94,7 +78,8 @@ Return values: """ if(dll is None): - raise Exception("#SQUIC: libSQUIC not loaded, use SQUIC.PATH_TO_libSQUIC(libSQUIC_path)."); + print(f"Error loading the SQUIC library: {squic_libs[sys.platform]}") + exit(1) p,n= Y.shape