Skip to content

Commit 9886f8b

Browse files
pdb5627michaelosthege
authored andcommitted
Change logger names from all "pymc" to module name (__name__)
1 parent f632a34 commit 9886f8b

File tree

15 files changed

+63
-35
lines changed

15 files changed

+63
-35
lines changed

pymc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import logging
1818

19-
_log = logging.getLogger("pymc")
19+
_log = logging.getLogger(__name__)
2020

2121
if not logging.root.handlers:
2222
_log.setLevel(logging.INFO)

pymc/backends/arviz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
___all__ = [""]
4848

49-
_log = logging.getLogger("pymc")
49+
_log = logging.getLogger(__name__)
5050

5151
# random variable object ...
5252
Var = Any # pylint: disable=invalid-name

pymc/backends/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from pymc.model import modelcontext
4343
from pymc.util import get_var_name
4444

45-
logger = logging.getLogger("pymc")
45+
logger = logging.getLogger(__name__)
4646

4747

4848
class BackendError(Exception):

pymc/backends/mcbackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
flatten_steps,
3838
)
3939

40-
_log = logging.getLogger("pymc")
40+
_log = logging.getLogger(__name__)
4141

4242

4343
def find_data(pmodel: Model) -> List[mcb.DataVariable]:

pymc/backends/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from pymc.stats.convergence import _LEVELS, SamplerWarning
2121

22-
logger = logging.getLogger("pymc")
22+
logger = logging.getLogger(__name__)
2323

2424

2525
class SamplerReport:

pymc/distributions/simulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
__all__ = ["Simulator"]
3131

32-
_log = logging.getLogger("pymc")
32+
_log = logging.getLogger(__name__)
3333

3434

3535
class SimulatorRV(RandomVariable):

pymc/ode/ode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from pymc.exceptions import DtypeError, ShapeError
2727
from pymc.ode import utils
2828

29-
_log = logging.getLogger("pymc")
29+
_log = logging.getLogger(__name__)
3030
floatX = pytensor.config.floatX
3131

3232

pymc/sampling/forward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
ArrayLike: TypeAlias = Union[np.ndarray, List[float]]
8181
PointList: TypeAlias = List[PointType]
8282

83-
_log = logging.getLogger("pymc")
83+
_log = logging.getLogger(__name__)
8484

8585

8686
def get_vars_in_point_list(trace, model):

pymc/sampling/mcmc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __call__(self, trace: IBaseTrace, draw: Draw):
8686
pass
8787

8888

89-
_log = logging.getLogger("pymc")
89+
_log = logging.getLogger(__name__)
9090

9191

9292
def instantiate_steppers(

pymc/sampling/parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from pymc.exceptions import SamplingError
3333
from pymc.util import RandomSeed
3434

35-
logger = logging.getLogger("pymc")
35+
logger = logging.getLogger(__name__)
3636

3737

3838
class ParallelSamplingError(Exception):

pymc/sampling/population.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
Step: TypeAlias = Union[BlockedStep, CompoundStep]
4646

4747

48-
_log = logging.getLogger("pymc")
48+
_log = logging.getLogger(__name__)
4949

5050

5151
def _sample_population(

pymc/smc/sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def sample_smc(
193193

194194
model = modelcontext(model)
195195

196-
_log = logging.getLogger("pymc")
196+
_log = logging.getLogger(__name__)
197197
_log.info("Initializing SMC sampler...")
198198
_log.info(
199199
f"Sampling {chains} chain{'s' if chains > 1 else ''} "

pymc/stats/convergence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"critical": logging.CRITICAL,
3030
}
3131

32-
logger = logging.getLogger("pymc")
32+
logger = logging.getLogger(__name__)
3333

3434

3535
@enum.unique

pymc/step_methods/hmc/base_hmc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from pymc.tuning import guess_scaling
3636
from pymc.util import get_value_vars_from_user_vars
3737

38-
logger = logging.getLogger("pymc")
38+
logger = logging.getLogger(__name__)
3939

4040

4141
class DivergenceInfo(NamedTuple):

tests/sampling/test_forward.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,12 @@ def test_logging_sampled_basic_rvs_prior(self, caplog):
805805

806806
with m:
807807
pm.sample_prior_predictive(samples=1)
808-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [x, z]")]
808+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [x, z]")]
809809
caplog.clear()
810810

811811
with m:
812812
pm.sample_prior_predictive(samples=1, var_names=["x"])
813-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [x]")]
813+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [x]")]
814814
caplog.clear()
815815

816816
def test_logging_sampled_basic_rvs_posterior(self, caplog):
@@ -823,40 +823,44 @@ def test_logging_sampled_basic_rvs_posterior(self, caplog):
823823
idata = az_from_dict(posterior={"x": np.zeros(5), "x_det": np.ones(5), "y": np.ones(5)})
824824
with m:
825825
pm.sample_posterior_predictive(idata)
826-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [z]")]
826+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [z]")]
827827
caplog.clear()
828828

829829
with m:
830830
pm.sample_posterior_predictive(idata, var_names=["y", "z"])
831-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [y, z]")]
831+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [y, z]")]
832832
caplog.clear()
833833

834834
# Resampling `x` will force resampling of `y`, even if it is in trace
835835
with m:
836836
pm.sample_posterior_predictive(idata, var_names=["x", "z"])
837-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [x, y, z]")]
837+
assert caplog.record_tuples == [
838+
("pymc.sampling.forward", logging.INFO, "Sampling: [x, y, z]")
839+
]
838840
caplog.clear()
839841

840842
# Missing deterministic `x_det` does not show in the log, even if it is being
841843
# recomputed, only `y` RV shows
842844
idata = az_from_dict(posterior={"x": np.zeros(5)})
843845
with m:
844846
pm.sample_posterior_predictive(idata)
845-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [y, z]")]
847+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [y, z]")]
846848
caplog.clear()
847849

848850
# Missing deterministic `x_det` does not cause recomputation of downstream `y` RV
849851
idata = az_from_dict(posterior={"x": np.zeros(5), "y": np.ones(5)})
850852
with m:
851853
pm.sample_posterior_predictive(idata)
852-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [z]")]
854+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [z]")]
853855
caplog.clear()
854856

855857
# Missing `x` causes sampling of downstream `y` RV, even if it is present in trace
856858
idata = az_from_dict(posterior={"y": np.ones(5)})
857859
with m:
858860
pm.sample_posterior_predictive(idata)
859-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [x, y, z]")]
861+
assert caplog.record_tuples == [
862+
("pymc.sampling.forward", logging.INFO, "Sampling: [x, y, z]")
863+
]
860864
caplog.clear()
861865

862866
def test_logging_sampled_basic_rvs_posterior_deterministic(self, caplog):
@@ -871,7 +875,7 @@ def test_logging_sampled_basic_rvs_posterior_deterministic(self, caplog):
871875
idata = az_from_dict(posterior={"x": np.zeros(5), "x_det": np.ones(5), "y": np.ones(5)})
872876
with m:
873877
pm.sample_posterior_predictive(idata, var_names=["x_det", "z"])
874-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [y, z]")]
878+
assert caplog.record_tuples == [("pymc.sampling.forward", logging.INFO, "Sampling: [y, z]")]
875879
caplog.clear()
876880

877881
@staticmethod
@@ -938,19 +942,25 @@ def test_logging_sampled_basic_rvs_posterior_mutable(self, mock_sample_results,
938942
# MultiTrace will only have the actual MCMC posterior samples but no information on
939943
# the MutableData and mutable coordinate values, so it will always assume they are volatile
940944
# and resample their descendants
941-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
945+
assert caplog.record_tuples == [
946+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
947+
]
942948
caplog.clear()
943949
elif kind == "InferenceData":
944950
# InferenceData has all MCMC posterior samples and the values for both coordinates and
945951
# data containers. This enables it to see that no data has changed and it should only
946952
# resample the observed variable
947-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [y]")]
953+
assert caplog.record_tuples == [
954+
("pymc.sampling.forward", logging.INFO, "Sampling: [y]")
955+
]
948956
caplog.clear()
949957
elif kind == "Dataset":
950958
# Dataset has all MCMC posterior samples and the values of the coordinates. This
951959
# enables it to see that the coordinates have not changed, but the MutableData is
952960
# assumed volatile by default
953-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [b, y]")]
961+
assert caplog.record_tuples == [
962+
("pymc.sampling.forward", logging.INFO, "Sampling: [b, y]")
963+
]
954964
caplog.clear()
955965

956966
original_offsets = model["offsets"].get_value()
@@ -959,13 +969,19 @@ def test_logging_sampled_basic_rvs_posterior_mutable(self, mock_sample_results,
959969
pm.set_data({"offsets": original_offsets + 1})
960970
pm.sample_posterior_predictive(samples)
961971
if kind == "MultiTrace":
962-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
972+
assert caplog.record_tuples == [
973+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
974+
]
963975
caplog.clear()
964976
elif kind == "InferenceData":
965-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [b, y]")]
977+
assert caplog.record_tuples == [
978+
("pymc.sampling.forward", logging.INFO, "Sampling: [b, y]")
979+
]
966980
caplog.clear()
967981
elif kind == "Dataset":
968-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [b, y]")]
982+
assert caplog.record_tuples == [
983+
("pymc.sampling.forward", logging.INFO, "Sampling: [b, y]")
984+
]
969985
caplog.clear()
970986

971987
with model:
@@ -974,13 +990,19 @@ def test_logging_sampled_basic_rvs_posterior_mutable(self, mock_sample_results,
974990
pm.set_data({"offsets": original_offsets, "y_obs": np.zeros((10, 4))})
975991
pm.sample_posterior_predictive(samples)
976992
if kind == "MultiTrace":
977-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
993+
assert caplog.record_tuples == [
994+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
995+
]
978996
caplog.clear()
979997
elif kind == "InferenceData":
980-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, sigma, y]")]
998+
assert caplog.record_tuples == [
999+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, sigma, y]")
1000+
]
9811001
caplog.clear()
9821002
elif kind == "Dataset":
983-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
1003+
assert caplog.record_tuples == [
1004+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
1005+
]
9841006
caplog.clear()
9851007

9861008
with model:
@@ -990,13 +1012,19 @@ def test_logging_sampled_basic_rvs_posterior_mutable(self, mock_sample_results,
9901012
pm.set_data({"offsets": original_offsets + 1, "y_obs": np.zeros((10, 3))})
9911013
pm.sample_posterior_predictive(samples)
9921014
if kind == "MultiTrace":
993-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
1015+
assert caplog.record_tuples == [
1016+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
1017+
]
9941018
caplog.clear()
9951019
elif kind == "InferenceData":
996-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
1020+
assert caplog.record_tuples == [
1021+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
1022+
]
9971023
caplog.clear()
9981024
elif kind == "Dataset":
999-
assert caplog.record_tuples == [("pymc", logging.INFO, "Sampling: [a, b, sigma, y]")]
1025+
assert caplog.record_tuples == [
1026+
("pymc.sampling.forward", logging.INFO, "Sampling: [a, b, sigma, y]")
1027+
]
10001028
caplog.clear()
10011029

10021030

0 commit comments

Comments
 (0)