orochi.base
Orochi Core: Unified Parameter Management
The orochi.base package forms the central body of the Orochi framework, providing a unified and robust system for parameter management, constraint enforcement, and cross-module interoperability. In Orochi’s architecture, calculation modules branch out as decentralized heads, while orochi.base acts as the common trunk that externalizes physical and instrumental variables.
Key Features
Centralized Parameter Control: All physical variables, boundaries, and active refinement flags are managed in a standardized dictionary format.
Hierarchical String-Address Namespace: Parameters across the entire framework are uniquely addressable via flat string paths (e.g., @phase_0/a/val, @pixia_0/beam_x/val), enabling external optimizers (SciPy, CMA-ES, Optuna) to manipulate multi-module parameters without glue code.
Automatic Change Detection & Caching: Methods decorated via DependencyMeta automatically track _changed_parameters and skip unneeded expensive computations when dependent parameters remain unchanged.
Execution Control: Provides both automated execution (__call__(force=False)) with dependency caching and explicit manual execution (run(force=True)) for full pipeline recalculation.
Symbolic Constraints & Symmetry: Integrates SymPy for symbolic mathematical relationships and binds space-group crystallographic constraints dynamically.
Diagnostic Introspection: Standardizes structured diagnostic reporting (.explain()) for autonomous AI agents and user feedback.
Parameter Management Specification
Parameters are internally stored as standardized dictionaries containing physical values and scientific metadata:
from orochi.base.core import OrochiBase
# Subclass or instantiate
obj = OrochiBase()
# 1. Direct dictionary value access
# Get and set primary value
obj["scale"] = 1.05
val = obj["scale"]
# 2. Accessing scientific attributes (bounds, active refinement toggle)
obj["scale", "min"] = 0.0
obj["scale", "max"] = 10.0
obj["scale", "fit"] = True # Participates in optimization
# 3. Flat string-addressing across registered instances
# Format: @<instance_id>/<parameter_key>/<attribute>
# e.g., @phase_0/a/val, @pixia_0/beam_x/val
Developer Guide: Creating an Orochi Module
Third-party developers and beamline scientists can create custom Orochi calculation modules by subclassing OrochiBase. Subclasses automatically inherit unified parameter storage, Gradio UI synthesis compatibility (param_boxes), dependency caching, and cross-module optimization interfaces.
What is a Custom Orochi Module?
A custom Orochi module does not need to be written completely from scratch. In fact, one of the primary design strengths of the Orochi architecture is wrapping existing, battle-tested scientific Python packages into standardized Orochi heads.
For example:
``orochi.fit``: Wraps LMFIT and Optuna, turning external numerical optimization and Bayesian sampling libraries into seamless Orochi components that directly inspect, bound, and refine parameters across multiple physical modules (such as orochi.pdfsim and orochi.phase).
``orochi.pixia``: Bridges 2D image processing libraries and detector integration algorithms into the Orochi pipeline.
By subclassing OrochiBase, existing libraries instantly acquire:
Unified Parameter Control: Parameters, search boundaries, and active refinement flags (fit, with backward-compatible alias optimize) are stored in standardized dictionaries accessible via flat string paths (e.g., @phase_0/a/val).
Dependency-Aware Caching: Expensive external calls or simulations are automatically skipped when inputs have not changed.
Pipeline & UI Interoperability: Automatic integration into multi-step execution graphs and automated Gradio web UI generation via param_boxes.
Example: Wrapping an External Library (The orochi.fit LMFIT Pattern)
Below is an illustrative example demonstrating how an external library (such as LMFIT) is wrapped into an Orochi module:
from orochi.base.core import OrochiBase
import lmfit
class CustomLmfitAdapter(OrochiBase):
"""Wraps LMFIT to optimize parameters across attached Orochi simulators."""
def __init__(self):
super().__init__()
# 1. Define optimizer hyperparameters
self["method"] = "leastsq"
self["max_nfev"] = 1000
self["ftol"] = 1e-5
self.simulators = []
def build_lmfit_params(self) -> lmfit.Parameters:
"""Translate Orochi parameters marked for optimization into lmfit Parameters."""
params = lmfit.Parameters()
for sim in self.simulators:
for key in sim.keys():
if sim.get((key, "fit"), False):
pname = f"{sim.id}_{key}"
val = sim[key]
pmin = sim.get((key, "min"), -float("inf"))
pmax = sim.get((key, "max"), float("inf"))
params.add(pname, value=val, min=pmin, max=pmax, vary=True)
return params
def objective(self, params: lmfit.Parameters, y_obs):
"""Objective function evaluated at each optimization iteration."""
# Update Orochi simulators with trial values
for sim in self.simulators:
for key in sim.keys():
pname = f"{sim.id}_{key}"
if pname in params:
sim[key] = params[pname].value
# Run simulator (benefits from Orochi's internal caching!)
sim()
y_calc = sum(sim.y for sim in self.simulators)
return y_obs - y_calc
def __call__(self, y_obs, force: bool = False):
"""Primary execution: run the wrapped external optimizer."""
if force:
self._state = "INIT"
lmfit_params = self.build_lmfit_params()
result = lmfit.minimize(self.objective, lmfit_params, args=(y_obs,), method=self["method"])
self.result = result
self._state = "DONE"
return result
def run(self, y_obs, force: bool = False):
"""Explicit execution entry point for manual scripts."""
return self.__call__(y_obs, force=force)
Standalone Custom Head Template (From Scratch)
For specialized physics models or custom data processing created from scratch, subclass OrochiBase and register method dependencies for selective caching:
from orochi.base.core import OrochiBase
class CustomScatteringHead(OrochiBase):
"""Custom Orochi calculation head."""
def __init__(self):
super().__init__()
# 1. Define module-specific parameters
self["wavelength"] = 0.18033
self["attenuation"] = 1.0
self["attenuation", "min"] = 0.0
self["attenuation", "max"] = 5.0
self["attenuation", "fit"] = True
# 2. Register method dependencies for automatic caching
# When self["wavelength"] changes, 'calc_geometry' will re-execute;
# otherwise it will be skipped during repeated calls.
self._method_dependencies["calc_geometry"] = {
"self": ["wavelength"]
}
def calc_geometry(self):
"""Heavy calculation step executed only when dependent parameters change."""
# Expensive calculation here...
pass
def calc_output(self):
"""Fast calculation step."""
pass
def __call__(self, force: bool = False):
"""Primary execution entry point."""
if force:
self._state = "INIT"
super().__call__(force=force)
self.calc_geometry()
self.calc_output()
self._state = "DONE"
def run(self, force: bool = False):
"""Explicit execution entry point for manual scripts."""
return self.__call__(force=force)
def explain(self) -> str:
"""Structured Markdown diagnostic report for AI agents and users."""
return f"### Custom Module Status\\n- State: {self._state}\\n- Wavelength: {self['wavelength']}"
Citation
If you use orochi.base in a scientific publication, please cite this package as:
S. Tominaka, Orochi: A Physics-Grounded Python Package for Pair Distribution Function Analysis of Crystalline and Low-Dimensional Materials, 2026. https://github.com/Tominaka-Laboratory/orochi.base
Installation
The preferred method is to install using pip:
pip install orochi.base
To confirm that the installation was successful, type:
python -c "import orochi.base; print('Orochi Base imported successfully')"
If you prefer to install from source:
git clone https://github.com/Tominaka-Laboratory/orochi.base.git
cd orochi.base
pip install -e .
Getting Started
You may consult our online documentation for tutorials and API references.
Support and Contribute
The orochi.base project welcomes your expertise and enthusiasm!
If you see a bug or want to request a feature, please report it as an issue and/or submit a fix as a PR.
Feel free to fork the project and contribute. To install orochi.base in a development mode, with its sources being directly used by Python rather than copied to a package directory, use the following in the root directory
pip install -e .
To ensure code quality and to prevent accidental commits into the default branch, please set up the use of our pre-commit hooks.
Improvements and fixes are always appreciated.
Before contributing, please read our Code of Conduct.
License
This project is licensed under the GNU General Public License v3.0 (GPLv3). See the LICENSE.rst file for details.
This copyleft license guarantees that Orochi remains freely accessible, open, and transparent to the entire scientific community, and that all derivative works must likewise remain open source.
Citation
If you use this package in academic research, please cite:
@article{tominaka2026orochi,
title = {Orochi: A Physics-Grounded Python Package for Pair Distribution Function Analysis of Crystalline and Low-Dimensional Materials},
author = {Tominaka, Satoshi},
year = {2026},
url = {https://github.com/Tominaka-Laboratory/orochi}
}
Contact
For more information on orochi.base please visit the project web-page or email Dr. Satoshi Tominaka at tominaka.satoshi@nims.go.jp.
Metadata
Release files for orochi.base 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| orochi_base-4.0.0.tar.gz | 34.7 kB | Without provenance | Details for orochi_base-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| orochi_base-4.0.0-py3-none-any.whl | Python 3 | none | any | Details for orochi_base-4.0.0-py3-none-any.whl |
Total release size: 65.0 kB
Release files / orochi_base-4.0.0.tar.gz
| Download URL | orochi_base-4.0.0.tar.gz |
|---|---|
| Size | 34.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
419ec1f277adfd2d6ca68998b9f97872af745bfdf8c53b8b4e54f6cb461d34db
|
|
BLAKE2b-256 checksum How to use checksums |
f80539235ff69c9c17cfa7f0ad8d2a9136b9a324754bd4e22c128549515a8040
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Release files / orochi_base-4.0.0-py3-none-any.whl
| Download URL | orochi_base-4.0.0-py3-none-any.whl |
|---|---|
| Size | 30.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2ed8fba11ecf69a9caf3ad9c1a93db4098d44a5371e43448e392d2005ac2eb2
|
|
BLAKE2b-256 checksum How to use checksums |
02055e0976ee221d661dedb2bbc53f0c355b3e7352da385def03f86fafa69f56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Security for orochi.base 4.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.