simpy – skill DevOps & Hạ tầng cho agent AI
Xây dựng, kiểm tra và phân tích các mô phỏng sự kiện rời rạc có giới hạn, dựa trên tiến trình, bằng SimPy. Dùng cho lập lịch sự kiện, hàng đợi tài nguyên, interrupt, giám sát, chạy lặp độc lập (independent replications), warm-up và phân tích đầu ra có thể tái lập.
Cài skill simpy bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/simpy-715fa.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /simpy – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/simpy-715fa.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $simpy – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/simpy-715fa.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /simpy – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/simpy-715fa.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /simpy – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
SimPy
Scope
Use this skill for process-based discrete-event models where active entities yield
events and contend for resources: queues, production systems, logistics, networks,
service operations, inventory, and other event-driven systems.
SimPy supplies an event scheduler and modeling primitives. It does not choose a
scientifically valid conceptual model, input distribution, warm-up, run length,
replication count, estimand, or causal interpretation. Treat those as simulation-study
methodology, not SimPy API behavior.
Current release and installation
Reviewed 2026-10-01 against current official documentation and the released source:
- Latest stable: SimPy 4.1.2, released on PyPI 2026-05-24; source tag
4.1.2 points to commit f4381649.
- Package metadata requires Python >=3.8 and classifies CPython 3.8-3.14
plus PyPy. SimPy has no runtime dependencies.
- 4.1.2 adds Python 3.13/3.14 support and modern-interpreter test fixes.
- Upstream and this skill are MIT-licensed.
Create a reproducible environment:
uv venv --python 3.13
source .venv/bin/activate
uv pip install "simpy==4.1.2"
python -c "import importlib.metadata; print(importlib.metadata.version('simpy'))"Do not silently substitute the latest documentation build: it may describe an
unreleased development revision. Use the versioned 4.1.2 links in
references/sources.md.
Model workflow
1. Define purpose and estimands. State the decision/question, system boundary,
entities, resources, state, outputs, time units, and terminating event or
steady-state target.
2. Write a conceptual model first. Record assumptions, distributions,
routing, priorities, initial conditions, and omitted mechanisms.
3. Implement generators. A SimPy process is an event-yielding Python generator.
Register the generator object with env.process(...).
4. Bound execution. Give every production run explicit time, entity, event, and
replication caps. Never call env.run() on a model containing an endless process.
A time horizon alone cannot stop an endless yield env.timeout(0) loop: events
keep running at the same simulation time. Add an event-count or no-time-progress
guard, and wait on state-change events instead of zero-delay busy polling.
5. Separate random streams. Use local RNG instances for logically distinct
stochastic sources; retain a seed manifest.
6. Instrument deliberately. Observe state after the transition of interest,
close time-weighted intervals at the horizon, and test that monitoring does not
alter event order.
7. Verify and validate. Test deterministic edge cases, conservation identities,
traces, queue discipline, and analytical benchmarks; compare against system or
expert evidence for the stated purpose.
8. Run independent replications. Make intervals from replication-level
estimates, not correlated entities within one run.
9. Report limitations. Include initialization, unfinished entities, run length,
seeds/streams, precision, sensitivity, and validation evidence. Never convert
simulation association into a causal claim.
Read references/simulation-methodology.md before making inferential claims.
Minimal bounded model
import random
import simpy
HORIZON = 480.0
arrival_rng = random.Random(101)
service_rng = random.Random(202)
env = simpy.Environment()
server = simpy.Resource(env, capacity=2)
completed = []
def customer(arrival):
with server.request() as request:
yield request
wait = env.now - arrival
yield env.timeout(service_rng.expovariate(1 / 6.0))
completed.append((env.now, wait))
def arrivals():
for _ in range(10_000): # Entity cap.
delay = arrival_rng.expovariate(1 / 4.0)
if env.now + delay >= HORIZON:
return
yield env.timeout(delay)
env.process(customer(env.now))
env.process(arrivals())
env.run(until=HORIZON)The numeric horizon is half-open: normal events scheduled exactly at 480.0 are
not processed. Report unfinished entities rather than silently treating them as
completed observations.
Core semantics
Environment and deterministic ordering
Environment is single-threaded. The queue is ordered by simulation time, event
priority, then a strictly increasing event ID. Same-time, same-priority events are
therefore processed FIFO in scheduling order. Model processes may represent
concurrency, but callbacks execute sequentially and deterministically.
This orders the events currently queued. A callback can insert an urgent event at
the current time, so a valid processing trace need not have globally increasing
priority or event IDs within a timestamp.
env.now: unitless simulation clock; choose and document one unit.env.peek(): next event time or infinity.env.step(): process one event; raisesEmptySchedulewhen empty.env.active_process: currently executing process, otherwiseNone.env.run(): drain the queue; unsafe with recurring or endless processes.
env.run(until=number) and env.run(until=event) are not interchangeable at
boundaries:
- A numeric value schedules an urgent stop event and excludes ordinary events at
that exact time.
- An Event criterion returns that event's value when its stop callback fires.
Other same-time ordering depends on priority and scheduling order.
- In 4.1.2,
Environment.step()preserves callbacks remaining after
StopSimulation by rescheduling the target. Consequently, after
env.run(until=target), target.processed can remain False until one more
step()/run() even though its value was returned. Do not use processed as the
sole post-run completion test.
See references/events.md and references/monitoring.md.
Event, Timeout, Process, and Condition
- An
Eventmoves once through not-triggered -> triggered/scheduled -> processed.
succeed(value) or fail(exception) triggers it once.
- A
Timeouttriggers when created, is scheduled fornow + delay, and cannot be
manually succeeded again.
env.process(generator)creates aProcess; the generator resumes with the
yielded event value. Returning from the generator succeeds the Process with that
return value. Uncaught exceptions fail it.
AnyOf/a | bandAllOf/a & byield aConditionValue: an ordered,
dict-like mapping from event objects to their values. Test membership using
the original event objects; do not assume a scalar result.
AnyOfdoes not cancel losing events. Explicitly cancel pending resource
requests when abandoning them; ordinary timeouts remain scheduled.
Interrupts
process.interrupt(cause) schedules an urgent interruption that throws
simpy.Interrupt into the target generator. Catch it around the yielded work that
may be interrupted, inspect interrupt.cause, update remaining work, then either
resume, re-yield the original event, or terminate.
Interrupting a process removes its resume callback from its current target; it does
not cancel that target event. A process cannot interrupt itself or a terminated
process. See references/process-interaction.md.
Shared resources
| Type | Semantics |
|---|---|
| Resource | FIFO semaphore-like usage slots |
| PriorityResource | Queued requests sorted by lower numeric priority first |
| PreemptiveResource | Priority queue plus optional preemption of a current user |
| Container | Homogeneous numeric level; put/get wait for capacity/material |
| Store | FIFO Python objects |
| FilterStore | First available item satisfying the request's predicate |
| PriorityStore | Comparable items returned in priority order |
Use a request context manager:
def job(env, resource):
with resource.request() as request:
yield request
yield env.timeout(3)On exit it releases an acquired request or cancels a still-pending one, including
during exception unwinding. For a manually retained pending put/get/request,
call cancel() if an interrupt or timeout makes the process abandon it.
PreemptiveResource.request(priority=..., preempt=True) uses lower numbers as
higher priority. The preempted process receives an Interrupt whose cause is a
Preempted object: cause.by is the preempting Process,
cause.usage_since is when use began, and cause.resource is the resource.
Queued priority takes precedence over the preempt flag; mixing preempting and
non-preempting requests needs explicit tests.
Read references/resources.md for blocked operations, queue rules, and examples.
Monitoring and stepping
Prefer explicit domain observations at state transitions. For generic resource
monitoring, wrappers or subclasses can inspect count, queue, level, items,
put_queue, and get_queue. For event tracing, schedule() and step() are the
central hooks.
Queue measurements are timing-sensitive:
- A request method's pre-state, post
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- devops-deploy – DevOps và triển khai ứng dụng — Docker, CI/CD với GitHub Actions, AWS Lambda, SAM…
- devops-pipeline-builder – Thiết kế và triển khai pipeline CI/CD, cấu hình Docker, chiến lược triển khai và tự động…
- devops-troubleshooter – Chuyên gia xử lý sự cố DevOps, chuyên ứng phó sự cố nhanh, gỡ lỗi nâng cao và…
- dns-management – Cấu hình DNS zone và record. Quản lý Route53, Cloud DNS và DNS tự host. Dùng khi thiết…
- docker-compose – Định nghĩa và chạy ứng dụng Docker nhiều container bằng Docker Compose.
- docker-expert – Bạn là chuyên gia containerization Docker nâng cao, có kiến thức thực tiễn toàn diện về…
- docker-management – Xây dựng, tối ưu và xử lý sự cố container và image Docker.
- dropthehassle-publish – Xuất bản trang tĩnh đã hoàn thiện lên liên kết HTTPS miễn phí với DropTheHassle: build…