Files
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

103 lines
5.2 KiB
Python

"""Auto-generated cb task for KiCad submission b7148878-ca7a-409c-a6c5-e1c6cff7858b."""
from __future__ import annotations
import asyncio
from pathlib import Path
import cua_bench as cb
_SUBMISSION_ID = "b7148878-ca7a-409c-a6c5-e1c6cff7858b"
_REMOTE_PROJECT_DIR = "/home/cua/kicad_project"
_HARNESS_DIR = Path(__file__).parent
@cb.tasks_config
def tasks() -> list[cb.Task]:
return [
cb.Task(
description='Design a KiCad-style schematic of a two opamp circuit that converts a bipolar +/- 10 V analog signal to a positive 0 to 5V analog signal that can be delivered to an ADC or microcontroller.\n\n\t• The first opamp (U1) buffers the input signal and is configured as a follower: \n\t\t○ Pin 1 is directly connected to overall circuit input.\n\t\t○ Pin 2 is connected directly to Pin 5\n\t\t○ Pin 3 is connected to a +15 Vdc power supply and a 0.1 uF decoupling capacitor.\n\t\t○ Pin 4 is connected to a -15 Vdc power supply and a 0.1 uF decoupling capacitor.\n\t\t○ Pin 5 is also connected to a 100 kOhm resistor (R1).\n\t• The second opamp (U2) is configured to provide voltage division and shifting.\n\t\t○ Pin 1 is connected to the shift voltage. This is generated by connecting a 4.096 Vdc reference to a 10 kOhm resistor (R3) followed by a 162 ohm resistor (R4). The other end of R4 is connected in parallel to a 10 kOhm resistor, 1 uF unpolarized capacitor, and Pin 1.\n\t\t○ Pin 2 is connected to the other side of R1 mentioned above.\n\t\t○ Pin 2 is also connected to a parallel combination of a 23 kOhm resistor (R2) and a 43 pF unpolarized capacitor (C1). The other end of this combination is connected to Pin 5\n\t\t○ Pin 3 is connected to a +5 Vdc power supply and a 0.1 uF decoupling capacitor.\n\t\t○ Pin 4 is connected to ground.\n\t\t○ Pin 5 is also connected to a 10 kOhm load, which provides a path to ground during startup transients.\n\t\t○ Pin 5 also provides the overall circuit output.\n\t• Reference: This circuit is modified from "Analog Engineer\'s Circuit Cookbook: Amplifiers", Texas Instruments, 2nd Ed 2019, p. 162.',
metadata={"difficulty": 'medium', "submission_id": _SUBMISSION_ID},
)
]
@cb.setup_task(split="train")
async def start(task_cfg: cb.Task, session: cb.DesktopSession) -> None:
await session.apps.kicad.install(with_shortcut=True)
initial_dir = _HARNESS_DIR / "initial"
for local_path in sorted(initial_dir.rglob("*")):
if not local_path.is_file():
continue
rel = local_path.relative_to(initial_dir)
remote_path = f"{_REMOTE_PROJECT_DIR}/{rel.as_posix()}"
remote_dir = f"{_REMOTE_PROJECT_DIR}/{rel.parent.as_posix()}"
await session.run_command(f"mkdir -p '{remote_dir}'", check=False)
await session.write_bytes(remote_path, local_path.read_bytes())
try:
await session.apps.kicad.launch(project_path=None)
except Exception:
pass
await asyncio.sleep(5)
@cb.solve_task(split="train")
async def solve(task_cfg: cb.Task, session: cb.DesktopSession) -> None:
"""Oracle solver: upload reference.net directly to the expected output path."""
await session.run_command(f"mkdir -p '{_REMOTE_PROJECT_DIR}'", check=False)
await session.write_bytes(
f"{_REMOTE_PROJECT_DIR}/output.net",
(_HARNESS_DIR / "reference.net").read_bytes(),
)
@cb.evaluate_task(split="train")
async def evaluate(task_cfg: cb.Task, session: cb.DesktopSession) -> float:
from cua_bench.netlist_compare import (
compare_kicad_netlists,
load_reference_netlist,
)
reference = load_reference_netlist(_HARNESS_DIR / "reference.net", _HARNESS_DIR)
# Try common netlist output locations first
candidate_paths = [
f"{_REMOTE_PROJECT_DIR}/{_SUBMISSION_ID}.net",
f"{_REMOTE_PROJECT_DIR}/output.net",
]
for path in candidate_paths:
result = await session.run_command(f"cat '{path}'", check=False)
candidate = result.get("stdout", "")
if candidate.strip():
return compare_kicad_netlists(candidate, reference)
# Search for any .net file in the project dir
result = await session.run_command(
f"find {_REMOTE_PROJECT_DIR} -name '*.net' | head -1", check=False
)
net_path = result.get("stdout", "").strip()
if net_path:
result = await session.run_command(f"cat '{net_path}'", check=False)
candidate = result.get("stdout", "")
if candidate.strip():
return compare_kicad_netlists(candidate, reference)
# Fall back: agent edited schematic without exporting — use kicad-cli to generate netlist
result = await session.run_command(
f"find {_REMOTE_PROJECT_DIR} -name '*.kicad_sch' | head -1", check=False
)
sch_path = result.get("stdout", "").strip()
if sch_path:
out_net = "/tmp/kicad_eval_output.net"
await session.run_command(
f"kicad-cli sch export netlist '{sch_path}' -o '{out_net}'",
check=False,
)
result = await session.run_command(f"cat '{out_net}'", check=False)
candidate = result.get("stdout", "")
if candidate.strip():
return compare_kicad_netlists(candidate, reference)
return 0.0