quantum_mcp
by ryanmat
README.md
# quantum engine
Quantum computing, optimization, and quantitative trading platform. Provides quantum_engine
as a standalone Python library for QUBO solvers and quantum feature generation, plus an MCP
server for Claude Code integration via the Model Context Protocol.
## What It Does
- **Quantum Optimization** -- D-Wave annealing and Qiskit simulation for QUBO problems
(portfolio selection, alert triage ordering, model routing, room scheduling)
- **Quantum Feature Generation** -- HSBC-style parameterized circuits (RY+CX) that produce
probability distributions as ML features for classical classifiers
- **Equity Trading Pipeline** -- End-to-end from IBKR data fetch through quantum/classical
backtesting to paper trading with 3-gate scientific validation
- **Prediction Markets** -- Kalshi market analysis, portfolio optimization, SVM classification
- **Multi-Agent Orchestration** -- Routing, consensus, and decomposition across agent types
## Project Status
| Component | Focus | Tests |
|-----------|-------|-------|
| quantum_engine | QUBO solvers, backends, feature generation | ~450 |
| Quantum Foundation | VQE, QAOA, Kernels, Q# | ~174 |
| Multi-Agent Orchestration | Routing, consensus, decomposition | ~180 |
| Trading v2 | Kalshi, IBKR, classifiers, risk, backtesting | ~378 |
| Equity Pipeline | Backtest -> Paper -> Live | ~132 |
| Benchmarks | D-Wave vs scipy, IBM kernel noise, Kalshi features | ~32 |
**Total: 1551 tests passing (27 skipped) | 44 MCP tools**
## Architecture
```
quantum_engine (standalone library) MCP Server (44 tools)
+-----------------------------------+ +-------------------------+
| Backends | | Tool Handlers |
| DWaveBackend (Advantage2) | | quantum, trading, |
| AerBackend (Qiskit simulator) | | kalshi, ibkr, |
| IBMQuantumBackend (Heron QPU) | | risk, ensemble |
| ScipyAnnealingBackend | +-------------------------+
| | |
| QUBO Solvers | Claude Code / Richard
| PortfolioQUBO (finance) |
| RoutingQUBO (model-to-domain) |
| TriageQUBO (alert ordering) |
| SchedulingQUBO (room/time) |
| |
| Feature Generation |
| QuantumFeatureGenerator |
| (6-qubit RY+CX, 64 features) |
+-----------------------------------+
```
## Requirements
- Python 3.13+
- uv package manager
- D-Wave Leap account (optional, for quantum annealing)
- IBM Quantum Open Plan (optional, for Heron QPU)
- IB Gateway (optional, for live equity trading)
## Installation
```bash
git clone https://github.com/ryanmat/quantum_mcp.git
cd quantum_mcp
uv sync --all-extras
```
For specific features:
```bash
uv sync --extra dwave # D-Wave annealing
uv sync --extra ibkr # IBKR trading
uv sync --extra data # Parquet persistence
uv sync --extra trading # Full trading pipeline
```
## Configuration
Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```
### D-Wave Quantum Annealing
```bash
DWAVE_API_TOKEN=DEV-xxx...
DWAVE_SOLVER=Advantage2_prototype2.6
```
### IBM Quantum (Optional)
```bash
IBM_QUANTUM_TOKEN=your-token
IBM_QUANTUM_INSTANCE=ibm_fez
```
### IBKR (Interactive Brokers)
```bash
IBKR_HOST=127.0.0.1
IBKR_PORT=4002 # 4002=paper (gateway), 7497=paper (TWS)
IBKR_CLIENT_ID=1
```
## Running the Server
```bash
uv run python -m quantum_mcp
```
## quantum_engine Library
The core quantum functionality is available as a standalone Python library:
```python
from quantum_engine.solvers import TriageQUBO, RoutingQUBO, SchedulingQUBO
from quantum_engine.backends import ScipyAnnealingBackend, DWaveBackend
from quantum_engine.features import QuantumFeatureGenerator
# Optimize alert investigation order
triage = TriageQUBO(alerts, operator_capacity=1)
solution = triage.solve(backend=ScipyAnnealingBackend())
# Generate quantum features for classical ML
gen = QuantumFeatureGenerator(n_qubits=6, circuit_depth=2)
features = gen.generate_features(metric_values) # 64 features
```
## MCP Tools (44 total)
### Quantum Computing (8)
| Tool | Description |
|------|-------------|
| `quantum_list_backends` | List available quantum backends |
| `quantum_estimate_cost` | Estimate job cost before submission |
| `quantum_simulate` | Local Qiskit simulation (bell, ghz, qft, custom) |
| `quantum_vqe` | Variational Quantum Eigensolver for ground state energy |
| `quantum_qaoa` | QAOA for combinatorial optimization (MaxCut) |
| `quantum_kernel` | Quantum kernel matrix for ML classification |
| `quantum_run_qsharp` | Execute Q# quantum programs |
| `quantum_anneal` | Solve QUBO via D-Wave quantum annealing (deprecated, use library) |
### Kalshi Prediction Markets (12)
| Tool | Description |
|------|-------------|
| `kalshi_get_markets` | List available Kalshi prediction markets |
| `kalshi_get_market` | Get details for a specific market |
| `kalshi_get_orderbook` | Get order book depth |
| `kalshi_place_order` | Place an order (requires confirm=true) |
| `kalshi_cancel_order` | Cancel an existing order |
| `kalshi_get_positions` | Get current positions |
| `kalshi_get_portfolio` | Get portfolio summary |
| `kalshi_get_orders` | Get orders with optional status filter |
| `kalshi_get_trades` | Get recent trades |
| `kalshi_get_balance` | Get account balance |
| `kalshi_optimize_portfolio` | QUBO portfolio optimization on current markets |
| `kalshi_estimate_edge` | Estimated probability edge for a market |
### IBKR Equity Trading (8)
| Tool | Description |
|------|-------------|
| `ibkr_get_quote` | Real-time equity quote |
| `ibkr_get_historical` | Historical OHLCV bars |
| `ibkr_place_order` | Place equity order (requires confirm=true) |
| `ibkr_get_positions` | Current equity positions |
| `ibkr_get_account` | Account summary |
| `ibkr_get_technicals` | Technical indicators (EMA, RSI, Bollinger, ATR) |
| `ibkr_get_regime` | Volatility regime detection |
| `ibkr_quantum_features` | Quantum-enhanced equity feature classification |
### Backtesting, Risk & ML (11)
| Tool | Description |
|------|-------------|
| `risk_check` | Risk assessment on a proposed order |
| `risk_status` | Current risk manager state |
| `validation_gate` | Validation gate check on backtest results |
| `classify_market` | Market event classification with quantum kernel SVM |
| `retrain_model` | Retrain classifier on settled data |
| `ensemble_predict` | Multi-agent ensemble prediction |
| `ensemble_status` | Ensemble agent accuracy statistics |
| `scan_arbitrage` | Scan for arbitrage opportunities |
| `arbitrage_details` | Detailed arbitrage analysis |
| `equity_backtest` | Quantum vs classical backtest with Gate 1 validation |
| `equity_paper_trade` | Paper trading session with risk management |
## Equity Trading Pipeline
3-gate scientific validation process:
```
E1: Parquet Data Offline OHLCV storage (AAPL, MSFT, JPM, XOM, UNH + SPY)
|
E2: Strategy QuantumEquityStrategy + ClassicalEquityStrategy
|
E3: Backtest Gate 1: 50+ trades, Sharpe >= 1.0, max DD <= 25%
|
E4: Paper Trade Gate 2: 30+ trades, Sharpe >= 0.8, degradation <= 25%
|
E5: Live Trade Gate 3: 20+ trades, Sharpe >= 0.7, $500 cap (Decimal)
```
Safety layers for live trading (all must pass):
1. `confirm=true` required for order placement
2. `RiskManager.assess_order()` must return allowed=true
3. Trade value must not exceed $500.00 (Decimal, hard cap)
## PDP Architecture
quantum_mcp is part of the Parallel Distributed Processing (PDP) platform, orchestrated by
[Richard (openclaw)](https://github.com/ryanmat/richard). TriageQUBO is wired into
the enrichment orchestrator for alert processing order. RoutingQUBO is wired into
the pdp-orchestrator for model-to-domain assignment.
**Peer PDP units:**
- **Precursor** -- Temporal state classification, forecasting, drift detection
## Testing
```bash
uv run pytest tests/ -v # All tests
uv run pytest tests/unit -v # Unit tests only
uv run pytest tests/ -v -k "qubo" # QUBO solver tests
uv run pytest tests/ --cov=quantum_mcp # With coverage
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues