Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8b6db4d
Documentation
raymondEhlers Jan 7, 2025
3ab0f2b
Add pre-commit
raymondEhlers Oct 8, 2025
ceab031
Update pre-commit versions
raymondEhlers Oct 8, 2025
ee50545
Switch to uv.lock, update pyproject
raymondEhlers Oct 8, 2025
b64f5da
Probably don't need TF right now...
raymondEhlers Oct 8, 2025
747bdec
Add ipython to aid development
raymondEhlers Oct 9, 2025
62bb47b
Begin refactoring MC sampling
raymondEhlers Oct 14, 2025
b282a40
Minor typos, linting
raymondEhlers Oct 14, 2025
fd6f869
Updated ruff conventions
raymondEhlers Oct 14, 2025
972c48e
Rename for clarity
raymondEhlers Oct 20, 2025
a943d1b
Centralize analysis config
raymondEhlers Oct 21, 2025
591d4f0
Fix linting issues
raymondEhlers Oct 21, 2025
665f25a
Linting fixes and formatting
raymondEhlers Oct 21, 2025
a874489
Add support for singular emulator IO
raymondEhlers Oct 21, 2025
909a917
Use more consistent naming
raymondEhlers Oct 21, 2025
c43ee0f
Process on improving emulator implementation
raymondEhlers Oct 21, 2025
dfdb454
Further splitting up functionality
raymondEhlers Oct 21, 2025
84bdf25
Continue updating - may have a complete example
raymondEhlers Oct 22, 2025
9140b9f
Fixes for providing analysis name
raymondEhlers Oct 22, 2025
3d26891
Attempt to use "settings" label more consistently
raymondEhlers Oct 22, 2025
41cba23
Minor cleanup
raymondEhlers Oct 22, 2025
a6950b7
Documentation
raymondEhlers Oct 22, 2025
37c9293
Move unexplained cov to sk_learn - it's more specific
raymondEhlers Nov 18, 2025
b66d31b
Further progress on emulator interface
raymondEhlers Nov 22, 2025
3b9ad9d
Rest of cleanup for emulation interface, implementation
raymondEhlers Nov 22, 2025
b37754c
Improved docs and interface for emulation
raymondEhlers Nov 22, 2025
703d3e4
Update pre-commit
raymondEhlers Nov 22, 2025
eb7cd6b
Selectively ignore module docstring formatting properly
raymondEhlers Nov 22, 2025
eca2070
Use new emulator interface in other modules
raymondEhlers Dec 2, 2025
092b593
Specify the emulator in the config
raymondEhlers Dec 2, 2025
cde56ff
Add note about IO
raymondEhlers Dec 2, 2025
4ab8a97
Cleanup author docs
raymondEhlers Dec 2, 2025
1a16c2a
Minor project / unicode cleanup
raymondEhlers Dec 2, 2025
40d406c
Linting, cleanup, formatting
raymondEhlers Dec 2, 2025
0a4bf98
Linting
raymondEhlers Dec 2, 2025
d860b53
Linting, formatting
raymondEhlers Dec 2, 2025
3cf2988
Match code conventions from other parts of codebase
raymondEhlers Dec 2, 2025
f9a5ed6
Minor cleanup
raymondEhlers Dec 2, 2025
cc4ae0f
Formatting
raymondEhlers Dec 2, 2025
584c9bb
Small cleanup for steering, restore logging
raymondEhlers Dec 15, 2025
e44009a
Fix emulation import
raymondEhlers Dec 15, 2025
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
.pdm-python
__pycache__/

# JS (pre-commit)
node_modules/

# VScode
*.code-workspace
.vscode/

# Data
data/
output/


92 changes: 92 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
# Useful to determine which files are included/excluded, tests of pre-commit, etc.
# Don't enable by default because it seems noisy. But I'll keep it around because
# it can be quite useful for debugging
# See: https://github.com/pre-commit/pre-commit/issues/1173#issuecomment-542341362
#- repo: meta
# hooks:
# - id: identity
# name: identity (all)

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.20.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v6.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: ".patch"
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace
exclude: ".patch"

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: ["--prose-wrap=preserve", "--print-width=120"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.14.6"
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: "v2.4.1"
hooks:
- id: codespell
additional_dependencies: [tomli]
# While it would be nice to have spell checking there, it doesn't handle the encoding of the output properly.
exclude: .ipynb

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.11.0.1"
hooks:
- id: shellcheck

- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.24.1"
hooks:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.35.0"
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs
1 change: 1 addition & 0 deletions config/rehlers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ parameters:
#-------------------------------------------
# Emulator parameters
emulator_parameters: &default_emulator_parameters
emulator_package: "sk_learn"

force_retrain: False
n_pc: 10
Expand Down
2,815 changes: 0 additions & 2,815 deletions pdm.lock

This file was deleted.

25 changes: 16 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ build-backend = "pdm.pep517.api"
name = "jetscape-bayesian"
description = "Analysis pipeline to implement Bayesian inference in high-energy physics "
license = {text = "BSD-3-Clause"}
# NOTE: <3.13 cap needed for tensorflow-io-gcs-filesystem
requires-python = ">=3.10,<3.13"
requires-python = ">=3.10"
authors = [
{ name = "Raymond Ehlers", email = "raymond.ehlers@cern.ch" },
{ name = "Luna (Yi) Chen", email = "chen.yi.first@gmail.com" },
{ name = "Christal Martin", email = "cbaillar@vols.utk.edu" },
{ name = "Cameron Parker", email = "cameron.parker@tamu.edu" },
]
# For hatch, need to remove the dependencies references here
dynamic = ["dependencies", "optional-dependencies", "version"]
dynamic = ["version"]
dependencies = [
# Data analysis and plotting
"matplotlib >=3.5.2",
Expand All @@ -29,7 +27,7 @@ dependencies = [
"seaborn >=0.11.2",
"silx >=1.0.0",
# Emulator training
"gpflow >=2.5.2",
# "gpflow >=2.5.2",
"pymc >=4.0.0",
"scikit-learn >=1.1.1",
"emcee>=3.1.4",
Expand All @@ -39,14 +37,19 @@ dependencies = [
]

[project.optional-dependencies]
test = [
"pytest >=6.2.4",
"pytest-cov >=3",
"pytest-sugar >=0.9.5",
]
dev = [
"ruff >=0.0.209",
"black >=22.1.0",
"mypy>=1.13.0",
"ipython >=8.0",
"ipykernel >=6.15.1",
"pytest >=7.4.0",
"pocoMC >=1.2.2",
"ipython>=8.37.0",
]

[tool.hatch]
Expand Down Expand Up @@ -94,6 +97,8 @@ exclude = [
'dist',
]
line-length = 120

[tool.ruff.lint]
select = [
"E", "F", "W", # flake8
"C901", # mccabe
Expand Down Expand Up @@ -131,15 +136,17 @@ unfixable = [
"T20", # flake8-print
"F841", # Removes unused variables
]
# Allow for characters that could be confused (per ruff)
allowed-confusables = ["σ", "ρ", "×"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 12

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = []

[tool.pylint]
master.py-version = "3.9"
master.py-version = "3.10"
master.ignore-paths= []
reports.output-format = "colorized"
similarities.ignore-imports = "yes"
Expand Down
76 changes: 76 additions & 0 deletions src/bayesian/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Primary analysis parameters.

.. codeauthor:: Raymond Ehlers <raymond.ehlers@cern.ch>, LBL/UCB
"""

from __future__ import annotations

import logging
from pathlib import Path
from typing import Any

import attrs
import yaml

logger = logging.getLogger(__name__)


@attrs.define
class AnalysisIO:
observables_table_dir: Path | str = attrs.field(converter=Path)
observables_config_dir: Path | str = attrs.field(converter=Path)
observables_filename: str = attrs.field()
_output_dir: Path = attrs.field()

@classmethod
def from_config(cls, config: dict[str, Any]) -> AnalysisIO:
return cls(
observables_table_dir=config["observable_table_dir"],
observables_config_dir=config["observable_config_dir"],
observables_filename=config["observables_filename"],
output_dir=config["output_dir"],
)

@classmethod
def from_config_file(cls, config_file: str | Path) -> AnalysisIO:
with Path(config_file).open() as stream:
config = yaml.safe_load(stream)

return cls.from_config(config=config)

def output_dir(self, analysis_config: AnalysisSettings) -> Path:
return self._output_dir / f"{analysis_config.name}_{analysis_config.parameterization}"


@attrs.define
class AnalysisSettings:
name: str
parameterization: str
config_file: Path = attrs.field(converter=Path)
io: AnalysisIO
raw_analysis_config: dict[str, Any] = attrs.field(factory=dict)

@classmethod
def from_config(cls, analysis_name: str, config_file: Path, config: dict[str, Any]) -> AnalysisSettings:
"""
Initialize the analysis configuration from a config file.
"""
raw_analysis_config = config["analyses"][analysis_name]
return cls(
name=analysis_name,
parameterization=raw_analysis_config["parameterization"],
config_file=config_file,
io=AnalysisIO.from_config(config=config),
raw_analysis_config=raw_analysis_config,
)

@classmethod
def from_config_file(cls, analysis_name: str, config_file: str | Path) -> AnalysisSettings:
with Path(config_file).open() as stream:
config = yaml.safe_load(stream)

return cls.from_config(analysis_name=analysis_name, config_file=Path(config_file), config=config)

@property
def output_dir(self) -> Path:
return self.io.output_dir(self)
Loading