diff --git a/logger_test.py b/logger_test.py new file mode 100644 index 00000000..843bd2e5 --- /dev/null +++ b/logger_test.py @@ -0,0 +1,23 @@ +"""This test is to test that logging works properly when importing torchquad.""" + +import unittest +from contextlib import contextmanager +from loguru import logger + +@contextmanager +def capture_logs(level = "INFO", format="{message}"): + """"Capture loguru-based logs.""" + output = [] + handler_id = logger.add(output.append, level = level, format = format) + + yield output + logger.remove(handler_id) + +class TestLogger(unittest.TestCase): + + def test_logging_with_tq(self): + import torchquad + with capture_logs() as cap_log: + logger.info("This message should print.") + self.assertEqual(cap_log,["This message should print.\n"]) + diff --git a/torchquad/__init__.py b/torchquad/__init__.py index fa5aa003..fd29b633 100644 --- a/torchquad/__init__.py +++ b/torchquad/__init__.py @@ -46,5 +46,4 @@ "_deployment_test", ] -set_log_level(os.environ.get("TORCHQUAD_LOG_LEVEL", "WARNING")) logger.info("Initializing torchquad.") diff --git a/torchquad/integration/utils.py b/torchquad/integration/utils.py index 9e78ac4a..882c6ca9 100644 --- a/torchquad/integration/utils.py +++ b/torchquad/integration/utils.py @@ -122,6 +122,7 @@ def _setup_integration_domain(dim, integration_domain, backend): # ignored unless its backend and the backend argument are the same. domain_arg_backend = infer_backend(integration_domain) convert_to_tensor = domain_arg_backend == "builtins" + if not convert_to_tensor and backend is not None and domain_arg_backend != backend: logger.warning( "integration_domain should be a list when the backend argument is set." diff --git a/torchquad/integration/vegas_map.py b/torchquad/integration/vegas_map.py index c81a6d92..a4c59ddd 100644 --- a/torchquad/integration/vegas_map.py +++ b/torchquad/integration/vegas_map.py @@ -30,6 +30,7 @@ def __init__(self, N_intervals, dim, backend, dtype, alpha=0.5) -> None: # Boundary locations x_edges and subdomain stepsizes dx_edges # Subdivide the domain [0,1]^dim equally spaced in N-d, EQ 8 + self.dx_edges = ( anp.ones((self.dim, self.N_intervals), dtype=self.dtype, like=self.backend) / self.N_intervals @@ -195,7 +196,8 @@ def _reset_weight(self): def update_map(self): """Update the adaptive map, Section II C.""" - smoothed_weights = self._smooth_map(self.weights, self.counts, self.alpha) + #smoothed_weights = self._smooth_map(self.weights, self.counts, self.alpha) + smoothed_weights = None if smoothed_weights is None: logger.warning( "Cannot update the VEGASMap. This can happen with an integrand "