Skip to content

Commit

Permalink
Merge pull request #90 from N3PDF/bump_version_pyproject
Browse files Browse the repository at this point in the history
Bump version and add pyproject.toml
  • Loading branch information
scarlehoff authored Jan 30, 2025
2 parents 2f86026 + 6d4a7d8 commit 115104f
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 3
matrix:
python-version: [3.9, '3.10']
python-version: [3.9, '3.12']

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions examples/example_pineappl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def hadronic_pspgen(xarr, mmin, mmax):
x2 = tau / y
s = tau * smax

jacobian = np.math.log(tau0) * np.math.log(tau0) * tau * r1
jacobian = np.log(tau0) * np.log(tau0) * tau * r1

# theta integration (in the CMS)
cos_theta = 2.0 * r3 - 1.0
Expand All @@ -71,7 +71,7 @@ def hadronic_pspgen(xarr, mmin, mmax):
u = -0.5 * s * (1.0 + cos_theta)

# phi integration
jacobian *= 2.0 * np.math.acos(-1.0)
jacobian *= 2.0 * np.acos(-1.0)

return s, t, u, x1, x2, jacobian

Expand Down
58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "vegasflow"
version = "1.4.0"
description="Hardware agnostic Monte Carlo integration"
authors = [
{name = "S. Carrazza", email = "[email protected]"},
{name = "J.Cruz-Martinez", email = "[email protected]"}
]
classifiers=[
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Physics',
]
dependencies = [
"joblib",
"numpy",
"tensorflow>2.2"
]

[project.optional-dependencies]
docs = [
'sphinx_rtd_theme',
'recommonmark',
'sphinxcontrib-bibtex',
]
examples = [
'cffi',
'pineappl',
'pdfflow',
'scipy'
]
benchmark = [
'vegas', # Lepage's Vegas for benchmarking
]
distribute = [
'dask',
'distributed',
'dask-jobqueue',
]

[tool.black]
line-length = 100
skip_magic_trailing_comma = true

[tool.isort]
atomic = true
line_length = 120
profile = "black" # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#custom-configuration
skip_gitignore = true
known_first_party = ["bgtrees"]
force_sort_within_sections = true

67 changes: 0 additions & 67 deletions setup.py

This file was deleted.

10 changes: 5 additions & 5 deletions src/vegasflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Monte Carlo integration with Tensorflow"""

from vegasflow.configflow import int_me, float_me, run_eager, DTYPE, DTYPEINT
from vegasflow.configflow import DTYPE, DTYPEINT, float_me, int_me, run_eager
from vegasflow.plain import PlainFlow, plain_sampler, plain_wrapper

# Expose the main interfaces
from vegasflow.vflow import VegasFlow, vegas_wrapper, vegas_sampler
from vegasflow.plain import PlainFlow, plain_wrapper, plain_sampler
from vegasflow.vflowplus import VegasFlowPlus, vegasflowplus_wrapper, vegasflowplus_sampler
from vegasflow.vflow import VegasFlow, vegas_sampler, vegas_wrapper
from vegasflow.vflowplus import VegasFlowPlus, vegasflowplus_sampler, vegasflowplus_wrapper

__version__ = "1.3.0"
__version__ = "1.4.0"
7 changes: 6 additions & 1 deletion src/vegasflow/configflow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""
Define some constants, header style
"""

import logging

# Most of this can be moved to a yaml file without loss of generality
import os
import logging

import numpy as np

# Some global parameters
Expand Down Expand Up @@ -94,6 +97,8 @@ def run_eager(flag=True):


FMAX = tf.constant(np.finfo(np.float64).max, dtype=DTYPE)


# The wrappers below transform tensors and array to the correct type
def int_me(i):
"""Cast the input to the `DTYPEINT` type"""
Expand Down
24 changes: 13 additions & 11 deletions src/vegasflow/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,29 @@
as it is the first one found idle.
"""

import inspect
import time
from abc import ABC, abstractmethod
import copy
import threading
import inspect
import logging
from abc import abstractmethod, ABC
import threading
import time

import joblib
import numpy as np
import tensorflow as tf

from vegasflow.configflow import (
MAX_EVENTS_LIMIT,
DEFAULT_ACTIVE_DEVICES,
DTYPE,
DTYPEINT,
MAX_EVENTS_LIMIT,
TECH_CUT,
float_me,
int_me,
fone,
fzero,
int_me,
)


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -304,7 +305,8 @@ def _apply_integration_limits(self, rand):

def _can_run_vectorial(self, expected_shape=None):
"""Accepting vectorial integrands depends on the algorithm,
if an algorithm can run on vectorial algorithms it should implement this method and return True"""
if an algorithm can run on vectorial algorithms it should implement this method and return True
"""
return self._CAN_RUN_VECTORIAL

#### Integration management
Expand Down Expand Up @@ -561,7 +563,7 @@ def compile(self, integrand, compilable=True, signature=None, trace=False, check
signature = False

compile_options = {
"experimental_autograph_options": tf.autograph.experimental.Feature.ALL,
"experimental_autograph_options": tf.autograph.experimental.Feature.ALL
}
if signature is None:
signature = autodiscover_signature
Expand Down Expand Up @@ -606,14 +608,14 @@ def batch_events(**kwargs):
)
test_array = tf.random.uniform((event_size, self.n_dim), dtype=DTYPE)
wgt = tf.random.uniform((event_size,), dtype=DTYPE)
res_tmp = new_integrand(test_array, weight=wgt).numpy()
res_tmp = new_integrand(test_array, weight=wgt) # .numpy()
res_shape = res_tmp.shape

expected_shape = (event_size,)

if len(res_shape) == 2:
self._vectorial = True
expected_shape = res_tmp.reshape(event_size, -1).shape
expected_shape = tf.reshape(res_tmp, (event_size, -1)).shape
if not self._can_run_vectorial(expected_shape):
raise NotImplementedError(
f"""The {self.__class__.__name__} algorithm does not support vectorial integrands
Expand Down
5 changes: 3 additions & 2 deletions src/vegasflow/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Plain implementation of the plainest possible MonteCarlo
"""

from vegasflow.configflow import fone, fzero
from vegasflow.monte_carlo import MonteCarloFlow, wrapper, sampler
import tensorflow as tf

from vegasflow.configflow import fone, fzero
from vegasflow.monte_carlo import MonteCarloFlow, sampler, wrapper


class PlainFlow(MonteCarloFlow):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/vegasflow/tests/test_algs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
everything works """
import json
import tempfile
import pytest

import numpy as np
import pytest
import tensorflow as tf

from vegasflow import plain_sampler, vegas_sampler
from vegasflow.configflow import DTYPE, run_eager
from vegasflow.vflow import VegasFlow
from vegasflow.plain import PlainFlow
from vegasflow.vflow import VegasFlow
from vegasflow.vflowplus import VegasFlowPlus
from vegasflow import plain_sampler, vegas_sampler
import tensorflow as tf

# Test setup
dim = 2
Expand Down
6 changes: 4 additions & 2 deletions src/vegasflow/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Test that the configuration is consistent
"""

import importlib
import os

import numpy as np
import importlib

import vegasflow.configflow
from vegasflow.configflow import DTYPE, DTYPEINT, int_me, float_me
from vegasflow.configflow import DTYPE, DTYPEINT, float_me, int_me


def test_int_me():
Expand Down
5 changes: 2 additions & 3 deletions src/vegasflow/tests/test_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import numpy as np
from pytest import mark

from vegasflow import float_me, run_eager
from vegasflow import VegasFlow, VegasFlowPlus, PlainFlow
import tensorflow as tf

from vegasflow import PlainFlow, VegasFlow, VegasFlowPlus, float_me, run_eager


def generate_integrand(variable):
"""Generate an integrand that depends on an input variable"""
Expand Down
9 changes: 5 additions & 4 deletions src/vegasflow/tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Miscellaneous tests that don't really fit anywhere else
"""
import pytest
import numpy as np

from vegasflow import VegasFlow, VegasFlowPlus, PlainFlow
import numpy as np
import pytest
import tensorflow as tf

from .test_algs import instance_and_compile, check_is_one
from vegasflow import PlainFlow, VegasFlow, VegasFlowPlus

from .test_algs import check_is_one, instance_and_compile


def _vector_integrand(xarr, weight=None):
Expand Down
6 changes: 2 additions & 4 deletions src/vegasflow/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
""" Test the utilities """

import numpy as np
import tensorflow as tf
import pytest
import tensorflow as tf

from vegasflow.configflow import DTYPEINT, int_me
from vegasflow.utils import consume_array_into_indices, py_consume_array_into_indices

from vegasflow.utils import generate_condition_function
from vegasflow.utils import consume_array_into_indices, generate_condition_function, py_consume_array_into_indices


def test_consume_array_into_indices():
Expand Down
3 changes: 2 additions & 1 deletion src/vegasflow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
This module contains tensorflow_compiled utilities
"""

from vegasflow.configflow import DTYPEINT, DTYPE, float_me, int_me, fzero
import tensorflow as tf

from vegasflow.configflow import DTYPE, DTYPEINT, float_me, fzero, int_me


@tf.function(
input_signature=[
Expand Down
Loading

0 comments on commit 115104f

Please sign in to comment.