Skip to content

Commit 6d4a7d8

Browse files
committed
restyled parts of the code
1 parent af24b27 commit 6d4a7d8

File tree

14 files changed

+81
-62
lines changed

14 files changed

+81
-62
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 3
1111
matrix:
12-
python-version: [3.9, '3.10']
12+
python-version: [3.9, '3.12']
1313

1414
steps:
1515
- uses: actions/checkout@v1

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ distribute = [
4343
'distributed',
4444
'dask-jobqueue',
4545
]
46+
47+
[tool.black]
48+
line-length = 100
49+
skip_magic_trailing_comma = true
50+
51+
[tool.isort]
52+
atomic = true
53+
line_length = 120
54+
profile = "black" # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#custom-configuration
55+
skip_gitignore = true
56+
known_first_party = ["bgtrees"]
57+
force_sort_within_sections = true
58+

src/vegasflow/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Monte Carlo integration with Tensorflow"""
22

3-
from vegasflow.configflow import int_me, float_me, run_eager, DTYPE, DTYPEINT
3+
from vegasflow.configflow import DTYPE, DTYPEINT, float_me, int_me, run_eager
4+
from vegasflow.plain import PlainFlow, plain_sampler, plain_wrapper
45

56
# Expose the main interfaces
6-
from vegasflow.vflow import VegasFlow, vegas_wrapper, vegas_sampler
7-
from vegasflow.plain import PlainFlow, plain_wrapper, plain_sampler
8-
from vegasflow.vflowplus import VegasFlowPlus, vegasflowplus_wrapper, vegasflowplus_sampler
7+
from vegasflow.vflow import VegasFlow, vegas_sampler, vegas_wrapper
8+
from vegasflow.vflowplus import VegasFlowPlus, vegasflowplus_sampler, vegasflowplus_wrapper
99

1010
__version__ = "1.4.0"

src/vegasflow/configflow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
22
Define some constants, header style
33
"""
4+
5+
import logging
6+
47
# Most of this can be moved to a yaml file without loss of generality
58
import os
6-
import logging
9+
710
import numpy as np
811

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

9598

9699
FMAX = tf.constant(np.finfo(np.float64).max, dtype=DTYPE)
100+
101+
97102
# The wrappers below transform tensors and array to the correct type
98103
def int_me(i):
99104
"""Cast the input to the `DTYPEINT` type"""

src/vegasflow/monte_carlo.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,29 @@
3232
as it is the first one found idle.
3333
"""
3434

35-
import inspect
36-
import time
35+
from abc import ABC, abstractmethod
3736
import copy
38-
import threading
37+
import inspect
3938
import logging
40-
from abc import abstractmethod, ABC
39+
import threading
40+
import time
41+
4142
import joblib
4243
import numpy as np
4344
import tensorflow as tf
45+
4446
from vegasflow.configflow import (
45-
MAX_EVENTS_LIMIT,
4647
DEFAULT_ACTIVE_DEVICES,
4748
DTYPE,
4849
DTYPEINT,
50+
MAX_EVENTS_LIMIT,
4951
TECH_CUT,
5052
float_me,
51-
int_me,
5253
fone,
5354
fzero,
55+
int_me,
5456
)
5557

56-
5758
logger = logging.getLogger(__name__)
5859

5960

@@ -304,7 +305,8 @@ def _apply_integration_limits(self, rand):
304305

305306
def _can_run_vectorial(self, expected_shape=None):
306307
"""Accepting vectorial integrands depends on the algorithm,
307-
if an algorithm can run on vectorial algorithms it should implement this method and return True"""
308+
if an algorithm can run on vectorial algorithms it should implement this method and return True
309+
"""
308310
return self._CAN_RUN_VECTORIAL
309311

310312
#### Integration management
@@ -561,7 +563,7 @@ def compile(self, integrand, compilable=True, signature=None, trace=False, check
561563
signature = False
562564

563565
compile_options = {
564-
"experimental_autograph_options": tf.autograph.experimental.Feature.ALL,
566+
"experimental_autograph_options": tf.autograph.experimental.Feature.ALL
565567
}
566568
if signature is None:
567569
signature = autodiscover_signature
@@ -606,14 +608,14 @@ def batch_events(**kwargs):
606608
)
607609
test_array = tf.random.uniform((event_size, self.n_dim), dtype=DTYPE)
608610
wgt = tf.random.uniform((event_size,), dtype=DTYPE)
609-
res_tmp = new_integrand(test_array, weight=wgt)#.numpy()
611+
res_tmp = new_integrand(test_array, weight=wgt) # .numpy()
610612
res_shape = res_tmp.shape
611613

612614
expected_shape = (event_size,)
613615

614616
if len(res_shape) == 2:
615617
self._vectorial = True
616-
expected_shape = res_tmp.reshape(event_size, -1).shape
618+
expected_shape = tf.reshape(res_tmp, (event_size, -1)).shape
617619
if not self._can_run_vectorial(expected_shape):
618620
raise NotImplementedError(
619621
f"""The {self.__class__.__name__} algorithm does not support vectorial integrands

src/vegasflow/plain.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
Plain implementation of the plainest possible MonteCarlo
33
"""
44

5-
from vegasflow.configflow import fone, fzero
6-
from vegasflow.monte_carlo import MonteCarloFlow, wrapper, sampler
75
import tensorflow as tf
86

7+
from vegasflow.configflow import fone, fzero
8+
from vegasflow.monte_carlo import MonteCarloFlow, sampler, wrapper
9+
910

1011
class PlainFlow(MonteCarloFlow):
1112
"""

src/vegasflow/tests/test_algs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
everything works """
88
import json
99
import tempfile
10-
import pytest
10+
1111
import numpy as np
12+
import pytest
13+
import tensorflow as tf
14+
15+
from vegasflow import plain_sampler, vegas_sampler
1216
from vegasflow.configflow import DTYPE, run_eager
13-
from vegasflow.vflow import VegasFlow
1417
from vegasflow.plain import PlainFlow
18+
from vegasflow.vflow import VegasFlow
1519
from vegasflow.vflowplus import VegasFlowPlus
16-
from vegasflow import plain_sampler, vegas_sampler
17-
import tensorflow as tf
1820

1921
# Test setup
2022
dim = 2

src/vegasflow/tests/test_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Test that the configuration is consistent
33
"""
44

5+
import importlib
56
import os
7+
68
import numpy as np
7-
import importlib
9+
810
import vegasflow.configflow
9-
from vegasflow.configflow import DTYPE, DTYPEINT, int_me, float_me
11+
from vegasflow.configflow import DTYPE, DTYPEINT, float_me, int_me
1012

1113

1214
def test_int_me():

src/vegasflow/tests/test_gradients.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
import numpy as np
66
from pytest import mark
7-
8-
from vegasflow import float_me, run_eager
9-
from vegasflow import VegasFlow, VegasFlowPlus, PlainFlow
107
import tensorflow as tf
118

9+
from vegasflow import PlainFlow, VegasFlow, VegasFlowPlus, float_me, run_eager
10+
1211

1312
def generate_integrand(variable):
1413
"""Generate an integrand that depends on an input variable"""

src/vegasflow/tests/test_misc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""
22
Miscellaneous tests that don't really fit anywhere else
33
"""
4-
import pytest
5-
import numpy as np
64

7-
from vegasflow import VegasFlow, VegasFlowPlus, PlainFlow
5+
import numpy as np
6+
import pytest
87
import tensorflow as tf
98

10-
from .test_algs import instance_and_compile, check_is_one
9+
from vegasflow import PlainFlow, VegasFlow, VegasFlowPlus
10+
11+
from .test_algs import check_is_one, instance_and_compile
1112

1213

1314
def _vector_integrand(xarr, weight=None):

0 commit comments

Comments
 (0)