Metadata-Version: 2.5
Name: omnisim-engine
Version: 1.0.0
Summary: OmniSim: The Universal Counterfactual Simulation Engine - Beyond Probabilistic Text Generation to Action-Conditioned World Simulation
Project-URL: Homepage, https://github.com/Deeven-Seru/omnisim
Project-URL: Repository, https://github.com/Deeven-Seru/omnisim
Project-URL: Issues, https://github.com/Deeven-Seru/omnisim/issues
Project-URL: Documentation, https://github.com/Deeven-Seru/omnisim#readme
Author-email: Deeven Seru <deevenseru11@gmail.com>
License: MIT
Keywords: chaos-engineering,counterfactual-simulation,infrastructure-as-code,mcts,reliability-engineering,sre,terraform
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24.0
Provides-Extra: accelerated
Requires-Dist: torch>=2.2.0; extra == 'accelerated'
Provides-Extra: all
Requires-Dist: marimo>=0.8.0; extra == 'all'
Requires-Dist: matplotlib>=3.7.0; extra == 'all'
Requires-Dist: torch>=2.2.0; extra == 'all'
Provides-Extra: notebook
Requires-Dist: marimo>=0.8.0; extra == 'notebook'
Requires-Dist: matplotlib>=3.7.0; extra == 'notebook'
Description-Content-Type: text/markdown

<div align="center">

<img src="assets/omnisim-banner.svg" alt="OmniSim: The Universal Counterfactual Simulation Engine" width="100%" />

<br/><br/>

[![CI Pipeline](https://img.shields.io/badge/CI_PIPELINE-PASSING-D4AF37?style=for-the-badge&logo=githubactions&logoColor=D4AF37&labelColor=08080A)](https://github.com/Deeven-Seru/omnisim/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/LICENSE-MIT-D4AF37?style=for-the-badge&labelColor=08080A)](LICENSE)
[![Python: 3.10 | 3.11 | 3.12](https://img.shields.io/badge/PYTHON-3.10%20%7C%203.11%20%7C%203.12-D4AF37?style=for-the-badge&logo=python&logoColor=D4AF37&labelColor=08080A)](https://python.org)
[![Research Paper](https://img.shields.io/badge/RESEARCH_PAPER-PDF_AVAILABLE-D4AF37?style=for-the-badge&labelColor=08080A)](paper/omnisim_paper.pdf)
[![Architecture: SAC](https://img.shields.io/badge/ARCHITECTURE-SAC_WORLD_MODEL-D4AF37?style=for-the-badge&labelColor=08080A)](ARCHITECTURE.md)

<br/>

<p align="center">
  <b>Beyond Autoregressive Token Prediction to Action-Conditioned World Simulation.</b><br/>
  Simulate tens of thousands of counterfactual future timelines before modifying production state.
</p>

<img src="assets/omnisim_thumbnail.png" alt="OmniSim Counterfactual Manifold Simulation" width="100%" style="border-radius: 8px; border: 1px solid #2D2719;" />

</div>

---

## 1. Executive Thesis: Why Text Models Hit a Ceiling

In 2017, Google published *"Attention Is All You Need"*, treating it as a machine translation improvement. Scaling autoregressive transformers over internet tokens unlocked conversational fluency, culminating in ChatGPT.

**However, LLMs are advisory oracles, not execution engines.**

When asking an LLM:
* *"How should our distributed architecture scale under a 3x flash sale?"*
* *"If we raise our SaaS tier price by 15%, what happens to churn and runway?"*
* *"If our primary database connection pool nears saturation, what compound intervention guarantees zero outage?"*

An LLM emits **statistically plausible text**. It cannot simulate physical, logical, or financial invariants across time. Operating on text-only predictions forces engineers into blind production deployments and catastrophic cascading failures.

**OmniSim flips this paradigm.** Grounded in **Action-Conditioned World Models, Test-Time Training (TTT), and Counterfactual Search (MCTS)**, OmniSim is an enterprise-grade **State-Action-Consequence (SAC)** simulation engine. 

Instead of guessing tokens, OmniSim ingests production topology (Kubernetes, OpenTelemetry, Terraform IaC), models non-linear dynamics, branches thousands of counterfactual intervention trajectories forward across arbitrary horizons, and proves which actions survive critical operational invariants before you execute.

---

## 2. Core Architecture: The 3-Tier Simulation Engine

```
[ Current System State S_0 ] ──► [ Relational Entity Graph & Invariant Rules ]
                                                 │
                                                 ▼
                                   ┌───────────────────────────┐
                                   │ Tier 1: World Model       │
                                   │ S_{t+1} = f_θ(S_t, A_t)   │
                                   └─────────────┬─────────────┘
                                                 ▼
                                   ┌───────────────────────────┐
                                   │ Tier 2: Counterfactual    │
                                   │ Monte Carlo Tree Search   │
                                   └─────────────┬─────────────┘
                                                 ▼
                                   ┌───────────────────────────┐
                                   │ Tier 3: Invariant Audits  │
                                   │ & Deterministic Verifiers │
                                   └─────────────┬─────────────┘
                                                 ▼
                 [ Executive Consequence Report & Optimal Intervention Plan ]
```

1. **Universal State Representation (`omnisim.core.state`):**
   * Encapsulates entities, continuous metrics, dynamic topology graphs, and invariant rules (SLAs, connection pool ceilings, debt covenants).
2. **Action-Conditioned World Dynamics (`omnisim.models.dynamics`):**
   * Propagates non-linear cascades (M/M/1 queuing contention, memory pressure, price elasticity, supply chain bottlenecks).
   * Accelerated across **NVIDIA Blackwell/Hopper GPUs (CUDA)**, **Apple Silicon (MPS)**, and multi-core vectorized CPU SIMD.
3. **Counterfactual MCTS Planner (`omnisim.models.search`):**
   * Searches the combinatorial tree of candidate interventions.
   * Prunes timelines violating SLA invariants and isolates minimal-cost, Pareto-optimal operational decisions.
4. **Autonomous Ingestion Adapters (`omnisim.ingest`):**
   * Native parsers for **Terraform HCL/JSON**, **Kubernetes Pod/HPA manifests**, and live **OpenTelemetry OTLP** streams.

---

## 3. Installation & Distribution

OmniSim can be installed across multiple package managers and environments:

### via `pip` (Python 3.10+)

```bash
# Direct from PyPI
pip install omnisim-engine

# Or directly from the GitHub Release Wheel
pip install https://github.com/Deeven-Seru/omnisim/releases/download/v1.0.0/omnisim_engine-1.0.0-py3-none-any.whl

# Or from source
pip install git+https://github.com/Deeven-Seru/omnisim.git
```

### via `brew` (Homebrew on macOS / Linux)

```bash
brew install Deeven-Seru/omnisim/omnisim
```

### via Standalone `curl` Installer (No manual venv setup)

```bash
curl -sSL https://raw.githubusercontent.com/Deeven-Seru/omnisim/main/scripts/install.sh | bash
```

### via `Docker` Container

```bash
# Run simulation in an isolated container
docker run --rm -v $(pwd):/workspace ghcr.io/deeven-seru/omnisim:v1 simulate --domain systems
```

### via GitHub Action (CI/CD Safety Gate)

Drop OmniSim directly into any repository's `.github/workflows/` to block cascading outages before code merges:

```yaml
name: OmniSim Safety Gate
on: [pull_request]

jobs:
  pre-flight-audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: OmniSim Pre-Flight Safety Gate
        uses: Deeven-Seru/omnisim@v1
        with:
          path: terraform/
          fail-on-violation: "true"
```

### Launch OmniSim Cloud SaaS Portal & API Gateway

Launches the multi-tenant SaaS control plane with live organization quotas, GitHub PR pre-flight gatekeeper feed, and REST APIs:

```bash
python3 -m omnisim.server
# Open http://localhost:8088 in your browser
```

### Launch Interactive Timeline Visualizer

Spins up the low-level timeline visualizer with dynamic slider controls, branching counterfactual trees, and metric deltas:

```bash
python3 -m omnisim.visualizer
# Open http://localhost:8088/visualizer
```

### Run Terminal Counterfactual Simulation

```bash
# Cloud infrastructure resilience scenario
python3 -m omnisim.cli simulate --domain systems --horizon 6
```

### Pre-Flight Terraform IaC Fire Audit

Audit Terraform HCL plans before `terraform apply` to detect cascading capacity fires:

```bash
python3 -m omnisim.cli terraform
```

### High-Throughput Stochastic Rollout Benchmark

```bash
# Benchmark 500 parallel stochastic rollouts in < 150ms
python3 -m omnisim.cli benchmark --domain systems --rollouts 500 --horizon 6
```

### Autonomous Auto-Remediation Patch Engine

Audit infrastructure code and synthesize zero-downtime Git unified diff patches ready for direct application:

```bash
python3 -m omnisim.cli patch examples/vulnerable_infrastructure.tf
```

### OmniSim Cloud & Python Client SDK

OmniSim provides an enterprise Python client SDK and multi-tenant SaaS control plane with pre-flight GitHub PR webhooks:

```python
from omnisim.client import OmniSimClient

client = OmniSimClient(api_key="your_tenant_key")
audit = client.audit_pull_request(
    hcl_code=open("main.tf").read(),
    pr_number=42,
    commit_sha="a1b2c3d"
)

if not audit["passed"]:
    print(f"Violations detected: {audit['violations_count']}")
    # Apply autonomous remediation patch directly
    print(audit["remediation_patch"])
```

### Canonical Microservices Reference Benchmark

Run simulation across Google Cloud Online Boutique (11 services), Cornell DeathStarBench (7 services), Fudan Train-Ticket (7 services), and Tsinghua GAIA (4 services):

```bash
python3 -m omnisim.cli microservices
```

### Telemetry Benchmark (Real AWS CloudWatch Metrics)

Run empirical verification against 8,000+ real-world AWS CloudWatch data points from the Numenta Anomaly Benchmark (NAB):

```bash
python3 -m omnisim.cli telemetry
```

### Google Cloud MCP Toolbox Historical Validation

Test OmniSim's blind foresight against Google's real-world Model Context Protocol Database Server (`googleapis/mcp-toolbox`):

```bash
python3 -m omnisim.cli mcp-toolbox
```

### TensorFlow Distributed Runtime Validation

Test OmniSim's blind foresight against Google's flagship machine learning engine (`tensorflow/tensorflow`):

```bash
python3 -m omnisim.cli tensorflow
```

### Adversarial Robustness Benchmark Suite

Run the 5-phase institutional stress test (Blind Historical Replay, Dark Debt & Uncertainty, Adversarial SRE Traps, Automated Ingestion, Asymmetric Loss Function):

```bash
python3 -m omnisim.cli robustness
```

### Execute Test Suite

```bash
python3 -m unittest discover -s tests -p "test_*.py" -v
```

---

## 4. Empirical Validation: Public Datasets & Production Post-Mortems

OmniSim has been benchmarked directly against real-world catastrophic failure post-mortems and canonical public datasets:

* **Google `tensorflow/tensorflow` Runtime Post-Mortems (BFC Fragmentation & Pipeline Deadlocks):**
  * *BFC Allocator OOM (Issue #41710):* Caught memory fragmentation reaching 0.87 despite 8 GB of free VRAM; synthesized dynamic memory growth with bucketed shape alignment (`cuda_malloc_async`), eliminating OOM with 0 violations.
  * *Inter-Op ThreadPool Starvation (Issue #21277):* Caught circular wait deadlocking worker threads from 450 QPS to 0 QPS; synthesized decoupled dedicated I/O thread pool with non-blocking admission.
* **Google Cloud `googleapis/mcp-toolbox` Issue / PR #3921 (`EMFILE File Descriptor Leak`):**
  * *Status Quo (v1.14.0 unpatched):* Database connection failure returned error without closing `pgxpool.Pool` / `sql.DB` handle. Dynamic config reloads leaked 16+ sockets per cycle, saturating OS descriptors (1,072 / 1,024 limit) and crashing downstream AI agent tool invocations at Step 3.
  * *OmniSim Blind Foresight:* Predicted exact `EMFILE` socket exhaustion; autonomously synthesized `pool.Close()` / `db.Close()` before return, exactly matching Google's upstream fix in commit `0001190a` across 26 source files.
* **Numenta Anomaly Benchmark (NAB) realAWSCloudwatch (8,064 real production points):**
  * *EC2 CPU 99.7% Catastrophic Spike:* Caught with a 10-minute early warning lead time before system collapse; counterfactual scaling intervention reduced CPU to 48.4% with 0 SLA breaches.
  * *ELB Ingress Surges:* Ground-truth verified against labeled anomaly windows peaking up to 656 req/5m.
* **k3s-io/k3s Issue #1459 (`Error 1040: Too Many Connections`):**
  * *Status Quo:* Saturated pool at Step 2 with 100% service degradation.
  * *OmniSim Remediation:* Injected connection pooling proxy; 0 violations, system stabilized.
* **deis/deis Issue #4297 (`Remaining Connection Slots Exhausted`):**
  * *Status Quo:* Instant fire at Step 1 under 300 concurrent requests on t2.micro RDS.
  * *OmniSim Remediation:* Sized RDS instance class to r6g.large with connection limit 1,365; pool saturation kept below 52%.

See [tests/test_github_validation.py](tests/test_github_validation.py) for reproducible test fixtures.

---

## 5. Research Paper & Architecture

* **Academic Paper:** [OmniSim: Universal Counterfactual Simulation Engine (PDF)](paper/omnisim_paper.pdf) | [Markdown Version](paper/omnisim_paper.md) | [LaTeX Source](paper/omnisim_paper.tex)
* **System Architecture Specification:** [ARCHITECTURE.md](ARCHITECTURE.md)

---

## 6. License & Attribution

Distributed under the MIT License. See [LICENSE](LICENSE) for details.
OmniSim is maintained by [Deeven-Seru](https://github.com/Deeven-Seru).
