From 1d7355762e5133409351ffeda9d231df1c70f63b Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Fri, 8 Nov 2024 12:33:33 -0500 Subject: [PATCH 1/6] docs: fix typo, add gitignore, remove obsolet MANIFEST.in --- .pre-commit-config.yaml | 7 +- MANIFEST.in | 13 ---- docs/.gitignore | 2 + docs/api/static/zfit_physics.compwa.rst | 2 +- docs/api/static/zfit_physics.roofit.rst | 42 +++++++++--- docs/api/static/zfit_physics.tfpwa.rst | 4 +- docs/api/zfit_physics.models.pdf_argus.rst | 7 -- docs/api/zfit_physics.models.pdf_cmsshape.rst | 7 -- docs/api/zfit_physics.models.pdf_conv.rst | 7 -- docs/api/zfit_physics.models.pdf_cruijff.rst | 7 -- docs/api/zfit_physics.models.pdf_erfexp.rst | 7 -- docs/api/zfit_physics.models.pdf_example.rst | 7 -- docs/api/zfit_physics.models.pdf_kde.rst | 7 -- .../zfit_physics.models.pdf_novosibirsk.rst | 7 -- docs/api/zfit_physics.models.pdf_relbw.rst | 7 -- docs/api/zfit_physics.models.pdf_tsallis.rst | 7 -- docs/api/zfit_physics.models.rst | 24 ------- docs/api/zfit_physics.pdf.rst | 7 -- docs/api/zfit_physics.rst | 24 ------- docs/api/zfit_physics.unstable.pdf.rst | 7 -- docs/api/zfit_physics.unstable.rst | 15 ----- docs/conf.py | 5 ++ docs/make_docs.sh | 5 +- tests/roofit/test_loss_compat.py | 67 ------------------- 24 files changed, 47 insertions(+), 247 deletions(-) delete mode 100644 MANIFEST.in create mode 100755 docs/.gitignore delete mode 100644 docs/api/zfit_physics.models.pdf_argus.rst delete mode 100644 docs/api/zfit_physics.models.pdf_cmsshape.rst delete mode 100644 docs/api/zfit_physics.models.pdf_conv.rst delete mode 100644 docs/api/zfit_physics.models.pdf_cruijff.rst delete mode 100644 docs/api/zfit_physics.models.pdf_erfexp.rst delete mode 100644 docs/api/zfit_physics.models.pdf_example.rst delete mode 100644 docs/api/zfit_physics.models.pdf_kde.rst delete mode 100644 docs/api/zfit_physics.models.pdf_novosibirsk.rst delete mode 100644 docs/api/zfit_physics.models.pdf_relbw.rst delete mode 100644 docs/api/zfit_physics.models.pdf_tsallis.rst delete mode 100644 docs/api/zfit_physics.models.rst delete mode 100644 docs/api/zfit_physics.pdf.rst delete mode 100644 docs/api/zfit_physics.rst delete mode 100644 docs/api/zfit_physics.unstable.pdf.rst delete mode 100644 docs/api/zfit_physics.unstable.rst delete mode 100644 tests/roofit/test_loss_compat.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 84ac776..d01b4d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,12 +68,7 @@ repos: - pyupgrade args: - --py39-plus - - repo: https://github.com/mgedmin/check-manifest - rev: '0.50' - hooks: - - id: check-manifest - args: [--no-build-isolation] - additional_dependencies: ['hatch-vcs', 'hatchling>=1.17.1'] + - repo: https://github.com/sondrelg/pep585-upgrade rev: v1.0 hooks: diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 9e2f41f..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,13 +0,0 @@ -include AUTHORS.rst -include CONTRIBUTING.rst -include HISTORY.rst -include LICENSE -include README.rst -include requirements.txt -include requirements_dev.txt - -recursive-include tests * -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] - -recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100755 index 0000000..3e7e2c9 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +/_build/ +/api/*.rst diff --git a/docs/api/static/zfit_physics.compwa.rst b/docs/api/static/zfit_physics.compwa.rst index 78dba30..15c7a4e 100644 --- a/docs/api/static/zfit_physics.compwa.rst +++ b/docs/api/static/zfit_physics.compwa.rst @@ -9,7 +9,7 @@ Import the module with: import zfit_physics.compwa as zcompwa -This will enable that :py:function:`~ tensorwaves.estimator.Estimator`, can be used as a loss function in zfit minimizers as +This will enable that a :py:class:`~ tensorwaves.estimator.Estimator`, for example ``estimator`` in the following, can be used as a loss function in zfit minimizers as .. code-block:: python diff --git a/docs/api/static/zfit_physics.roofit.rst b/docs/api/static/zfit_physics.roofit.rst index e6a0a77..45c036b 100644 --- a/docs/api/static/zfit_physics.roofit.rst +++ b/docs/api/static/zfit_physics.roofit.rst @@ -11,26 +11,52 @@ For example via conda: $ mamba install -c conda-forge root +.. jupyter-execute:: + :hide-code: + :hide-output: + + import numpy as np + from ROOT import RooArgSet, RooDataSet, RooGaussian, RooRealVar + + data = np.random.normal(loc=2.0, scale=3.0, size=1000) + + mur = RooRealVar("mu", "mu", 1.2, -4, 6) + sigmar = RooRealVar("sigma", "sigma", 1.3, 0.5, 10) + obsr = RooRealVar("x", "x", -2, 3) + RooFit_gauss = RooGaussian("gauss", "gauss", obsr, mur, sigmar) + + RooFit_data = RooDataSet("data", "data", {obsr}) + for d in data: + obsr.setVal(d) + RooFit_data.add(RooArgSet(obsr)) + + minimizer = zfit.minimize.Minuit() + Import the module with: -.. code-block:: python - import zfit_physics.roofit as ztfroofit -this will enable the RooFit functionality in zfit. +.. jupyter-execute:: -We can create a RooFit NLL as ``RooFit_nll`` and use it as a loss function in zfit. For example, with a Gaussian model ``RooFit_gauss`` and a dataset ``RooFit_data``, both created with RooFit: + import zfit_physics.roofit as zroofit + +this will enable the RooFit functionality in zfit and allow to automatically minimize the function using a zfit minimimzer as -.. code-block:: python +.. jupyter-execute:: RooFit_nll = RooFit_gauss.createNLL(RooFit_data) - minimizer.minimize(loss=RooFit_nll) + +We can create a RooFit NLL as ``RooFit_nll`` and use it as a loss function in zfit. For example, with a Gaussian model ``RooFit_gauss`` and a dataset ``RooFit_data``, both created with RooFit: + +.. jupyter-execute:: + + result = minimizer.minimize(loss=RooFit_nll) More explicitly, the loss function can be created with -.. code-block:: python +.. jupyter-execute:: - nll = zroofit.loss.nll_from_roofit(fcn) + nll = zroofit.loss.nll_from_roofit(RooFit_nll) Variables diff --git a/docs/api/static/zfit_physics.tfpwa.rst b/docs/api/static/zfit_physics.tfpwa.rst index 3c50bfb..a23d470 100644 --- a/docs/api/static/zfit_physics.tfpwa.rst +++ b/docs/api/static/zfit_physics.tfpwa.rst @@ -1,7 +1,7 @@ TF-PWA ======================= -TFPWA is a generic software package intended for Partial Wave Analysis (PWA). It can be connected with zfit, +TF-PWA is a generic software package intended for Partial Wave Analysis (PWA). It can be connected with zfit, currently by providing a loss function that can be minimized by a zfit minimizer. Import the module with: @@ -10,7 +10,7 @@ Import the module with: import zfit_physics.tfpwa as ztfpwa -This will enable that :py:function:`~tfpwa.model.FCN` can be used as a loss function in zfit minimizers as +This will enable that :py:class:`~tf_pwa.model.FCN` can be used as a loss function in zfit minimizers as .. code-block:: python diff --git a/docs/api/zfit_physics.models.pdf_argus.rst b/docs/api/zfit_physics.models.pdf_argus.rst deleted file mode 100644 index c9523dc..0000000 --- a/docs/api/zfit_physics.models.pdf_argus.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_argus -========== - -.. automodule:: zfit_physics.models.pdf_argus - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_cmsshape.rst b/docs/api/zfit_physics.models.pdf_cmsshape.rst deleted file mode 100644 index 7aeb83d..0000000 --- a/docs/api/zfit_physics.models.pdf_cmsshape.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_cmsshape -============= - -.. automodule:: zfit_physics.models.pdf_cmsshape - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_conv.rst b/docs/api/zfit_physics.models.pdf_conv.rst deleted file mode 100644 index be55ef7..0000000 --- a/docs/api/zfit_physics.models.pdf_conv.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_conv -========= - -.. automodule:: zfit_physics.models.pdf_conv - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_cruijff.rst b/docs/api/zfit_physics.models.pdf_cruijff.rst deleted file mode 100644 index 713107e..0000000 --- a/docs/api/zfit_physics.models.pdf_cruijff.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_cruijff -============ - -.. automodule:: zfit_physics.models.pdf_cruijff - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_erfexp.rst b/docs/api/zfit_physics.models.pdf_erfexp.rst deleted file mode 100644 index 7d1ed78..0000000 --- a/docs/api/zfit_physics.models.pdf_erfexp.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_erfexp -=========== - -.. automodule:: zfit_physics.models.pdf_erfexp - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_example.rst b/docs/api/zfit_physics.models.pdf_example.rst deleted file mode 100644 index bd90dbd..0000000 --- a/docs/api/zfit_physics.models.pdf_example.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_example -============ - -.. automodule:: zfit_physics.models.pdf_example - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_kde.rst b/docs/api/zfit_physics.models.pdf_kde.rst deleted file mode 100644 index a64f8e1..0000000 --- a/docs/api/zfit_physics.models.pdf_kde.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_kde -======== - -.. automodule:: zfit_physics.models.pdf_kde - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_novosibirsk.rst b/docs/api/zfit_physics.models.pdf_novosibirsk.rst deleted file mode 100644 index d4ef65e..0000000 --- a/docs/api/zfit_physics.models.pdf_novosibirsk.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_novosibirsk -================ - -.. automodule:: zfit_physics.models.pdf_novosibirsk - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_relbw.rst b/docs/api/zfit_physics.models.pdf_relbw.rst deleted file mode 100644 index bd768c9..0000000 --- a/docs/api/zfit_physics.models.pdf_relbw.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_relbw -========== - -.. automodule:: zfit_physics.models.pdf_relbw - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.pdf_tsallis.rst b/docs/api/zfit_physics.models.pdf_tsallis.rst deleted file mode 100644 index 97e4fd4..0000000 --- a/docs/api/zfit_physics.models.pdf_tsallis.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf\_tsallis -============ - -.. automodule:: zfit_physics.models.pdf_tsallis - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.models.rst b/docs/api/zfit_physics.models.rst deleted file mode 100644 index 61c19a7..0000000 --- a/docs/api/zfit_physics.models.rst +++ /dev/null @@ -1,24 +0,0 @@ -models -====== - -.. automodule:: zfit_physics.models - :members: - :undoc-members: - :show-inheritance: - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.models.pdf_argus - zfit_physics.models.pdf_cmsshape - zfit_physics.models.pdf_conv - zfit_physics.models.pdf_cruijff - zfit_physics.models.pdf_erfexp - zfit_physics.models.pdf_example - zfit_physics.models.pdf_kde - zfit_physics.models.pdf_novosibirsk - zfit_physics.models.pdf_relbw - zfit_physics.models.pdf_tsallis diff --git a/docs/api/zfit_physics.pdf.rst b/docs/api/zfit_physics.pdf.rst deleted file mode 100644 index 13c0245..0000000 --- a/docs/api/zfit_physics.pdf.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf -=== - -.. automodule:: zfit_physics.pdf - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.rst b/docs/api/zfit_physics.rst deleted file mode 100644 index 51e5dc0..0000000 --- a/docs/api/zfit_physics.rst +++ /dev/null @@ -1,24 +0,0 @@ -zfit\_physics package -===================== - -.. automodule:: zfit_physics - :members: - :undoc-members: - :show-inheritance: - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - zfit_physics.models - zfit_physics.unstable - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.pdf diff --git a/docs/api/zfit_physics.unstable.pdf.rst b/docs/api/zfit_physics.unstable.pdf.rst deleted file mode 100644 index 79e75f0..0000000 --- a/docs/api/zfit_physics.unstable.pdf.rst +++ /dev/null @@ -1,7 +0,0 @@ -pdf -=== - -.. automodule:: zfit_physics.unstable.pdf - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/api/zfit_physics.unstable.rst b/docs/api/zfit_physics.unstable.rst deleted file mode 100644 index 9f02a0d..0000000 --- a/docs/api/zfit_physics.unstable.rst +++ /dev/null @@ -1,15 +0,0 @@ -unstable -======== - -.. automodule:: zfit_physics.unstable - :members: - :undoc-members: - :show-inheritance: - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - zfit_physics.unstable.pdf diff --git a/docs/conf.py b/docs/conf.py index 96397b2..4375033 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -335,6 +335,11 @@ "matplotlib": ("https://matplotlib.org/stable/", None), "pandas": ("https://pandas.pydata.org/docs/", None), "numpy": ("https://numpy.org/doc/stable/", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference/", None), + "tensorwaves": ("https://tensorwaves.readthedocs.io/latest/", None), + "zfit": ("https://zfit.readthedocs.io/en/latest/", None), + "tf_pwa": ("https://tf-pwa.readthedocs.io/en/latest/", None), + "pyhf": ("https://pyhf.readthedocs.io/en/latest/", None), } # -- Options for todo extension ---------------------------------------------- diff --git a/docs/make_docs.sh b/docs/make_docs.sh index c3399bc..f9f914c 100755 --- a/docs/make_docs.sh +++ b/docs/make_docs.sh @@ -6,11 +6,10 @@ MAKE_DOCS_PATH="$( cd "$(dirname "$0")" ; pwd -P )" popd > /dev/null # generate the ReST files -echo "debug" -echo ${MAKE_DOCS_PATH}/../zfit_physics +#echo ${MAKE_DOCS_PATH}/../zfit_physics ls ${MAKE_DOCS_PATH} ls . -sphinx-apidoc -o ${MAKE_DOCS_PATH}/api ${MAKE_DOCS_PATH}/../zfit_physics -fMeT && \ +sphinx-apidoc -o ${MAKE_DOCS_PATH}/api ${MAKE_DOCS_PATH}/../src/zfit_physics -fMeT && \ python3 ${MAKE_DOCS_PATH}/api/tools/change_headline.py ${MAKE_DOCS_PATH}/api/zfit_physics.* && \ make -C ${MAKE_DOCS_PATH} clean && make -C ${MAKE_DOCS_PATH} html -j8 && \ echo "Documentation successfully built!" || echo "FAILED to build Documentation" diff --git a/tests/roofit/test_loss_compat.py b/tests/roofit/test_loss_compat.py deleted file mode 100644 index 8b9db51..0000000 --- a/tests/roofit/test_loss_compat.py +++ /dev/null @@ -1,67 +0,0 @@ -import numpy as np -import pytest - - -def test_loss_registry(): - _ = pytest.importorskip("ROOT") - # Copyright (c) 2024 zfit - - import zfit - - import zfit_physics.roofit as zroofit - - # create space - obs = zfit.Space("x", -2, 3) - - # parameters - mu = zfit.Parameter("mu", 1.2, -4, 6) - sigma = zfit.Parameter("sigma", 1.3, 0.5, 10) - - # model building, pdf creation - gauss = zfit.pdf.Gauss(mu=mu, sigma=sigma, obs=obs) - - # data - ndraw = 10_000 - data = np.random.normal(loc=2.0, scale=3.0, size=ndraw) - data = obs.filter(data) # works also for pandas DataFrame - - from ROOT import RooArgSet, RooDataSet, RooFit, RooGaussian, RooRealVar - - mur = RooRealVar("mu", "mu", 1.2, -4, 6) - sigmar = RooRealVar("sigma", "sigma", 1.3, 0.5, 10) - obsr = RooRealVar("x", "x", -2, 3) - gaussr = RooGaussian("gauss", "gauss", obsr, mur, sigmar) - - datar = RooDataSet("data", "data", {obsr}) - for d in data: - obsr.setVal(d) - datar.add(RooArgSet(obsr)) - - # create a loss function - nll = gaussr.createNLL(datar) - - nllz = zfit.loss.UnbinnedNLL(model=gauss, data=data) - - # create a minimizer - tol = 1e-3 - verbosity = 0 - minimizer = zfit.minimize.Minuit(gradient=True, verbosity=verbosity, tol=tol, mode=1) - minimizerzgrad = zfit.minimize.Minuit(gradient=False, verbosity=verbosity, tol=tol, mode=1) - - params = nllz.get_params() - initvals = np.array(params) - - with zfit.param.set_values(params, initvals): - result = minimizer.minimize(nllz) - - with zfit.param.set_values(params, initvals): - result2 = minimizer.minimize(nll) - - assert result.params['mu']['value'] == pytest.approx(result2.params['mu']['value'], rel=1e-3) - assert result.params['sigma']['value'] == pytest.approx(result2.params['sigma']['value'], rel=1e-3) - - with zfit.param.set_values(params, params): - result4 = minimizerzgrad.minimize(nll) - - assert result.params['mu']['value'] == pytest.approx(result4.params['mu']['value'], rel=1e-3) - assert result.params['sigma']['value'] == pytest.approx(result4.params['sigma']['value'], rel=1e-3) From 3edfb6bacc31fb99cc4a164e2a648240cb1e0967 Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 12 Nov 2024 10:26:02 -0500 Subject: [PATCH 2/6] docs: use environment.yml for doc building --- .readthedocs.yaml | 10 +--------- docs/environment.yml | 10 ++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 docs/environment.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8e9f92f..bc45245 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -7,7 +7,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: "3.9" + python: "mambaforge-22.9" @@ -16,11 +16,3 @@ sphinx: configuration: docs/conf.py formats: [ ] - -python: - install: - - requirements: docs/additional_requirements.txt - - method: pip - path: . - extra_requirements: - - dev diff --git a/docs/environment.yml b/docs/environment.yml new file mode 100644 index 0000000..10b328b --- /dev/null +++ b/docs/environment.yml @@ -0,0 +1,10 @@ +name: rtd38 +channels: + - conda-forge + - defaults +dependencies: + - python=3.9 + - root<=6.30 + - uv + - pip: + - .[dev] From caeaf3710efb2753b58504ef9436ad480e34135f Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 12 Nov 2024 10:45:32 -0500 Subject: [PATCH 3/6] docs: use environment.yml for doc building --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index bc45245..20cd904 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -15,4 +15,7 @@ build: sphinx: configuration: docs/conf.py +conda: + environment: environment.yml + formats: [ ] From 60cae705cf532c1fc033c5ccfa0b9705998c6dfc Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 12 Nov 2024 15:59:11 -0500 Subject: [PATCH 4/6] fix: typo --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 20cd904..97b122d 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -16,6 +16,6 @@ sphinx: configuration: docs/conf.py conda: - environment: environment.yml + environment: docs/environment.yml formats: [ ] From 3b8391c2eb8680caa4530c22385c933c43659a1e Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 12 Nov 2024 16:14:11 -0500 Subject: [PATCH 5/6] fix: typo --- docs/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/environment.yml b/docs/environment.yml index 10b328b..8546f08 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -7,4 +7,4 @@ dependencies: - root<=6.30 - uv - pip: - - .[dev] + - ../[dev] From b3352498d6eb7eaedfa874387b37fa69c847ddeb Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 12 Nov 2024 16:43:36 -0500 Subject: [PATCH 6/6] fix: typo --- docs/api/static/zfit_physics.roofit.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/static/zfit_physics.roofit.rst b/docs/api/static/zfit_physics.roofit.rst index 45c036b..2ae151c 100644 --- a/docs/api/static/zfit_physics.roofit.rst +++ b/docs/api/static/zfit_physics.roofit.rst @@ -16,6 +16,7 @@ For example via conda: :hide-output: import numpy as np + import zfit from ROOT import RooArgSet, RooDataSet, RooGaussian, RooRealVar data = np.random.normal(loc=2.0, scale=3.0, size=1000)