From c6b765076c7471213741ed93ee504f87c63633e4 Mon Sep 17 00:00:00 2001 From: eltrompetero Date: Thu, 27 Oct 2022 19:17:37 +0200 Subject: [PATCH 1/4] minor updates better sampler handling in Model added default __init__() method --- coniii/models.py | 43 ++++++++++++++++++++----------------------- coniii/solvers.py | 22 ---------------------- 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/coniii/models.py b/coniii/models.py index 8d4c122..3109061 100644 --- a/coniii/models.py +++ b/coniii/models.py @@ -2,28 +2,6 @@ # ConIII module for maxent models. # Authors: Edward Lee (edlee@alumni.princeton.edu) and Bryan Daniels # (bryan.daniels.1@asu.edu) -# -# MIT License -# -# Copyright (c) 2019 Edward D. Lee, Bryan C. Daniels -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. # ====================================================================================== # from importlib import import_module import multiprocess as mp @@ -37,7 +15,21 @@ class Model(): """Basic model class outline. """ - + def __init__(self, multipliers, rng=None, verbose=False): + """ + Parameters + ---------- + multipliers : list of ndarray or ndarray + Can be an integer (all parameters are set to zero), list of vectors [fields, + couplings], a vector of fields and couplings concatenated together, or a + matrix of parameters where the diagonal entries are the fields. + """ + + self.multipliers = multipliers + + self.rng = rng or np.random.RandomState() # this will get passed to sampler if it is set up + self.verbose = verbose + def setup_sampler(self, sample_method='metropolis', sample_size=1000, @@ -66,6 +58,11 @@ def setup_sampler(self, self.sampler = mcPotts3(self.n, self.multipliers, self.calc_e, rng=self.rng, **sampler_kwargs) + elif sample_method=='metropolis': + self.sampleMethod = sample_method + self.sampler = Metropolis(self.n, self.multipliers, self.calc_e, + rng=self.rng, + **sampler_kwargs) else: raise NotImplementedError("Unrecognized sampler %s."%sample_method) self.sample = None diff --git a/coniii/solvers.py b/coniii/solvers.py index 9d55bd7..dbd407f 100755 --- a/coniii/solvers.py +++ b/coniii/solvers.py @@ -1,28 +1,6 @@ # =============================================================================================== # # ConIII module for algorithms for solving the inverse Ising problem. # Authors: Edward Lee (edlee@alumni.princeton.edu) and Bryan Daniels (bryan.daniels.1@asu.edu) -# -# MIT License -# -# Copyright (c) 2020 Edward D. Lee, Bryan C. Daniels -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. # =============================================================================================== # from scipy.optimize import minimize, fmin_ncg, minimize_scalar, root import multiprocess as mp From 4cf7cb4674c7c4a60a3038053bdb8307ad433a76 Mon Sep 17 00:00:00 2001 From: eltrompetero Date: Thu, 27 Oct 2022 19:19:11 +0200 Subject: [PATCH 2/4] release notes --- RELEASE_NOTES | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 03eb38a..e330710 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,33 +1,11 @@ Log for major changes in releases -MIT License -Copyright (c) 2020 Edward D. Lee, Bryan C. Daniels - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - -v3.0.1 (2022/11) +v3.0.1 (To be released 2022/11) ---------------------------------------------------- - Bug fix in setup script. -v3.0.0 (To be released 2022/06) +v3.0.0 (Released 2022/06) ---------------------------------------------------- - Conditional (fixed spin) Metropolis sampling now in C++). - Standardized method names for generating samples and data member names for From be88b250495d26509cc6ec00fb9884706a84d79f Mon Sep 17 00:00:00 2001 From: eltrompetero Date: Thu, 27 Oct 2022 19:45:09 +0200 Subject: [PATCH 3/4] updated readme and tested usage guide --- README.md | 74 +++++++++++-------------------------------------------- 1 file changed, 15 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 285c5a9..c5ffca9 100755 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ # Convenient Interface to Inverse Ising ConIII is a Python package for solving maximum entropy problems with a focus on the -pairwise maximum entropy model, also known as the inverse Ising problem. Support for -Python 3.8.3 and higher. +pairwise maximum entropy model, also known as the inverse Ising problem. If you use ConIII for your research, please consider citing the following: > Lee, E.D. and Daniels, B.C., 2019. Convenient Interface to Inverse Ising (ConIII): A @@ -16,15 +15,14 @@ The paper also contains an overview of the modules. For code documentation, see ## Installation -This package is available on PyPI. It can be installed by first installing the needed -Boost C++ libraries and using pip. +To set up an Anaconda environment called "test" and install from pip, run the following code. The openblas package is only recommended for AMD users. ```bash -$ conda install -c conda-forge boost==1.74 +$ conda create -n test -c conda-forge python=3.10 numpy scipy numba cython jupyter ipython multiprocess boost==1.74 matplotlib mpmath blas=*=openblas $ pip install coniii ``` If you have trouble using `pip`, then you can always build this package from source. The following code will down download the latest release from GitHub and install -the package. Make sure that you are running Python 3.8.3 or higher and have boost v1.74.0 +the package. Make sure that you are running Python 3.10 and have boost v1.74.0 installed. ```bash $ git clone https://github.com/eltrompetero/coniii.git @@ -32,9 +30,6 @@ $ cd coniii $ ./pypi_compile.sh $ pip install dist/*.whl ``` -(Note: Using setuptools in the usual way of `python -setup.py install` will not work because eggs are incompatible with cached jit functions -generated using numba.) #### Setting up exact solution for systems *N > 9* If you would like to use the `Enumerate` solver for system sizes greater than 9 spins, you @@ -48,79 +43,40 @@ starting a Python terminal and running Once inside the install directory, you can run in your bash shell ```bash -$ python enumerate.py [N] +$ python enumerate.py [N] 1 ``` -where `[N]` should be replaced by the size of the system. This will write the equations -for the Ising model in the {0,1} basis. On the other hand, +where `[N]` should be replaced by the size of the system. This specifies that the system should be written for the {-1,1} basis. Note that the package uses the {-1,1} basis by default. For more details, see the `__main__` block at the end of the file enumerate.py. +For the {0,1} basis, use ```bash -$ python enumerate.py [N] 1 +$ python enumerate.py [N] ``` -specifies that the system should be written for the {-1,1} basis. Note that the package -uses the {-1,1} basis by default. For more details, see the `__main__` block at the end of -the file enumerate.py. - -## Quick guide (with Jupyter notebook) +## Quick guide with Jupyter notebook A [Jupyter notebook](https://github.com/eltrompetero/coniii/blob/py3/ipynb/usage_guide.ipynb) with a -brief introduction and examples for how to use ConIII is available. An HTML version is -[here](https://github.com/eltrompetero/coniii/blob/py3/ipynb/usage_guide.html). The -notebook is installed into your package directory if you used pip. +brief introduction and examples for how to use ConIII is available. The +notebook is also installed into your package directory if you used pip. -To use the notebook, install jupyter. -```bash -$ pip install jupyter -``` -or if you are using the Conda package manager -```bash -$ conda install jupyter -``` - -Then, first copy the notebook file "usage_guide.ipynb" into a directory outside the -"coniii" directory. Change to this directory and run +To use the notebook, install jupyter such as by following the setup instructions above. Then, copy the notebook file "usage_guide.ipynb" into a directory outside the "coniii" directory. Change to this directory and run ```bash $ jupyter notebook ``` This should open the notebook in your default web browser. -## Quick guide (console) - -First, install iPython for a console-based interpreter and start it. -```bash -$ pip install ipython -``` -or if you are using the Conda package manager -```bash -$ conda install ipython -``` - -Then, first copy the notebook file -["usage_guide.py"](https://github.com/eltrompetero/coniii/blob/py3/ipynb/usage_guide.py) -into a directory outside the "coniii" directory. Change to this directory and run -```bash -$ ipython -``` - -Once inside the iPython interpreter, run -```python ->>> %run usage_guide.py -``` -This will run all the examples sequentially, so you may want to comment out unwanted lines. - ## Troubleshooting This package is only maintained for Python 3 and has only been tested for Python -3.8.3. Check which version of Python you are running in your terminal with +3.10. Check which version of Python you are running in your terminal with ```bash $ python --version ``` ConIII has been tested on the following systems -* Ubuntu 20.04.1 +* Ubuntu 20.04.5 Trouble compiling the Boost extension manually? Check if your Boost library is included in your path. If it is not, then you can add an include directory entry @@ -146,7 +102,7 @@ The package directory can be found by running inside python You may also need to install pytest. ```bash -$ pip install pytest +$ conda install -c conda-forge pytest ``` ### Updating From 85764f8278153506f7f6c70280d5d1d56d3b1023 Mon Sep 17 00:00:00 2001 From: eltrompetero Date: Thu, 27 Oct 2022 19:53:46 +0200 Subject: [PATCH 4/4] updated release notes --- RELEASE_NOTES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index e330710..158ab2b 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,7 +1,7 @@ Log for major changes in releases -v3.0.1 (To be released 2022/11) +v3.0.1 (Released 2022/10) ---------------------------------------------------- - Bug fix in setup script.