Skip to main content

PHSL (Python Historical Strategy Lab) - 璇玑定量化战略审计终端与多智能体沙盘

Project description

Xuanji General Strategic Prototype

Author: Peng Hao Affiliation: Python Historical Strategy Lab
License: MIT

PHSL: Xuanji Strategic Audit Terminal 🛡️

Python Historical Strategy Lab (PHSL) presents the Xuanji Strategic Audit Terminal, an advanced, AI-driven wargaming and strategic simulation system.

Xuanji acts as a digital wind tunnel for strategy, performing rigorous "Red Team" audits on strategic visions by mapping them to historical prototypes and stress-testing them in simulated environments. By integrating systems thinking,the system quantifies the physical viability of a strategy against real-world environmental noise, friction, and resistance.

📐 The Core Strategic Axiom

At the heart of the Xuanji engine is the structural conservation of historical and realistic isomorphism. Strategic effectiveness is calculated using the following core formula:

$$E = \frac{P \cdot (ssc_d \cdot L)}{(I \cdot (1 + vol)) + P}$$

Dimensional Variables:

$E$ (Strategic Effectiveness): The actualized impact of the strategy.
$P$ (Resource Pressure): The resources and effort applied.
$ssc_d$ (SSC Density / Logical Density): The binding strength between the strategic vision and physical assets, which is mathematically equivalent to the likelihood P(E|H) in Bayes' theorem.
$L$ (Leverage): The strategic multiplier (e.g., technological generation gaps).
$I$ (Inertia): The inherent resistance or friction of the target environment.
$vol$ (Volatility): Geopolitical or market fluctuations.

✨ Key Features

Strategic Oracle (AI Intelligence): Powered by Google's Gemini 2.5 Pro model, the Oracle module dynamically searches for historical prototypes, estimates Bayesian parameters, and outputs comprehensive JSON-formatted intelligence reports.

Bayesian Cognitive Engine: Refines the probability of success using Bayesian noise filtration (FRE Validation) and Monte Carlo simulations to find the "Truth Distribution."

Physics-Based Stress Testing:

  • ERT (Environmental Resilience Test): Calculates system stability and identifies the critical Collapse Line (Break Point / BP).
  • SIP (Strategic Ignition Point): Models efficiency against environmental resistance to find the exact Activation Pressure (AP) needed for a strategy to take effect across different leverage tiers (L1-L3 vs. L-0 Baseline).

Interactive UI & Visualizations: A sleek Streamlit dashboard (app.py) combined with matplotlib logic (visualizer.py) to render structural resilience audits and truth curves.

📂 Project StructurePlaintextphsl/

├── app.py # Main Streamlit web application and UI layout

├── controller.py # Central nervous system orchestrating Oracle and Engine

├── engine.py # Core mathematical and Bayesian calculation engine

├── arena.py # Acts as the Dynamic Digital Wind Tunnel for strategy testing.

├── oracle.py # Gemini API integration for historical & intelligence mapping

├── protocol.py # Isomorphism protocol for contextual switching

├── report_generator.py # CLI-based comprehensive strategy report generation

├── visualizer.py # Custom Matplotlib plotting library (Truth curves, SIP, ERT)

└── init.py # Package initialization

🚀 Installation & Setup

  1. Clone the repository and navigate to the project directory:(Ensure you have Python 3.8+ installed)
  2. Install required dependencies:Bashpip install streamlit google-genai matplotlib pandas numpy
  3. Configure Network/Proxy (If applicable):By default, oracle.py is configured with local proxies. If you are running this in an environment without proxy requirements, you may need to comment out lines 10-11 in oracle.py.
  4. 💻 Usage Run the Streamlit application from your terminal:Bash streamlit run app.py

Operating the Terminal:

Open the local web address provided by Streamlit.In the sidebar console, enter your Google Gemini API Key.Input your Strategic Vision Description (e.g., "The impact of the Belt and Road Initiative on restructuring global supply chains...").Click "⚡ 启动全领域审计" (Initiate All-Domain Audit).

Review the generated intelligence reports, historical isomorphism mappings, and physics-based stress test charts.

🛠️ System Components Breakdown

  • The Oracle (oracle.py): Acts as the Chief Auditing Officer. It enforces logical dimensionality reduction, applies real-time intelligence gathering, and matches inputs with evolutionary or military history.

  • The Engine (engine.py): Executes the mathematical heavy lifting. It applies noise filters to leverage factors, ensuring that technological or structural advantages decay appropriately in high-noise environments.

  • The Visualizer (visualizer.py): Generates high-fidelity, cyberpunk-styled (dark theme) charts to visualize the Monte Carlo truth curves and strategic hedge auditing.

  • The Arena (arena.py): Acts as the Dynamic Digital Wind Tunnel. It orchestrates multi-agent, double-blind red/blue adversarial simulations across multiple parallel universes. By pit-testing the red team's strategy against dynamic environmental blowbacks round-by-round, it tracks physical attrition, applies life/death isolation statistics, and calculates the true Emergent Break Point and absolute survival rates under extreme resistance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phsl-0.1.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phsl-0.1.0-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file phsl-0.1.0.tar.gz.

File metadata

  • Download URL: phsl-0.1.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for phsl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e1cd00293bba2e9dbc6cfe9ef51fa9fa5df16440fbdd9657699a6290f6f0e4b
MD5 a4bbc5b071ab897a9049c84ff50f5370
BLAKE2b-256 1db0b639db971960f53f5646ad44051f4e85cd9c2ed0d599140c112e79ed9a0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for phsl-0.1.0.tar.gz:

Publisher: publish.yml on pystrategylab/phsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phsl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: phsl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for phsl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b28755a19d07cf4604a7031df265761f2979d23f23f05336bd930bb4803d8a8f
MD5 5282eb8268f182bb5319ac4d860a1571
BLAKE2b-256 557000e99239395cd6dd97047c7e6860568ecc4fa6f093b98bc74fca5ac8f027

See more details on using hashes here.

Provenance

The following attestation bundles were made for phsl-0.1.0-py3-none-any.whl:

Publisher: publish.yml on pystrategylab/phsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page