From 22ca289b43641eafbe3e6be480857bb9e5400f01 Mon Sep 17 00:00:00 2001 From: h-aze Date: Sat, 2 Dec 2023 13:16:13 +0000 Subject: [PATCH] Changed slog to saver (histroically made sense but not with current design) --- .github/workflows/docs.yml | 2 +- CONTRIBUTING.md | 9 +++++++ README.md | 23 +++++++++--------- .../regularized_linear_regression.ipynb | 20 +++++++-------- slune.jpeg | Bin 0 -> 7446 bytes src/__init__.py | 1 + src/slune/__init__.py | 4 +-- src/slune/slune.py | 2 +- tests/test_slune.py | 4 +-- 9 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 slune.jpeg diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 513cabe..1998cdf 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,7 +28,7 @@ jobs: - run: pip install pdoc # ADJUST THIS: build your documentation into docs/. # We use a custom build script for pdoc itself, ideally you just run `pdoc -o docs/ ...` here. - - run: pdoc --docformat google -o docs/.html src + - run: pdoc --docformat google --logo "https://github.com/h-0-0/slune/slune.jpeg" -o docs/.html src - uses: actions/upload-pages-artifact@v2 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..a9d86e6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# Contributing +If you would like to contribute to slune please first familiarize yourself with the package by taking a look at the docs. In particular please read about the class design, the base classes and take a look at the code for the helper functions in the slune module. + +To contribute to the package please either submit a pull request for an open issue or open a new issue. If you are unsure about whether to open a new issue or in general have any problems please open a discussion in the discussions tab. + +Checklist for contributing: +- [ ] Make sure that your code is well documented and that the documentation is clear and concise, use google style docstrings. +- [ ] Make sure that your code is well tested and that the tests are clear and concise, want to keep coverage as high as possible! (minimum 90%) and keep tests as simple as possible! +- [ ] Make sure that you only solve the issue that you are attempting to close, if you find other issues please open a new issue for them. diff --git a/README.md b/README.md index c83f99f..64b7545 100644 --- a/README.md +++ b/README.md @@ -73,16 +73,16 @@ if __name__ == "__main__": test_y = [7, 8, 9] test_predictions = linear_regression_regularized(X, y, test_X, alpha) - # First let's load in a function that we can use to get a saver object that uses the default method of logging (we call this object a slog = saver + logger). The saving will be coordinated by a csv saver object which saves and reads results from csv files stored in a hierarchy of directories. - from slune import get_csv_slog - csv_slog = get_csv_slog(params = args) + # First let's load in a function that we can use to get a saver object that uses the default method of logging. The saving will be coordinated by a csv saver object which saves and reads results from csv files stored in a hierarchy of directories. + from slune import get_csv_saver + csv_saver = get_csv_saver(params = args) # Let's now calculate the mean squared error of our predictions and log it! mse = mean((test_y[i] - test_predictions[i])**2 for i in range(len(test_y))) - csv_slog.log({'mse': mse}) + csv_saver.log({'mse': mse}) # Let's now save our logged results! - slog.save_collated() + csv_saver.save_collated() ``` Now let's write some code that will submit some jobs to train our model using different hyperparameters!! ```python @@ -92,29 +92,28 @@ from slune.searchers import SearcherGrid grid_searcher = SearcherGrid({'alpha' : [0.25, 0.5, 0.75]}, runs = 1) # Let's now import a function which will submit a job for our model, the script_path specifies the path to the script that contains the model we want to train. The template_path specifies the path to the template script that we want to specify the job with, cargs is a list of constant arguments we want to pass to the script for each tuning. -# We set slog to None as we don't want to not run jobs if we have already run them before. +# We set saver to None as we don't want to not run jobs if we have already run them before. from slune import sbatchit script_path = 'model.py' template_path = 'template.sh' -sbatchit(script_path, template_path, grid_searcher, cargs=[], slog=None) +sbatchit(script_path, template_path, grid_searcher, cargs=[], saver=None) ``` Now we've submitted our jobs we will wait for them to finish 🕛🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛, now that they are finished we can read the results! ```python -from slune import get_csv_slog -csv_slog = get_csv_slog(params = None) -params, value = csv_slog.read(params = [], metric_name = 'mse', select_by ='min') +from slune import get_csv_saver +csv_saver = get_csv_saver(params = None) +params, value = csv_saver.read(params = [], metric_name = 'mse', select_by ='min') print(f'Best hyperparameters: {params}') print(f'Their MSE: {value}') ``` Amazing! 🥳 We have successfully used slune to train our model. I hope this gives you a good flavour of how you can use slune and how easy it is to use! -Please check out the examples folder for notebooks detailing in more depth some potential ways you can use slune. The docs are not yet up and running 😢 but they are coming soon! +Please check out the examples folder for notebooks detailing in more depth some potential ways you can use slune and of course please check out the docs! ## Roadmap - Make package user friendly: - Go through automation settings. - Code of conduct. - - Contributing guidelines. - Add to pypi. Still in early stages! First thing on the horizon is better integration with SLURM: - Set-up notifications for job completion, failure, etc. diff --git a/examples/From_README/regularized_linear_regression.ipynb b/examples/From_README/regularized_linear_regression.ipynb index 393158a..3cf26d7 100644 --- a/examples/From_README/regularized_linear_regression.ipynb +++ b/examples/From_README/regularized_linear_regression.ipynb @@ -67,16 +67,16 @@ " test_y = [7, 8, 9]\n", " test_predictions = linear_regression_regularized(X, y, test_X, alpha)\n", "\n", - " # First let's load in a function that we can use to get a saver object that uses the default method of logging (we call this object a slog = saver + logger). The saving will be coordinated by a csv saver object which saves and reads results from csv files stored in a hierarchy of directories.\n", - " from slune import get_csv_slog\n", - " csv_slog = get_csv_slog(params = args)\n", + " # First let's load in a function that we can use to get a saver object that uses the default method of logging. The saving will be coordinated by a csv saver object which saves and reads results from csv files stored in a hierarchy of directories.\n", + " from slune import get_csv_saver\n", + " csv_saver = get_csv_saver(params = args)\n", "\n", " # Let's now calculate the mean squared error of our predictions and log it!\n", " mse = mean((test_y[i] - test_predictions[i])**2 for i in range(len(test_y)))\n", - " csv_slog.log({'mse': mse})\n", + " csv_saver.log({'mse': mse})\n", "\n", " # Let's now save our logged results!\n", - " slog.save_collated()" + " csv_saver.save_collated()" ] }, { @@ -100,11 +100,11 @@ "grid_searcher = SearcherGrid({'alpha' : [0.25, 0.5, 0.75]}, runs = 1)\n", "\n", "# Let's now import a function which will submit a job for our model, the script_path specifies the path to the script that contains the model we want to train. The template_path specifies the path to the template script that we want to specify the job with, cargs is a list of constant arguments we want to pass to the script for each tuning. \n", - "# We set slog to None as we don't want to not run jobs if we have already run them before.\n", + "# We set saver to None as we don't want to not run jobs if we have already run them before.\n", "from slune import sbatchit\n", "script_path = 'model.py'\n", "template_path = 'template.sh'\n", - "sbatchit(script_path, template_path, grid_searcher, cargs=[], slog=None)" + "sbatchit(script_path, template_path, grid_searcher, cargs=[], saver=None)" ] }, { @@ -120,9 +120,9 @@ "metadata": {}, "outputs": [], "source": [ - "from slune import get_csv_slog\n", - "csv_slog = get_csv_slog(params = None)\n", - "params, value = csv_slog.read(params = [], metric_name = 'mse', select_by ='min')\n", + "from slune import get_csv_saver\n", + "csv_saver = get_csv_saver(params = None)\n", + "params, value = csv_saver.read(params = [], metric_name = 'mse', select_by ='min')\n", "print(f'Best hyperparameters: {params}')\n", "print(f'Their MSE: {value}')" ] diff --git a/slune.jpeg b/slune.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..4691219a00ce2e7b441ad92049fbd2afb9199742 GIT binary patch literal 7446 zcmbVw3pkY9*Z3ZTajC{N%4HOlPzaIRkPs>)msF;r+!CQ&Vnzz#XsA%msgV?NB)NuT z$gR^&?sqdoD&m+ajaPH~w$3@f^L^j*{r}JJ`_{~Q-}UUh_ImePd+oK>-hv?k9Y{Ia zIoJUd3V^-v2LudYWg8uM8i4)#fffKj44_g1fiR>X3s?^k0HJ)Lzgti``RKoCki60< zm={UD|KRDK#JgQvnX3F5crkljSVq>!eA zjSa!&ptGIBKHDFY5>h-77ItQ3aLC!n@Pqcd)w~XSt6@IC*{sY5!U^AqFl!f=eJk|e z?-lwVU=RGs+q-Q=)*SEtHIpR!){v^-oMT56b^qb}A1MjHQxU$fhYL~9H!M678bSxs zE>V$TD|8&B<-*~lAf35F`~OK7uFxm{r0ah096D$Nd0s=il(bhoppDEZ#js{U=Iic5g-hl0VhBVPy;T&;QzsI_=DdDghK8Z5Dv%r zg8&c-$5_Lb6$z&x?EuaKU$7nMKzawzgScbG&TuRQcK=`Y)A^_EG7SI=sz4xU_@~X0 z3P6Q1020ssY11?TKw1)j7tg{@grE2!4h^3|r=f>^DFR^iVE|;`!7)c7P8;m_(T`fS z8vv0Bf#BcOL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NgXMTAdic=_r9j`0RV_H34n5pDq%xzo1tUvuY;I9_~sB(0#fYE#o`Rg`oc^R4;AC6?#kKPpql zF8d1;h=;L$wwn_ylXJZ284t1(AN_Pa7Daf~HGi9Pk@$|lbi-bYE$7O@fNwwyi5y+a z(QR{1llB|>#4eo6>2=PIzCM#|?PvLFZ19)Ql=UQf0iH<+e%6TL=#9*h0QJIC^SYi< z7MMNCSW@+;zb<{aIncP!Of4HNMfejwo4Sem-of=^isiFy73+?kYbQQ}$zdfy{4WqE z7=#Y;Wq~hI0jD$5OQplCTG^hPP^A)ym~~o8^@lXtGjP&{7is(Z=AB=(+ix~jHYNLx zP+hgs1fVo@3Ez=`&yAOTj$=kBT>B=9_z+Fv)Vtg3mz_(!KjmJZFui8HeDKKC%RD`8 z8s49bz^fI;O^Vz$QXmf5x`kX#9`T&CsKi|2?zs?@@k>J>Ob%tLK0?lT3cc69YokVXj?h)U};?EGZ M5~lu-ND>VH2V9qMvH$=8 literal 0 HcmV?d00001 diff --git a/src/__init__.py b/src/__init__.py index 08bfb69..8b96745 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,4 +1,5 @@ """ .. include:: ../README.md .. include:: ../CLASSDESIGN.md +.. include:: ../CONTRIBUTING.md """ \ No newline at end of file diff --git a/src/slune/__init__.py b/src/slune/__init__.py index 36709c2..2f02e78 100644 --- a/src/slune/__init__.py +++ b/src/slune/__init__.py @@ -4,10 +4,10 @@ from .searchers import * from .savers import * from .loggers import * -from .slune import submit_job, sbatchit, lsargs, garg, get_csv_slog +from .slune import submit_job, sbatchit, lsargs, garg, get_csv_saver from . import base, utils -# __all__ = ['submit_job', 'sbatchit', 'lsargs', 'garg', 'get_csv_slog', +# __all__ = ['submit_job', 'sbatchit', 'lsargs', 'garg', 'get_csv_saver', # 'base', 'utils', 'default', 'grid', 'csv'] import importlib.metadata diff --git a/src/slune/slune.py b/src/slune/slune.py index c3ef5f1..ab4fc9d 100644 --- a/src/slune/slune.py +++ b/src/slune/slune.py @@ -91,7 +91,7 @@ def single_garg(arg_name): else: return single_garg(arg_names) -def get_csv_slog(params: Optional[dict]= None, root_dir: Optional[str]='slune_results') -> BaseSaver: +def get_csv_saver(params: Optional[dict]= None, root_dir: Optional[str]='slune_results') -> BaseSaver: """ Returns a SaverCsv object with the given parameters and root directory. Args: diff --git a/tests/test_slune.py b/tests/test_slune.py index ae5428e..4729d01 100644 --- a/tests/test_slune.py +++ b/tests/test_slune.py @@ -25,10 +25,10 @@ def test_sbatchit(self, mock_run): searcher = MagicMock() searcher.__iter__.return_value = [['arg1', 'arg2'], ['arg3', 'arg4']] cargs = ["carg1", "carg2"] - slog = None + saver = None # Act - sbatchit(script_path, template_path, searcher, cargs, slog) + sbatchit(script_path, template_path, searcher, cargs, saver) # Assert calls = [call(['sbatch', template_path, script_path, 'carg1', 'carg2', 'arg1', 'arg2'], check=True),