Skip to content

Add checks #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[bumpversion]
commit = True
tag = True
current_version = 1.0.0-dev
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}

[bumpversion:file:setup.py]

[bumpversion:file:./src/pycompressor/__init__.py]

[bumpversion:part:release]
optional_value = prod
first_value = dev
values =
dev
prod
4 changes: 2 additions & 2 deletions .github/workflows/deploy_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install packages 📦
run: |
# install pip
python -m pip install --upgrade pip
pip install .[docs]
pip install .
pip install -r docs-requirements.txt
- name: Build 🔨
run: |
cd doc/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Test modules and coverage with pytest
shell: bash --login {0}
run: |
pip install .[tests]
pip install -r tests-requirements.txt
pytest -v tests/ --cov=./src/pycompressor --cov-report=xml
- name: Upload coverage report
uses: codecov/codecov-action@v1
Expand Down
3 changes: 3 additions & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recommonmark
sphinx_rtd_theme
sphinxcontrib-bibtex
1 change: 1 addition & 0 deletions ganpdfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ nd_steps : 4 # Number of steps to train
ng_steps : 3 # Number of steps to train the Generator for one training run
batch_size : 70 # Batch size per epoch in terms of percentage
epochs : 1000 # Number of epochs
pdf: NNPDF40_nnlo_as_0118_1000
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cma
numpy
numba
rich
scipy
tqdm
2 changes: 1 addition & 1 deletion runcard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# PDF Set #
###################################################
pdfsetting:
pdf: NNPDF40_nnlo_as_0118_1000rep
pdf: NNPDF40_nnlo_as_0118_1000
existing_enhanced: False

###################################################
Expand Down
92 changes: 23 additions & 69 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,54 @@
"""
pyCompressor is a Python implementation of a compressor code
presented in this paper https://arxiv.org/pdf/1504.06469 and
implemented here https://github.com/scarrazza/compressor.
pyCompressor is q python package for Monte Carlo Parton Distribution Functions
(PDFs) compression.

This program has been developed within the N3PDF group.
(n3pdf.mi.infn.it/)
This program has been developed within the N3PDF group. (n3pdf.mi.infn.it/)

Authors: - Stefano Carrazza
- Juan Cruz-Martinez
- Juan M. Cruz-Martinez
- Tanjona R. Rabemananjara

License: GPL-3.0, 2020
"""


import os
import re
import pathlib
from setuptools import setup
from setuptools import find_packages

PACKAGE = "pycompressor"
THIS_DIR = pathlib.Path(__file__).parent
LONG_DESCRIPTION = (THIS_DIR / "README.md").read_text()
REQUIREMENTS = (THIS_DIR / "requirements.txt").read_text()

# Used for pytest and code coverage
TESTS_REQUIEREMENTS = [
"pylint",
"pytest",
"pytest-cov",
"pytest-env",
"pygit2",
"semver"
]

# Dependencies for the packages
PACKAGE_REQUIEREMENTS = [
"cma",
"tqdm",
"scipy",
"numpy",
"numba",
"rich"
]

# Depending on the documents more dependencies can be added
DOCS_REQUIEREMENTS = [
"recommonmark",
"sphinx_rtd_theme",
"sphinxcontrib-bibtex"
]

# Check if LHAPDF is installed
try:
import lhapdf
except ImportError:
print(f"Note: {PACKAGE} requires the installation of LHAPDF")

# Check if Validphys is installed
try:
import validphys
except ImportError:
print(f"Note: {PACKAGE} requires the installation of VALIDPHYS")

# Read through Readme
try:
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()
except IOError:
print("Read me file not found.")


# Get package version
def get_version():
"""
Gets the version from the package's __init__ file
if there is some problem, let it happily fail
"""
VERSIONFILE = os.path.join("src", PACKAGE, "__init__.py")
initfile_lines = open(VERSIONFILE, "rt").readlines()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
for line in initfile_lines:
mo = re.search(VSRE, line, re.M)
if mo:
return mo.group(1)


setup(
name=PACKAGE,
version=get_version(),
description="PDF set compressor",
author="Stefano Carrazza, Juan Cruz Martinez, Tanjona R. Rabemananjara",
version='1.0.0-dev',
description="PDF Compression",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author="N3PDF",
author_email="tanjona.rabemananjara@mi.infn.it",
license="GPL 3.0",
url="https://github.com/N3PDF/pyCompressor",
extras_require={"docs": DOCS_REQUIEREMENTS, "tests": TESTS_REQUIEREMENTS},
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=PACKAGE_REQUIEREMENTS,
entry_points={"console_scripts":
[
zip_safe=False,
project_urls={
"Documentation": "https://n3pdf.github.io/pycompressor/",
"Source": "https://github.com/N3PDF/pyCompressor"
},
entry_points={
"console_scripts": [
"pycomp = pycompressor.scripts.main:main",
"validate = pycompressor.scripts.validate:main",
"cmp-fids = pycompressor.scripts.fids:main",
Expand All @@ -107,10 +59,12 @@ def get_version():
},
package_dir={"": "src"},
packages=find_packages("src"),
install_requires=REQUIREMENTS,
classifiers=[
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
],
Expand Down
2 changes: 1 addition & 1 deletion src/pycompressor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.0.0-dev"
12 changes: 4 additions & 8 deletions src/pycompressor/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# implement ValidPhys application
# ValidPhys Action

import re
import sys
import shutil
import pathlib
import logging
import hashlib
import warnings

from validphys.app import App
from reportengine import colors
from reportengine.compat import yaml
from validphys.app import App
from validphys.config import Environment, Config
from validphys.config import EnvironmentError_, ConfigError

Expand All @@ -34,9 +31,8 @@ def init_output(self):
# check file exists, is a file, has extension.
if not self.config_yml.exists():
raise CompressorError("Invalid runcard. File not found.")
else:
if not self.config_yml.is_file():
raise CompressorError("Invalid runcard. Must be a file.")
if not self.config_yml.is_file():
raise CompressorError("Invalid runcard. Must be a file.")
# Check if results folder exists
self.output_path = pathlib.Path(self.output_path).absolute()
try:
Expand Down
35 changes: 23 additions & 12 deletions src/pycompressor/compressing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import shutil
import logging
import pathlib
import numpy as np
Expand All @@ -10,12 +9,13 @@
from rich.style import Style
from rich.console import Console
from numpy.random import Generator, PCG64
from reportengine.checks import CheckError
from reportengine.checks import make_argcheck

from pycompressor.pdfgrid import XGrid
from pycompressor.pdfgrid import PdfSet
from pycompressor.compressor import compress
from pycompressor.utils import remap_index
from pycompressor.compressor import Compress
from pycompressor.utils import extract_index
from pycompressor.utils import extract_estvalues

console = Console()
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -44,19 +44,30 @@ def splash():
console.print(logo)


@make_argcheck
def check_validity(pdfsetting, compressed, gans):
members = pdfsetting["pdf"].load().GetMembers()
if members < compressed:
if not gans["enhance"] and not pdfsetting["existing_enhanced"]:
raise CheckError(
f" Cannot get {compressed} replicas from"
f" {members} members if enhancing is not active.")


@check_validity
def compressing(pdfsetting, compressed, minimizer, est_dic, gans):
"""
Action that performs the compression. The parameters
for the compression are provided by a `runcard.yml`.

Parameters
----------
pdf: str
pdf/PDF name
compressed: int
Size of the compressed set
est_dic: dict
Dictionary containing the list of estimators
pdf: str
pdf/PDF name
compressed: int
Size of the compressed set
est_dic: dict
Dictionary containing the list of estimators
"""

pdf = str(pdfsetting["pdf"])
Expand Down Expand Up @@ -136,7 +147,7 @@ def compressing(pdfsetting, compressed, minimizer, est_dic, gans):
console.print(table)

# Init. Compressor class
comp = compress(
comp = Compress(
prior,
enhanced,
est_dic,
Expand All @@ -152,7 +163,7 @@ def compressing(pdfsetting, compressed, minimizer, est_dic, gans):
if minimizer == "genetic":
# Run compressor using GA
with trange(nb_iter) as iter_range:
for i in iter_range:
for _ in iter_range:
iter_range.set_description("Compression")
erf, index = comp.genetic_algorithm(nb_mut=5)
erf_list.append(erf)
Expand Down
Loading