Skip to content

Commit

Permalink
merging and fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewghgriffiths committed May 17, 2023
2 parents eb9a7c8 + dd0a2ec commit 9960057
Show file tree
Hide file tree
Showing 295 changed files with 6,478 additions and 6,847 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run unittests
name: Tests

on: [push]

Expand Down Expand Up @@ -47,6 +47,7 @@ jobs:
echo "Branch $BRANCH did not exist in $PACKAGE"
else
echo "Branch $BRANCH did exist in $PACKAGE"
git fetch
git checkout $BRANCH
fi
popd
Expand All @@ -57,7 +58,7 @@ jobs:
pip3 install --upgrade pip
pip3 install setuptools
pip3 install wheel
pip3 install pytest
pip3 install pytest coverage pytest-cov
pip3 install -r PyAutoConf/requirements.txt
pip3 install -r PyAutoFit/requirements.txt
pip3 install -r PyAutoFit/build_requirements.txt
Expand All @@ -67,7 +68,9 @@ jobs:
export PYTHONPATH=$PYTHONPATH:$ROOT_DIR/PyAutoConf
export PYTHONPATH=$PYTHONPATH:$ROOT_DIR/PyAutoFit
pushd PyAutoFit
pytest
pytest --cov autofit --cov-report xml:coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
- name: Slack send
if: ${{ failure() }}
id: slack
Expand Down
13 changes: 13 additions & 0 deletions CITATIONS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _references:

Citations & References
======================

The bibtex entries for **PyAutoFit** and its affiliated software packages can be found
`here <https://github.com/rhayes777/PyAutoFit/blob/main/files/citations.bib>`_, with example text for citing **PyAutoFit**
in `.tex format here <https://github.com/rhayes777/PyAutoFit/blob/main/files/citation.tex>`_ format here and
`.md format here <https://github.com/rhayes777/PyAutoFit/blob/main/files/citations.md>`_. As shown in the examples, we
would greatly appreciate it if you mention **PyAutoFit** by name and include a link to our GitHub page!

**PyAutoFit** is published in the `Journal of Open Source Software <https://joss.theoj.org/papers/10.21105/joss.02550#>`_ and its
entry in the above .bib file is under the key ``pyautofit``.
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ the situation is not yet resolved.

## License

This code of conduct has been adapted from [*NUMFOCUS code of conduct*](https://github.com/numfocus/numfocus/blob/master/manual/numfocus-coc.md#the-short-version),
which is adapted from numerous sources, including the [*Geek Feminism wiki, created by the Ada Initiative and other volunteers, which is under a Creative Commons Zero license*](http://geekfeminism.wikia.com/wiki/Fiterence_anti-harassment/Policy), the [*Contributor Covenant version 1.2.0*](http://contributor-covenant.org/version/1/2/0/), the [*Bokeh Code of Conduct*](https://github.com/bokeh/bokeh/blob/master/CODE_OF_CONDUCT.md), the [*SciPy Code of Conduct*](https://github.com/jupyter/governance/blob/master/conduct/enforcement.md), the [*Carpentries Code of Conduct*](https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html#enforcement-manual), and the [*NeurIPS Code of Conduct*](https://neurips.cc/public/CodeOfConduct).
This code of conduct has been adapted from [*NUMFOCUS code of conduct*](https://github.com/numfocus/numfocus/blob/main/manual/numfocus-coc.md#the-short-version),
which is adapted from numerous sources, including the [*Geek Feminism wiki, created by the Ada Initiative and other volunteers, which is under a Creative Commons Zero license*](http://geekfeminism.wikia.com/wiki/Fiterence_anti-harassment/Policy), the [*Contributor Covenant version 1.2.0*](http://contributor-covenant.org/version/1/2/0/), the [*Bokeh Code of Conduct*](https://github.com/bokeh/bokeh/blob/main/CODE_OF_CONDUCT.md), the [*SciPy Code of Conduct*](https://github.com/jupyter/governance/blob/main/conduct/enforcement.md), the [*Carpentries Code of Conduct*](https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html#enforcement-manual), and the [*NeurIPS Code of Conduct*](https://neurips.cc/public/CodeOfConduct).

**PyAutoFit Code of Conduct is licensed under the [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/).**
17 changes: 10 additions & 7 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# MANIFEST.in
exclude .gitignore
exclude .coverage
exclude .travis.yml
exclude docs
include README.rst
include setup.cfg
recursive-include autofit/config *
include CITATIONS.rst
include LICENSE
include requirements.txt
include optional_requirements.txt

prune .cache
prune .git
prune build
prune dist

recursive-exclude *.egg-info *
recursive-include tests *
include requirements.txt
recursive-include data *

recursive-include autofit/config *

exclude docs

global-exclude test_autofit
recursive-exclude test_autofit *
17 changes: 15 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ PyAutoFit: Classy Probabilistic Programming
.. |binder| image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/Jammy2211/autofit_workspace/HEAD

.. |RTD| image:: https://readthedocs.org/projects/pyautofit/badge/?version=latest
:target: https://pyautofit.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. |Tests| image:: https://github.com/rhayes777/PyAutoFit/actions/workflows/main.yml/badge.svg
:target: https://github.com/rhayes777/PyAutoFit/actions

.. |Build| image:: https://github.com/rhayes777/PyAutoBuild/actions/workflows/release.yml/badge.svg
:target: https://github.com/rhayes777/PyAutoBuild/actions

.. |JOSS| image:: https://joss.theoj.org/papers/10.21105/joss.02550/status.svg
:target: https://doi.org/10.21105/joss.02550

|binder| |JOSS|
|binder| |Tests| |Build| |RTD| |JOSS|

`Installation Guide <https://pyautofit.readthedocs.io/en/latest/installation/overview.html>`_ |
`readthedocs <https://pyautofit.readthedocs.io/en/latest/index.html>`_ |
`Introduction on Binder <https://mybinder.org/v2/gh/Jammy2211/autofit_workspace/release?filepath=introduction.ipynb>`_ |
`HowToFit <https://pyautofit.readthedocs.io/en/latest/howtofit/howtofit.html>`_


..
_ One day make these BOLD with a colon like my fellowsahip proposa,s where the first is Model Composition & Fitting: Tools for composing a complex model and fitting it with dynesty...
PyAutoFit is a Python based probabilistic programming language for the fully Bayesian analysis of extremely large
datasets which:

Expand Down Expand Up @@ -59,7 +73,6 @@ noisy 1D data. Here's the ``data`` (black) and the model (red) we'll fit:

.. image:: https://raw.githubusercontent.com/rhayes777/PyAutoFit/master/files/toy_model_fit.png
:width: 400
:alt: Alternative text

We define our model, a 1D Gaussian by writing a Python class using the format below:

Expand Down
11 changes: 6 additions & 5 deletions autofit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
from .mapper.prior_model.attribute_pair import InstanceNameValue
from .mapper.prior_model.attribute_pair import PriorNameValue
from .mapper.prior_model.attribute_pair import cast_collection
from .mapper.prior_model.collection import CollectionPriorModel
from .mapper.prior_model.collection import CollectionPriorModel as Collection
from .mapper.prior_model.prior_model import PriorModel
from .mapper.prior_model.prior_model import PriorModel as Model
from .mapper.prior_model.collection import Collection
from .mapper.prior_model.prior_model import Model
from .mapper.prior_model.prior_model import Model
from .mapper.prior_model.util import PriorModelNameValue
from .non_linear.abstract_search import NonLinearSearch
from .non_linear.abstract_search import PriorPasser
from .non_linear.analysis.analysis import Analysis
from .non_linear.analysis.combined import CombinedAnalysis
from .non_linear.grid.grid_search import GridSearchResult
from .non_linear.initializer import InitializerBall
from .non_linear.initializer import InitializerPrior
Expand All @@ -86,6 +86,7 @@
from .example.model import Gaussian
from .text import formatter
from .text import samples_text
from .interpolator import LinearInterpolator, SplineInterpolator
from .tools import util


Expand All @@ -109,4 +110,4 @@ def save_abc(pickler, obj):

conf.instance.register(__file__)

__version__ = "2022.11.26.11"
__version__ = "2023.3.27.1"
75 changes: 32 additions & 43 deletions autofit/aggregator/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ def filter(self, *predicates) -> "AggregatorGroup":
-------
A collection of groups of the same length with each group having the same or fewer members.
"""
return AggregatorGroup(
[
group.filter(*predicates)
for group in self.groups
]
)
return AggregatorGroup([group.filter(*predicates) for group in self.groups])

def __getitem__(self, item):
return self.groups[item]
Expand All @@ -75,10 +70,7 @@ def values(self, name: str) -> List[List]:
-------
A list of lists of values.
"""
return [
group.values(name)
for group in self.groups
]
return [group.values(name) for group in self.groups]


class AbstractAggregator:
Expand All @@ -98,23 +90,15 @@ def remove_unzipped(self):
Removes the unzipped output directory for each phase.
"""
for phase in self.search_outputs:

split_path = path.split(phase.directory)[0]

unzipped_path = path.join(split_path)

rmtree(
unzipped_path,
ignore_errors=True
)
rmtree(unzipped_path, ignore_errors=True)

def __getitem__(
self,
item: Union[slice, int]
) -> Union[
"AbstractAggregator",
SearchOutput
]:
self, item: Union[slice, int]
) -> Union["AbstractAggregator", SearchOutput]:
"""
If an index is passed in then a specific phase output is returned.
Expand All @@ -130,9 +114,7 @@ def __getitem__(
An aggregator or phase
"""
if isinstance(item, slice):
return AbstractAggregator(
self.search_outputs[item]
)
return AbstractAggregator(self.search_outputs[item])
return self.search_outputs[item]

def __len__(self):
Expand Down Expand Up @@ -184,12 +166,26 @@ def values(self, name: str) -> Iterator:
-------
A generator of values for the attribute
"""
return map(
lambda phase: getattr(
phase, name
),
self.search_outputs
)
return map(lambda phase: getattr(phase, name), self.search_outputs)

def child_values(self, name: str) -> Iterator[List]:
"""
Get values with a given name from the child analyses of each search in
this aggregator.
Parameters
----------
name
The name of an attribute expected to be associated with
child analysis output. If a pickle file with this name
is in the child analysis output directory then that pickle
will be loaded.
Returns
-------
A generator of values for the attribute
"""
return (phase.child_values(name) for phase in self.search_outputs)

def map(self, func):
"""
Expand All @@ -204,10 +200,7 @@ def map(self, func):
-------
A generator of results
"""
return map(
func,
self.search_outputs
)
return map(func, self.search_outputs)

def group_by(self, field: str) -> AggregatorGroup:
"""
Expand Down Expand Up @@ -241,11 +234,7 @@ def model_results(self) -> str:


class Aggregator(AbstractAggregator):
def __init__(
self,
directory: Union[str, os.PathLike],
completed_only=False
):
def __init__(self, directory: Union[str, os.PathLike], completed_only=False):
"""
Class to aggregate phase results for all subdirectories in a given directory.
Expand Down Expand Up @@ -276,9 +265,7 @@ def __init__(
f.extractall(path.join(root, filename[:-4]))
except zipfile.BadZipFile:
raise zipfile.BadZipFile(
f"File is not a zip file: \n "
f"{root} \n"
f"{filename}"
f"File is not a zip file: \n " f"{root} \n" f"{filename}"
)

for root, _, filenames in os.walk(directory):
Expand All @@ -289,5 +276,7 @@ def __init__(
if len(search_outputs) == 0:
print(f"\nNo search_outputs found in {directory}\n")
else:
print(f"\n A total of {str(len(search_outputs))} search_outputs and results were found.")
print(
f"\n A total of {str(len(search_outputs))} search_outputs and results were found."
)
super().__init__(search_outputs)
Loading

0 comments on commit 9960057

Please sign in to comment.