mocaco 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mocaco-0.1.0/.github/workflows/ci.yml +41 -0
- mocaco-0.1.0/.github/workflows/publish.yml +75 -0
- mocaco-0.1.0/.gitignore +10 -0
- mocaco-0.1.0/AGENTS.md +11 -0
- mocaco-0.1.0/CHANGELOG.md +36 -0
- mocaco-0.1.0/CONTRIBUTING.md +104 -0
- mocaco-0.1.0/LICENSE +165 -0
- mocaco-0.1.0/PKG-INFO +105 -0
- mocaco-0.1.0/README.md +87 -0
- mocaco-0.1.0/assets/Logo_v1.png +0 -0
- mocaco-0.1.0/docs/constitution.md +145 -0
- mocaco-0.1.0/docs/index.md +5 -0
- mocaco-0.1.0/docs/methods/clt_absolute.md +45 -0
- mocaco-0.1.0/examples/triangular_example.py +46 -0
- mocaco-0.1.0/local/flatten_code.py +97 -0
- mocaco-0.1.0/local/mocaco_all.txt +1022 -0
- mocaco-0.1.0/local/mocaco_clean.txt +912 -0
- mocaco-0.1.0/mkdocs.yml +32 -0
- mocaco-0.1.0/pyproject.toml +87 -0
- mocaco-0.1.0/scripts/generate_docs.py +114 -0
- mocaco-0.1.0/scripts/generate_stubs.py +99 -0
- mocaco-0.1.0/site/404.html +455 -0
- mocaco-0.1.0/site/assets/images/favicon.png +0 -0
- mocaco-0.1.0/site/assets/javascripts/bundle.d7400e89.min.js +16 -0
- mocaco-0.1.0/site/assets/javascripts/bundle.d7400e89.min.js.map +7 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ar.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.da.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.de.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.du.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.el.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.es.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.fi.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.fr.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.he.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.hi.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.hu.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.hy.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.it.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ja.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.jp.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.kn.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ko.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.multi.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.nl.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.no.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.pt.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ro.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ru.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.sa.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.stemmer.support.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.sv.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.ta.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.te.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.th.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.tr.min.js +18 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.vi.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/min/lunr.zh.min.js +1 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/tinyseg.js +206 -0
- mocaco-0.1.0/site/assets/javascripts/lunr/wordcut.js +6708 -0
- mocaco-0.1.0/site/assets/javascripts/workers/search.2c215733.min.js +42 -0
- mocaco-0.1.0/site/assets/javascripts/workers/search.2c215733.min.js.map +7 -0
- mocaco-0.1.0/site/assets/stylesheets/main.ec1eaa64.min.css +1 -0
- mocaco-0.1.0/site/assets/stylesheets/main.ec1eaa64.min.css.map +1 -0
- mocaco-0.1.0/site/assets/stylesheets/palette.ab4e12ef.min.css +1 -0
- mocaco-0.1.0/site/assets/stylesheets/palette.ab4e12ef.min.css.map +1 -0
- mocaco-0.1.0/site/constitution/index.html +913 -0
- mocaco-0.1.0/site/index.html +497 -0
- mocaco-0.1.0/site/methods/clt_absolute/index.html +735 -0
- mocaco-0.1.0/site/search/search_index.json +1 -0
- mocaco-0.1.0/site/sitemap.xml +3 -0
- mocaco-0.1.0/site/sitemap.xml.gz +0 -0
- mocaco-0.1.0/spec/main_spec.md +197 -0
- mocaco-0.1.0/spec/roadmap.md +25 -0
- mocaco-0.1.0/spec/tests_spec.md +266 -0
- mocaco-0.1.0/src/mocaco/__init__.py +10 -0
- mocaco-0.1.0/src/mocaco/api.py +109 -0
- mocaco-0.1.0/src/mocaco/api.pyi +40 -0
- mocaco-0.1.0/src/mocaco/methods/__init__.py +7 -0
- mocaco-0.1.0/src/mocaco/methods/clt_absolute.py +133 -0
- mocaco-0.1.0/src/mocaco/protocols.py +104 -0
- mocaco-0.1.0/src/mocaco/registry.py +126 -0
- mocaco-0.1.0/src/mocaco/result.py +222 -0
- mocaco-0.1.0/src/mocaco/wrappers.py +170 -0
- mocaco-0.1.0/tests/conftest.py +62 -0
- mocaco-0.1.0/tests/methods/test_clt_absolute.py +200 -0
- mocaco-0.1.0/tests/test_api.py +130 -0
- mocaco-0.1.0/tests/test_integration.py +67 -0
- mocaco-0.1.0/tests/test_protocols.py +103 -0
- mocaco-0.1.0/tests/test_registry.py +185 -0
- mocaco-0.1.0/tests/test_result.py +344 -0
- mocaco-0.1.0/tests/test_wrappers.py +182 -0
- mocaco-0.1.0/uv.lock +1880 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout repository
|
|
19
|
+
uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: uv sync --all-extras --dev
|
|
33
|
+
|
|
34
|
+
- name: Run code formatting & linter check (Ruff)
|
|
35
|
+
run: uv run ruff check .
|
|
36
|
+
|
|
37
|
+
- name: Run type check (mypy)
|
|
38
|
+
run: uv run mypy src/
|
|
39
|
+
|
|
40
|
+
- name: Run tests (pytest)
|
|
41
|
+
run: uv run pytest
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*" # Triggers only when you push a tag like v0.1.0
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
name: Build distribution 📦
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout source
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v3
|
|
18
|
+
with:
|
|
19
|
+
enable-cache: true
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.12"
|
|
25
|
+
|
|
26
|
+
- name: Build sdist and wheel
|
|
27
|
+
run: uv build
|
|
28
|
+
|
|
29
|
+
- name: Store the distribution packages
|
|
30
|
+
uses: actions/upload-artifact@v4
|
|
31
|
+
with:
|
|
32
|
+
name: python-package-distributions
|
|
33
|
+
path: dist/
|
|
34
|
+
|
|
35
|
+
publish-to-testpypi:
|
|
36
|
+
name: Publish to TestPyPI 🧪
|
|
37
|
+
needs: build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: testpypi
|
|
41
|
+
url: https://test.pypi.org/p/mocaco
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
44
|
+
contents: read
|
|
45
|
+
steps:
|
|
46
|
+
- name: Download all the dists
|
|
47
|
+
uses: actions/download-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: python-package-distributions
|
|
50
|
+
path: dist/
|
|
51
|
+
|
|
52
|
+
- name: Publish to TestPyPI
|
|
53
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
54
|
+
with:
|
|
55
|
+
repository-url: https://test.pypi.org/legacy/
|
|
56
|
+
|
|
57
|
+
publish-to-pypi:
|
|
58
|
+
name: Publish to PyPI 🚀
|
|
59
|
+
needs: publish-to-testpypi # Waits for TestPyPI to succeed first
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
environment:
|
|
62
|
+
name: pypi
|
|
63
|
+
url: https://pypi.org/p/mocaco
|
|
64
|
+
permissions:
|
|
65
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
66
|
+
contents: read
|
|
67
|
+
steps:
|
|
68
|
+
- name: Download all the dists
|
|
69
|
+
uses: actions/download-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: python-package-distributions
|
|
72
|
+
path: dist/
|
|
73
|
+
|
|
74
|
+
- name: Publish to PyPI
|
|
75
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
mocaco-0.1.0/.gitignore
ADDED
mocaco-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Role
|
|
2
|
+
|
|
3
|
+
You are an expert python agent aligned with the developer rules of this repository:
|
|
4
|
+
|
|
5
|
+
1. Read always the contitution.md and the main_spec.md before any modification.
|
|
6
|
+
2. If user mention a task, they are in roadmap.md Only user modify this file. Do not add new points.
|
|
7
|
+
3. Do not commit your modifications. User must review the changes, accept them and commit them. Commit only if user request it explicitly and clearly
|
|
8
|
+
4. Ask any clarification before doing changes if the user do not provide enough instructions.
|
|
9
|
+
5. Despite test are part of the constitution, add them only under user requests
|
|
10
|
+
6. Do not modify the pyproject.toml file except if user request it explicitly.
|
|
11
|
+
7. Run `uv run ruff check --fix . && uv run ruff format .` to verify "All checks passed!" AND `uv run mypy src/` to verify "Sucess: no issues found in..." after each modification.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the mocaco project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## Unreleased
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Version bump from `0.1.0` to `1.0.0` in `pyproject.toml`.
|
|
12
|
+
- Updated `docs/index.md` with onboarding contribution section.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- (none for 1.0.0 initial release)
|
|
16
|
+
|
|
17
|
+
### Deprecated
|
|
18
|
+
- (none for 1.0.0 initial release)
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- (none for 1.0.0 initial release)
|
|
22
|
+
|
|
23
|
+
## 0.1.0 — 2026-01-01
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- Initial library structure: `src/mocaco/`, `docs/`, `tests/`, `scripts/`
|
|
27
|
+
- Core convergence criterion: `clt_absolute` — Central Limit Theorem based convergence criterion using an absolute Monte Carlo error threshold
|
|
28
|
+
- Registry auto-discovery pattern — `pkgutil` auto-imports all modules in `src/mocaco/methods/`
|
|
29
|
+
- `ConvergenceResult` abstraction with common fields: `method`, `n`, `estimate`, `error`, `is_converged`, `diagnostics`, `data`
|
|
30
|
+
- Public API: `mcc.samples(df, it_col, target_col)`, `mcc.convergence(samples, method="...")`, `mcc.convergence.clt_absolute(samples, ...)`, `mcc.methods()`, `mcc.describe("name")`
|
|
31
|
+
- Documentation: `constitution.md`, `roadmap.md`, `main_spec.md`, `docs/index.md`, `docs/methods/clt_absolute.md`
|
|
32
|
+
- Test suite foundation: `tests/` with tests for API, registry, protocols, wrappers, results, integration, and methods
|
|
33
|
+
- Project configuration: `pyproject.toml`, `AGENTS.md`, `LICENSE`, `README.md`, `uv.lock`, `.gitignore`
|
|
34
|
+
- Build system: hatchling-based wheel build
|
|
35
|
+
- `# 8. CONTRIBUTING.md Guidelines for external developers registering new convergence criteria.` — New contributing guidelines document at repository root, covering the philosophy of adding only one Python file to register a new convergence criterion, the required file structure (imports, pydantic `params_type`, `@registry.register()` decorator, `run` method), formatting and code quality (ruff, mypy, GitHub Actions), auto-generated documentation, and optional but recommended testing.
|
|
36
|
+
- `# 9. CHANGELOG.md Project Files` — Changelog file created for release notes, following Keep a Changelog format.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Contributing to mocaco
|
|
2
|
+
|
|
3
|
+
## Philosophy
|
|
4
|
+
|
|
5
|
+
mocaco is an extensible library for convergence analysis of Monte Carlo simulations. It is designed to be easy to use by both users and developers (non-python expert friendly). Adding a new convergence criterion requires **only one Python file** — no changes to the public API, registry, or documentation are needed manually. The project uses an auto-discovery mechanism that process all modules from `src/mocaco/methods/`, so a new criterion is immediately integrated in the library after its module is created.
|
|
6
|
+
|
|
7
|
+
Friendly remainder: The maintainer (me) is not (yet) a python expert and likely the library can be improved in many ways. If you are a real expert and you desire to pull changes across the libary itself I will be very happy.
|
|
8
|
+
|
|
9
|
+
## Keep in mind
|
|
10
|
+
|
|
11
|
+
Each convergence criterion lives as a single module in `src/mocaco/methods/`. The main aspect to remember is that the method will recive a formated polar DataFrame and will return an structured results, including another polar DataFrame. The imput and output data is also explained on this guide as well as the method file structure (see clt_absolute.py method to see an example).
|
|
12
|
+
|
|
13
|
+
### Input data
|
|
14
|
+
|
|
15
|
+
The file `src/mocaco/protocols.py` defines the class `SampleFrame` which make sure the input data is standarized. It defines which columns must be used by the method, which will be available for the method. Actually the defined columns names are:
|
|
16
|
+
|
|
17
|
+
- `df` (pl.DataFrame) Source Polars DataFrame.
|
|
18
|
+
- `it_col` (str) Column containing the iteration/order of the samples.
|
|
19
|
+
- `target_col` (str) Column containing the quantity to analyze.
|
|
20
|
+
|
|
21
|
+
The file `src/mocaco/protocols.py` also defines the structure of the method, and particularly the run method, which includes:
|
|
22
|
+
|
|
23
|
+
- `samples` (`SampleFrame`) The structured input
|
|
24
|
+
- `params` The method parameters.
|
|
25
|
+
|
|
26
|
+
This structure is which allow automatic method discovery and documentation among others. Here data columns are used as `samples.target_col` or `samples.it_col`, while method parameters are used as `params.confidence_level`, for example.
|
|
27
|
+
|
|
28
|
+
### Output data
|
|
29
|
+
|
|
30
|
+
The file `src/mocaco/result.py` defines the class `ConvergenceResult`, which contains all the results a method must or can return. See it or see the module clt_absolute.py as a reference. This ensures all methos can be used by the library and be easyly plotted.
|
|
31
|
+
|
|
32
|
+
## Method structure
|
|
33
|
+
|
|
34
|
+
Said this, the detailed structure for a new method is as follows:
|
|
35
|
+
|
|
36
|
+
### 1. Imports and setup
|
|
37
|
+
|
|
38
|
+
One-line module string description and mandatory basic modules and imports from `mocaco`. Typically includes `polars`, `pydantic`, `scipy.stats`, the `registry`, and `ConvergenceResult`.
|
|
39
|
+
|
|
40
|
+
### 2. Parameter specification (`params_type`)
|
|
41
|
+
|
|
42
|
+
A **pydantic `BaseModel`** defines the criterion's input parameters. This is the single source of truth for validation and documentation. Each field must provide:
|
|
43
|
+
|
|
44
|
+
- Type information
|
|
45
|
+
- Default values if apply
|
|
46
|
+
- Validation constraints (e.g., `gt`, `lt`)
|
|
47
|
+
- Human-readable descriptions
|
|
48
|
+
|
|
49
|
+
Using pydantic ensures automatic validation, consistent API docs, and generated parameter documentation.
|
|
50
|
+
|
|
51
|
+
### 3. Criterion class (decorated with `@registry.register()`)
|
|
52
|
+
|
|
53
|
+
The main class must:
|
|
54
|
+
|
|
55
|
+
- Assign a stable, concise, lowercase, descriptive `name` (e.g., `"clt_absolute"`)
|
|
56
|
+
- Set `params_type` to the parameter model
|
|
57
|
+
- Optionally set `supports_eval_frequency`
|
|
58
|
+
- Provide documentation sections: `description`, `assumptions`, `limitations`, `result_interpretation`, `example_usage`, `references`
|
|
59
|
+
- Implement a `run(samples, params)` method that returns a `ConvergenceResult`
|
|
60
|
+
|
|
61
|
+
The `@registry.register()` decorator handles automatic registration — no manual API updates are needed.
|
|
62
|
+
|
|
63
|
+
### 4. Execution logic (`run` method)
|
|
64
|
+
|
|
65
|
+
The core convergence computation. Takes a `SampleFrame` and validated `params`, returns a `ConvergenceResult` with the common fields: `method`, `n`, `estimate`, `error`, `is_converged`, `diagnostics`, `data`, among others.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Formatting and code quality
|
|
70
|
+
|
|
71
|
+
Once a method is created whit the desired structure:
|
|
72
|
+
|
|
73
|
+
- Run `uv run ruff check --fix . && uv run ruff format .` to ensure Ruff formatting and linting standards.
|
|
74
|
+
- Run `uv run mypy src/` for type checking — all convergence methods must be compatible with the project's strict mypy configuration.
|
|
75
|
+
- GitHub Actions CI runs on every pull request across Python 3.12, 3.13, and 3.14, including ruff, mypy, and pytest.
|
|
76
|
+
|
|
77
|
+
## Documentation
|
|
78
|
+
|
|
79
|
+
Documentation is **automatically generated** from the method's parameter specification and class attributes. This is why the following parameters are **mandatory** on every method:
|
|
80
|
+
|
|
81
|
+
- `params_type` — pydantic BaseModel; its fields are the single source of truth for validation and docs
|
|
82
|
+
- `name` — stable identifier, used in API endpoints and documentation
|
|
83
|
+
- `assumptions` — explicitly documented statistical assumptions (i.i.d., finite variance, CLT applicability, etc.)
|
|
84
|
+
- `limitations` — what the criterion does not guarantee
|
|
85
|
+
- `result_interpretation` — explanation of each `ConvergenceResult` field
|
|
86
|
+
- `example_usage` — minimal working example
|
|
87
|
+
- `references` — academic citations where applicable
|
|
88
|
+
|
|
89
|
+
The `docs/index.md` and method docs in `docs/methods/` are regenerated by running `uv run python scripts/generate_docs.py`.
|
|
90
|
+
|
|
91
|
+
## Testing
|
|
92
|
+
|
|
93
|
+
Tests are **optional but highly recommended**. A new criterion should include tests covering:
|
|
94
|
+
|
|
95
|
+
- Valid inputs
|
|
96
|
+
- Invalid parameters
|
|
97
|
+
- Edge cases
|
|
98
|
+
- Expected convergence behavior
|
|
99
|
+
- Expected non-convergence behavior
|
|
100
|
+
- Result structure
|
|
101
|
+
|
|
102
|
+
If tests are not provided, the maintainer will likely contact the contributor to clarify doubts and add the required test coverage before merging.
|
|
103
|
+
|
|
104
|
+
---
|
mocaco-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
mocaco-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mocaco
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convergence analysis for Monte Carlo series — works with Polars DataFrames
|
|
5
|
+
Author-email: Álvaro Esteban Muñoz <em.alvaro.l@gmail.com>
|
|
6
|
+
License: LGPL-3.0-or-later
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: matplotlib>=3.11.2
|
|
10
|
+
Requires-Dist: numpy>=2.5.3
|
|
11
|
+
Requires-Dist: pandas>=3.0.6
|
|
12
|
+
Requires-Dist: polars>=1.44.2
|
|
13
|
+
Requires-Dist: pyarrow>=25.0.1
|
|
14
|
+
Requires-Dist: pydantic>=2.13.5
|
|
15
|
+
Requires-Dist: rich>=15.0.0
|
|
16
|
+
Requires-Dist: scipy>=1.18.1
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# mocaco
|
|
20
|
+
|
|
21
|
+
[](https://github.com/emalvarol/mocaco/actions/workflows/ci.yml)
|
|
22
|
+

|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
Convergence analysis for Monte Carlo series using Polars DataFrames.
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<img src="assets/Logo_v1.png" alt="mocaco logo" width="400"/>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
The library provides a simple API for applying different convergence and
|
|
32
|
+
stopping criteria to Monte Carlo simulation results.
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import polars as pl
|
|
38
|
+
import mocaco as mcc
|
|
39
|
+
|
|
40
|
+
# Prepare your Monte Carlo samples
|
|
41
|
+
df = pl.DataFrame({"it": range(1000), "value": your_samples})
|
|
42
|
+
|
|
43
|
+
# Create a normalized sample frame
|
|
44
|
+
samples = mcc.samples(df, it_col="it", target_col="value")
|
|
45
|
+
|
|
46
|
+
# Run a convergence criterion
|
|
47
|
+
result = mcc.convergence.clt_absolute(samples, threshold=0.01)
|
|
48
|
+
|
|
49
|
+
# Inspect results
|
|
50
|
+
print(result.is_converged) # True/False
|
|
51
|
+
print(result.estimate) # Final cumulative mean
|
|
52
|
+
print(result.error) # Final CLT-based absolute error
|
|
53
|
+
print(result.n) # Number of samples
|
|
54
|
+
# and more...
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API Overview
|
|
58
|
+
|
|
59
|
+
| Function | Description |
|
|
60
|
+
|----------|-------------|
|
|
61
|
+
| `mcc.samples(df, it_col, target_col)` | Create a normalized sample frame from a Polars DataFrame |
|
|
62
|
+
| `mcc.convergence(samples, method="...")` | Generic invocation of any registered criterion |
|
|
63
|
+
| `mcc.convergence.clt_absolute(samples, ...)` | Typed invocation of a specific criterion |
|
|
64
|
+
| `mcc.methods()` | List all registered convergence criteria |
|
|
65
|
+
| `mcc.describe("clt_absolute")` | Get metadata and parameter info for a criterion |
|
|
66
|
+
|
|
67
|
+
## Available Methods
|
|
68
|
+
|
|
69
|
+
- [`clt_absolute`](docs/methods/clt_absolute.md) — CLT-based absolute error threshold
|
|
70
|
+
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
73
|
+
Full documentation is available in the `docs/` directory or can be built with:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
mkdocs serve
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Installation (Developers)
|
|
80
|
+
|
|
81
|
+
### Environment
|
|
82
|
+
|
|
83
|
+
Create the virtual environment and install the project in editable mode with `uv`:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv venv
|
|
87
|
+
uv sync
|
|
88
|
+
uv pip install -e .
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If it is needed to remove an old environment:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
Remove-Item -Recurse -Force .venv
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### ruff
|
|
98
|
+
```bash
|
|
99
|
+
uv run ruff check --fix . && uv run ruff format .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### mypy
|
|
103
|
+
```bash
|
|
104
|
+
uv run mypy src/
|
|
105
|
+
```
|
mocaco-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# mocaco
|
|
2
|
+
|
|
3
|
+
[](https://github.com/emalvarol/mocaco/actions/workflows/ci.yml)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Convergence analysis for Monte Carlo series using Polars DataFrames.
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="assets/Logo_v1.png" alt="mocaco logo" width="400"/>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
The library provides a simple API for applying different convergence and
|
|
14
|
+
stopping criteria to Monte Carlo simulation results.
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import polars as pl
|
|
20
|
+
import mocaco as mcc
|
|
21
|
+
|
|
22
|
+
# Prepare your Monte Carlo samples
|
|
23
|
+
df = pl.DataFrame({"it": range(1000), "value": your_samples})
|
|
24
|
+
|
|
25
|
+
# Create a normalized sample frame
|
|
26
|
+
samples = mcc.samples(df, it_col="it", target_col="value")
|
|
27
|
+
|
|
28
|
+
# Run a convergence criterion
|
|
29
|
+
result = mcc.convergence.clt_absolute(samples, threshold=0.01)
|
|
30
|
+
|
|
31
|
+
# Inspect results
|
|
32
|
+
print(result.is_converged) # True/False
|
|
33
|
+
print(result.estimate) # Final cumulative mean
|
|
34
|
+
print(result.error) # Final CLT-based absolute error
|
|
35
|
+
print(result.n) # Number of samples
|
|
36
|
+
# and more...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API Overview
|
|
40
|
+
|
|
41
|
+
| Function | Description |
|
|
42
|
+
|----------|-------------|
|
|
43
|
+
| `mcc.samples(df, it_col, target_col)` | Create a normalized sample frame from a Polars DataFrame |
|
|
44
|
+
| `mcc.convergence(samples, method="...")` | Generic invocation of any registered criterion |
|
|
45
|
+
| `mcc.convergence.clt_absolute(samples, ...)` | Typed invocation of a specific criterion |
|
|
46
|
+
| `mcc.methods()` | List all registered convergence criteria |
|
|
47
|
+
| `mcc.describe("clt_absolute")` | Get metadata and parameter info for a criterion |
|
|
48
|
+
|
|
49
|
+
## Available Methods
|
|
50
|
+
|
|
51
|
+
- [`clt_absolute`](docs/methods/clt_absolute.md) — CLT-based absolute error threshold
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
Full documentation is available in the `docs/` directory or can be built with:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
mkdocs serve
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Installation (Developers)
|
|
62
|
+
|
|
63
|
+
### Environment
|
|
64
|
+
|
|
65
|
+
Create the virtual environment and install the project in editable mode with `uv`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv venv
|
|
69
|
+
uv sync
|
|
70
|
+
uv pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If it is needed to remove an old environment:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
Remove-Item -Recurse -Force .venv
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ruff
|
|
80
|
+
```bash
|
|
81
|
+
uv run ruff check --fix . && uv run ruff format .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### mypy
|
|
85
|
+
```bash
|
|
86
|
+
uv run mypy src/
|
|
87
|
+
```
|
|
Binary file
|