How ritam-05/cpu-scheduler-rl works
1. What this repository is
- This is a small benchmark service for CPU scheduling under RL / agent control.
- The core artifact is a deterministic scheduling environment plus a grading layer that scores agent decisions on three tasks.
2. Primary runtime shape
- The system is centered on a FastAPI application exposed on port 7860.
- It is meant to run both locally and in Docker / Hugging Face Spaces.
- app.py is the local entrypoint, while server/app.py and openenv.yaml support the hosted deployment path.
3. Environment subsystem
- env.py is the heart of the benchmark: it models the CPU scheduling state and transitions.
- The environment is deterministic, which matters for reproducible grading and for comparing policies fairly.
- The expected interaction pattern is the standard control loop: reset → inspect state → choose action → step → observe next state.
4. Task and benchmark definition
- tasks.py defines the three graded tasks referenced in the README.
- These tasks likely parameterize the scheduling scenario and define what counts as a successful policy for each benchmark variant.
- This is the main benchmark boundary: the same environment machinery is reused, but task configuration changes the evaluation target.
5. Grading subsystem
- grader.py evaluates submissions against the task definitions and environment behavior.
- The GET /grade/{task_id} endpoint exposes this scoring path over HTTP.
- This is separate from the interactive environment API, so grading can be treated as a read-only evaluation layer.
6. Service/API boundary
- The FastAPI service exposes the operational surface of the benchmark:
- GET /health
- GET /tasks
- POST /reset
- POST /step
- GET /state
- GET /grade/{task_id}
- GET /validate
- This creates a clean split between clients and the simulation engine: clients never manipulate internal state directly, only through API calls.
7. Baseline agent / inference path
- inference.py is the baseline runner for exercising the benchmark with an OpenAI-compatible client.
- It supports external model APIs such as DeepSeek via API_BASE_URL, MODEL_NAME, and API_KEY / HF_TOKEN.
- If no credentials are present, it falls back to a shortest-job-first heuristic, which keeps the repo runnable for smoke tests without any model service.
8. Agent abstraction
- agent.py likely contains the decision-making wrapper used by the baseline or evaluation harness.
- Architecturally, this is the “policy” side of the system: it consumes state and emits scheduling actions.
- That keeps agent logic decoupled from the environment and from the HTTP service.
9. Testing boundary
- tests/test_env.py focuses on the environment behavior, which is the most important deterministic contract in the repo.
- The test emphasis suggests the environment is treated as the source of truth, with correctness validated at the state-transition level rather than only through end-to-end API calls.
10. Packaging and deployment
- Dockerfile, requirements.txt, pyproject.toml, and uv.lock define a reproducible Python runtime.
- openenv.yaml and the README’s Hugging Face instructions indicate the project is designed to be deployed as an OpenEnv-style benchmark service.
- app_port: 7860 is a key deployment assumption for diagramming the runtime.
11. Data flow to show in a diagram
- The main flow is: client or agent → FastAPI endpoint → environment state machine → updated state/score → client.
- For grading, the flow is: task selection → grader → environment/task definitions → score result.
- For baseline inference, the flow is: inference.py → model API or SJF fallback → environment API → benchmark outcome.
12. Important architectural boundary
- The most important separation is between:
- benchmark logic (env.py, tasks.py, grader.py)
- service transport (app.py, server/app.py)
- client/agent execution (agent.py, inference.py)
- That boundary is what makes the repository reusable both as a local simulator and as a hosted benchmark endpoint.
Main entry points: inference.py Inference runner · env.py Env state · app.py Local app · server/app.py Hosted app
Components 15
Benchmark logic
Deterministic scheduling state, task definitions, and grading.
- Benchmark core · The reusable CPU scheduling benchmark composed of environment, tasks, and grading.
- Env state · CPU scheduling state machine and reset/step transitions.
env.py - Tasks · Definitions for the three graded benchmark tasks.
tasks.py - Grader · Evaluates task submissions against the environment and task definitions.
grader.py
Service transport
FastAPI entrypoints that expose the benchmark over HTTP.
- API surface · The exposed benchmark operations for health, task listing, reset, step, state, grading, and validation.
- Local app · Local FastAPI entrypoint for running the service directly.
app.py - Hosted app · Hosted deployment FastAPI app used by the server package.
server/app.py
Client execution
Policy wrappers and baseline inference paths that drive the environment.
- Agent · Decision-making wrapper that turns state observations into scheduling actions.
agent.py - Inference runner · Exercises the benchmark with an OpenAI-compatible client or a heuristic fallback.
inference.py - Model API · External LLM endpoint used by the baseline runner when credentials are available.
- SJF fallback · Short-job-first heuristic used when no model credentials are present.
Deployment
Container and hosted-runtime configuration.
- Container build · Defines the reproducible containerized runtime for local or hosted execution.
Dockerfile - OpenEnv config · Hosted deployment configuration for the benchmark service.
openenv.yaml - Package setup · Project metadata and dependency lockfiles for reproducible installation.
Tests
Deterministic contract checks for the environment.
- Env tests · Validates the deterministic environment contract and state transitions.
tests/test_env.py
Connections 18
- Benchmark core → Env state: contains · The benchmark core is implemented by the environment state machine.
- Benchmark core → Tasks: defines · Task variants parameterize the benchmark.
- Benchmark core → Grader: scores · The grader turns environment/task behavior into benchmark results.
- API surface → Env state: drives · HTTP calls reset, inspect, and advance the deterministic environment.
- API surface → Tasks: lists · The service exposes the available benchmark tasks.
- API surface → Grader: exposes · The grading endpoint invokes the scoring layer.
- Local app → API surface: serves · Local entrypoint wiring for the FastAPI service.
- Hosted app → API surface: serves · Hosted deployment wiring for the FastAPI service.
- Agent → Env state: acts on · The policy wrapper consumes observations and emits actions.
- Inference runner → Agent: uses · Baseline inference routes decisions through the agent abstraction.
- Inference runner → Model API: calls · Primary path uses an OpenAI-compatible external model endpoint.
- Inference runner → SJF fallback: falls back to · Heuristic scheduling is used when no credentials are available.
- Inference runner → API surface: drives · Baseline runner interacts with the benchmark through HTTP.
- Env tests → Env state: verifies · Tests focus on deterministic state transitions and reset/step behavior.
- Container build → Local app: packages · Container build runs the local application entrypoint.
- OpenEnv config → Hosted app: deploys · Hosted configuration targets the server package app.
- Package setup → Local app: supports · Packaging and dependency metadata support local execution.
- Package setup → Hosted app: supports · Packaging and dependency metadata support hosted execution.