Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e9a70c7
Update dependencies in Cargo.lock and add Cargo.lock to .gitignore
shawhanken Dec 18, 2025
68da611
Merge branch 'main' of https://github.com/yusufyian/RustPython
shawhanken Dec 18, 2025
1bf2bdf
Update dependencies in Cargo.lock and add Cargo.lock to .gitignore
shawhanken Dec 19, 2025
1726b36
Add additional reference files to .gitignore
shawhanken Dec 19, 2025
fd57302
Update .gitignore to exclude additional files and improve dependency …
shawhanken Dec 19, 2025
ecfabb8
Merge branch 'RustPython:main' into main
yusufyian Dec 19, 2025
bc9b80a
Merge branch 'main' of https://github.com/yusufyian/RustPython
shawhanken Dec 19, 2025
1a1c97a
Add checkpoint functionality to VirtualMachine
shawhanken Dec 19, 2025
3997507
Add checkpoint request handling and update checkpoint functionality
shawhanken Dec 19, 2025
551d025
Enhance demo script with additional print statements for debugging
shawhanken Dec 19, 2025
665790f
Update demo user and enhance README with testing instructions
shawhanken Dec 24, 2025
c2edc6b
Update .gitignore to include demo files
shawhanken Dec 24, 2025
4dc6120
Update .gitignore and demo script for type checking
shawhanken Dec 25, 2025
9ac5e54
Rename RustPython binary to "pvm" in Cargo.toml and update demo.py fo…
yusufyian Dec 26, 2025
8ea2822
Rename RustPython binary to 'pvm' in Cargo.toml and update demo.py fo…
yusufyian Dec 26, 2025
66dc584
Update README and test script to reflect binary name change from 'rus…
yusufyian Dec 29, 2025
6c26391
Refactor demo.py for improved clarity and structure in checkpointing …
yusufyian Dec 29, 2025
a1c1891
Update demo.py and README for financial trading scenario simulation
yusufyian Dec 29, 2025
f41b080
Enhance demo.py with additional trading scenario features and update …
yusufyian Dec 29, 2025
5f547a5
Implement PVM host and runtime modules with initial configurations
yusufyian Dec 29, 2025
3ed0799
Update various files for improved functionality and clarity
yusufyian Dec 29, 2025
9704677
Enhance VM functionality and code clarity
yusufyian Dec 29, 2025
965b201
Enhance demo script and update .gitignore
yusufyian Dec 30, 2025
9f354c2
Update .gitignore to include all reference files and remove specific …
yusufyian Dec 30, 2025
b50f1f3
Remove obsolete reference files for PVM integration and continuation …
yusufyian Dec 30, 2025
f8fc889
Remove obsolete demo files for checkpoint/resume functionality
yusufyian Dec 30, 2025
26ac488
Remove obsolete binary snapshot file for demo functionality
yusufyian Dec 30, 2025
b2ba6ea
Remove obsolete test script for checkpoint/resume functionality
yusufyian Dec 30, 2025
2dfed2d
Refactor comments in state_store.py for clarity and consistency
yusufyian Dec 30, 2025
d8aabdd
Enhance checkpoint functionality and update .gitignore
yusufyian Dec 30, 2025
6d54427
Update source location handling in compiler-source
yusufyian Dec 30, 2025
a1a7ec6
Refactor checkpoint and snapshot handling for improved functionality
yusufyian Dec 30, 2025
3620c13
Update version formatting in version.rs to reflect PVM 0.0.2 integration
yusufyian Dec 31, 2025
fe31a3d
Add PVM versioning support and update build script
yusufyian Dec 31, 2025
8eaf89f
Implement multi-frame checkpoint support and enhance stack management
yusufyian Dec 31, 2025
5544761
Enhance checkpoint functionality and update demo scripts
yusufyian Dec 31, 2025
13117d6
Add support for enumerate, zip, map, and filter in snapshot handling
yusufyian Dec 31, 2025
63c44b5
Enhance checkpoint and block stack management in VM
yusufyian Dec 31, 2025
c6806af
Add support for ListIterator and RangeIterator in snapshot handling
yusufyian Jan 3, 2026
9844d0d
Add comprehensive demo snapshot to .gitignore
yusufyian Jan 3, 2026
a07fed6
Remove Cargo.lock file to prevent unnecessary tracking of dependencies
yusufyian Jan 5, 2026
06e9e6a
Add error handling and execution options in PVM runtime
yusufyian Jan 5, 2026
072c0cc
Add determinism support and enhance error handling in PVM runtime
yusufyian Jan 8, 2026
5e01466
Enhance PVM runtime with import tracing and version updates
yusufyian Jan 8, 2026
b9dc39d
Add new business scenario demos to README
yusufyian Jan 8, 2026
d5afdde
Fix formatting issue in escrow_marketplace_demo.py by adding a newlin…
yusufyian Jan 12, 2026
9f3c462
Enhance PVM runtime with continuation support and new features
yusufyian Jan 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update demo.py and README for financial trading scenario simulation
- Modified demo.py to simulate a trading day pipeline, including order loading, risk checks, and trade settlement.
- Enhanced print statements for clarity on order processing, risk flags, and final report generation.
- Updated README to describe the new financial trading scenario and its phases, ensuring users understand the demo's functionality.
  • Loading branch information
yusufyian committed Dec 29, 2025
commit a1c1891294b4b5de87438decb818b175c17f642a
4 changes: 4 additions & 0 deletions examples/breakpoint_resume_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

这个演示使用 PVM 的 VM 级断点/恢复原型:运行到断点行时保存虚拟机状态并退出进程;再次运行时加载断点数据,直接从断点行之后继续执行。

## 场景说明(金融交易)

示例代码模拟了一个“交易日流水线”:第一阶段加载订单、行情与风控阈值;第二阶段在断点恢复后完成撮合与风险检查,生成成交记录与风险标记;第三阶段再次恢复后进行结算与账本汇总,输出最终报告并清理断点文件。这样可以直观看到:即使进程中途退出,VM 仍能在下一次运行从断点处无缝继续,且之前构建的状态(订单、成交、风险结果等)都会被完整保留。

## 运行方式

第一次运行(触发断点 1 并退出):
Expand Down
115 changes: 81 additions & 34 deletions examples/breakpoint_resume_demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
print(" Idea: VM saves state at checkpoints and exits.")
print(" Run flow: 1) run -> stop #1, 2) resume -> stop #2, 3) resume -> finish")
print("=" * 60)
print("[1/3] build input state (ai agent runs)")
print(" action: load run telemetry, set cost/latency thresholds, and precompute summary stats")
runs = [
{"id": "job-001", "agent": "planner", "tokens": 640, "tool_calls": 2, "latency_ms": 820},
{"id": "job-002", "agent": "coder", "tokens": 1480, "tool_calls": 5, "latency_ms": 2400},
{"id": "job-003", "agent": "reviewer", "tokens": 520, "tool_calls": 1, "latency_ms": 610},
print("[1/3] build input state (trading day snapshot)")
print(" action: load orders, prices, and risk limits; precompute exposure summary")
orders = [
{"id": "ord-001", "symbol": "AAPL", "side": "BUY", "qty": 120, "limit": 192.10},
{"id": "ord-002", "symbol": "MSFT", "side": "SELL", "qty": 80, "limit": 411.50},
{"id": "ord-003", "symbol": "NVDA", "side": "BUY", "qty": 60, "limit": 122.30},
]
cost_per_1k_tokens = 0.03
alert_latency_ms = 2000
run_log = ["loaded runs", f"alert_latency_ms={alert_latency_ms}"]
prices = {"AAPL": 192.25, "MSFT": 411.10, "NVDA": 122.60}
max_order_notional = 25000.0
slippage_limit = 0.35
run_log = ["loaded orders", f"slippage_limit={slippage_limit}"]
summary = {
"run_count": len(runs),
"total_tokens": sum(item["tokens"] for item in runs),
"total_latency_ms": sum(item["latency_ms"] for item in runs),
"order_count": len(orders),
"total_qty": sum(item["qty"] for item in orders),
"symbols": sorted({item["symbol"] for item in orders}),
}
for item in runs:
for item in orders:
print(
" run {id} agent={agent} tokens={tokens} tool_calls={tool_calls} "
"latency_ms={latency_ms}".format(**item)
" order {id} {side} {qty} {symbol} limit={limit}".format(**item)
)
print(f" cost_per_1k_tokens={cost_per_1k_tokens} alert_latency_ms={alert_latency_ms}")
print(f" prices={prices}")
print(f" max_order_notional={max_order_notional} slippage_limit={slippage_limit}")
print(f" summary={summary}")

# Breakpoint 1: must be a standalone statement.
Expand All @@ -49,18 +50,45 @@

# Phase 2: derive alerts and billing info from restored state.
print("[2/3] resumed after checkpoint #1")
print(" action: flag slow runs, compute per-run cost, aggregate totals, and append run log")
alerts = [item["id"] for item in runs if item["latency_ms"] >= alert_latency_ms]
costs = [
{"id": item["id"], "cost": round((item["tokens"] / 1000) * cost_per_1k_tokens, 4)}
for item in runs
]
total_cost = round(sum(item["cost"] for item in costs), 4)
run_log.append(f"alerts={alerts}")
run_log.append(f"total_cost={total_cost}")
print(f" alerts={alerts}")
print(f" costs={costs} total_cost={total_cost}")
print(f" log={run_log}")
print(" action: simulate fills, compute slippage and notional, flag risk, append run log")
fills = []
risk_flags = []
for item in orders:
mkt = prices[item["symbol"]]
slip = round(abs(mkt - item["limit"]), 2)
notional = round(mkt * item["qty"], 2)
fills.append(
{
"id": item["id"],
"symbol": item["symbol"],
"side": item["side"],
"qty": item["qty"],
"fill": mkt,
"slippage": slip,
"notional": notional,
}
)
if slip > slippage_limit or notional > max_order_notional:
risk_flags.append(item["id"])
total_notional = round(sum(item["notional"] for item in fills), 2)
run_log.append(f"risk_flags={risk_flags}")
run_log.append(f"total_notional={total_notional}")
print(" fills:")
for item in fills:
print(
" - {id} {symbol} {side} qty={qty} fill={fill} "
"slip={slippage} notional={notional}".format(**item)
)
print(" risk_flags:")
if risk_flags:
for item_id in risk_flags:
print(f" - {item_id}")
else:
print(" - none")
print(f" total_notional={total_notional}")
print(" log:")
for entry in run_log:
print(f" - {entry}")

# Breakpoint 2: save state again and exit; next run continues below.
print(SEP)
Expand All @@ -75,17 +103,36 @@
# Phase 3: produce a final report and clean up the checkpoint file.
print(SEP)
print("[3/3] resumed after checkpoint #2")
print(" action: finalize report and cleanup snapshot")
print(" action: settle trades, build ledger, emit final report, and cleanup snapshot")
ledger = [
{
"symbol": item["symbol"],
"net_qty": item["qty"] if item["side"] == "BUY" else -item["qty"],
"avg_price": item["fill"],
}
for item in fills
]
report = {
"summary": summary,
"alerts": alerts,
"costs": costs,
"total_cost": total_cost,
"risk_flags": risk_flags,
"ledger": ledger,
"total_notional": total_notional,
"status": "ready",
}
run_log.append("report_ready")
print(f" report={report}")
print(f" log={run_log}")
print(" report:")
print(f" summary={report['summary']}")
print(f" risk_flags={report['risk_flags']}")
print(" ledger:")
for item in report["ledger"]:
print(
" - {symbol} net_qty={net_qty} avg_price={avg_price}".format(**item)
)
print(f" total_notional={report['total_notional']}")
print(f" status={report['status']}")
print(" log:")
for entry in run_log:
print(f" - {entry}")
print(SEP)

# Clean up the checkpoint file so the next run starts fresh.
Expand Down