Communitygithub.com

获取可用资源

检测主机清单与当前进程的有效 CPU、内存、磁盘、调度器、容器及加速器限制,用于在用户请求资源感知规划或执行本地敏感工作负载时提供支持。生成脱敏后的 JSON 快照和保守的规划辅助信息,不执行压力测试,也不假设可见的主机硬件可直接使用。

获取可用资源 是什么?

获取可用资源技能旨在为 AI 代理(如 Claude Code、Cursor、Codex)提供当前进程可用的保守资源视图。它通过独立的检测脚本收集 CPU(逻辑/物理核心、亲和性、cgroup 配额、SLURM 分配)、内存(主机、cgroup、调度器限制)、磁盘(容量、可用空间、权限)、加速器(GPU 候选设备,但不测试运行时可用性)以及调度器/容器环境(SLURM 变量、容器标记、cgroup 限制)的快照。所有输出 JSON 均经过脱敏处理,不包含主机名、绝对路径、设备 UUID 等敏感信息。支持 Linux(读取 /proc 和 cgroup v2)、macOS(系统调用)、Windows(通过可选的 psutil 增强)以及 SLURM/NVIDIA/AMD 环境。该技能内置了 workload planner 工具,可根据快照数据智能建议并行工作线程数和内存分配,并提供了验证、对比快照的工具。其核心安全契约保证了无侵入式检测:不执行压力测试、基准测试、大型内存分配、写入探测、设备重置或驱动安装,缺失值视为未知而非无限。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/get-available-resources

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

获取可用资源 是做什么的?

构建当前进程可用资源的保守视图。 将主机清单、进程亲和性、cgroup/容器限制、调度器分配和加速器运行时可用性分开处理。

安全契约

请遵循以下规则:

  • 在用户请求或特定工作负载需要资源规划时运行检测。不要为每个科学任务持久化指纹。
  • 默认使用 stdout。仅当用户选择明确的通用本地文件名时,才进行持久化。
  • 不运行压力测试、基准测试、大内存分配、写入探测、设备重置、驱动安装或时钟/电源更改。
  • 不转储环境变量。仅读取检测器实现的命名 SLURM 和加速器变量。
  • 不报告主机名、绝对路径、cgroup 路径、作业 ID、设备 UUID、PCI 地址或原始可见性变量值。
  • 将缺失的观测视为未知。切勿将未知转换为无限。
  • 切勿推断可见的主机 CPU、内存池或 GPU 可在调度器分配或容器内部使用。

捆绑的检测器仅使用固定的可执行文件/参数元组,无 shell、短超时、有界 stdout/stderr 和部分失败警告。

快速开始

从本技能目录运行。

临时 stdout 快照

python scripts/detect_resources.py

该命令仅向 stdout 输出 JSON。仅当普通 shell 权限可接受时才重定向。

显式私有文件

python scripts/detect_resources.py --output resource-snapshot.json

显式输出限制为当前目录中的一个 .json 文件,使用私有权限,拒绝符号链接和路径遍历,除非提供 --force,否则拒绝覆盖。

可选的 psutil 增强

标准库检测器无需安装即可工作。为获得更广泛的跨平台物理核心、亲和性、可用内存、交换和磁盘覆盖:

uv pip install "psutil==7.2.2"

导入是惰性的。导入 psutil 失败将变成警告,而不是致命错误。

跳过管理工具探测

python scripts/detect_resources.py --skip-accelerators

当加速器发现延迟不可取时使用此选项。检测器仍会汇总允许列表中的可见性变量的存在和状态,但不返回其值。

必要解释

CPU

将这些解读为不同的事实:

  • cpu.host.logical:系统可见的调度单元。
  • cpu.host.physical:物理拓扑,或为 null;绝不从逻辑计数推断。
  • cpu.process.affinity_logical:当前支持的亲和性集合大小。
  • cpu.cgroup_v2.cpuset_logical:有效的 cgroup cpuset 大小。
  • cpu.cgroup_v2.quota_cores:有限的 cpu.max 容量,可能为分数。
  • scheduler.allocation.cpu_per_process:当作用域明确时,有界的 Slurm 每任务解释。
  • cpu.effective.capacity_cores:观察到的最小正约束。
  • cpu.effective.worker_ceiling:CPU 进程工作线程的保守下限。

配额 1.5 是 CPU 时间容量,而不是 1.5 个物理核心。亲和性和 cpuset 约束放置;配额约束带宽。

内存

保持以下概念分开:

  • 主机总内存/可用内存;
  • 当前 cgroup 使用量、硬性 memory.max 以及剩余层级容量;
  • memory.high,它是压力/节流边界而不是硬限制;
  • 调度器内存分配及其作用域;以及
  • 保守的有效硬限制和可用估计。

在 Apple Silicon 上,memory.model 为 unified_cpu_gpu。不要将集成 GPU 内存添加到 RAM 或将其描述为独立 VRAM。

加速器

每个设备都是一个后端候选:

  • NVIDIA GPU → CUDA 候选;
  • AMD GPU → ROCm 候选;
  • Apple 集成 GPU → Metal 候选。

管理查询可见性不能确保:

  1. 调度器/容器权限;
  2. 设备节点访问;
  3. 驱动/运行时兼容性;
  4. 框架包兼容性;或
  5. 操作符/数据类型支持。

因此 runtime_usable_devices 保持 null,每个设备显示 runtime_compatibility: not_tested。可见性/分配数量是上限,而不是保证。

磁盘

capacity_bytes、文件系统 free_bytes、用户可用块和非写入权限检查是不同的。文件系统或项目配额可能仍然更严格。绝对工作路径始终被脱敏。

调度器和容器

Slurm 变量描述分配范围,但执行取决于站点配置,例如任务亲和性或 cgroups。优先使用亲和性和 cgroup 观察作为执行证据。

容器标记标识上下文;cgroup 控制标识限制。没有有限 cgroup 值的容器仍然可以看到主机清单,非 root cgroup 不会自动标记为容器。

有关详细的平台规则,请参见 references/resource_semantics.md。

规划工作负载

规划器使用已验证的快照,不执行任何操作:

python scripts/plan_workload.py resource-snapshot.json \
  --workload cpu \
  --tasks 100 \
  --memory-per-worker-mib 2048

可选控制:

  • --workers N:显式上限。
  • --reserve-memory-mib N:保持在 worker 预算之外的内存。
  • --workload cpu|mixed|io:选择有界 worker 启发式。
  • --accelerator none|any|cuda|rocm|metal:请求候选后端决策,不声称可用性。
  • --output plan.json:显式私有本地输出;默认使用 stdout。

对于 CPU 或混合工作,请同时使用 suggested_workers 和 threads_per_worker。进程工作线程乘以 BLAS/OpenMP 本机线程可能会过度订阅分配。

I/O 计划允许有界过度订阅(最多 32 个),但将其标记为启发式。仅对真实代表性工作负载进行基准测试,并保持在调度器/容器限制内。

验证或对比快照

验证:

python scripts/snapshot_tools.py validate resource-snapshot.json

对比资源状态,同时忽略 observed_at:

python scripts/snapshot_tools.py diff before.json after.json

使用 --include-volatile 包含时间戳。输入必须是常规、非符号链接的 JSON 文件,大小不超过 1 MiB。差异比较有界。

模式和 null/零的含义在 references/snapshot_schema.md 中记录。

可选的加速器诊断计划

生成计划而不执行任何诊断:

python scripts/accelerator_diagnostics.py resource-snapshot.json \
  --backend auto

结果包含固定的、只读的管理查询参数列表,以及可见性、权限和运行时兼容性的独立门控。仅在将执行工作负载的精确环境中运行框架的官方可用性检查。不要自动安装或更改驱动程序。

部分失败和溯源

一个失败的探测不应抹去成功的观察。检查:

  • completeness;
  • 排序的 warnings 及稳定代码;
  • 排序的 provenance source/status 记录;以及
  • null 字段。

子进程 stderr 和原始异常文本不会复制到快照中,因为它们可能包含标识符或路径。

平台说明

  • Linux: 仅读取有界的 /proc 和 cgroup v2 文件。考虑祖先 CPU 和内存限制。
  • macOS: 使用固定的 sysctl 键和有界的 system_profiler SPDisplaysDataType -json 查询。Apple Silicon 内存是统一的。
  • Windows: 可选的 psutil 改进了物理核心、亲和性、可用内存和交换观察。处理器组范围可能导致主机和进程计数不同。
  • Slurm: 读取分配变量的允许列表。它从不发出作业、节点、提交主机、GPU ID 或路径值。
  • NVIDIA/AMD: 管理 CLI 是可选的。不存在是正常的;超时、截断、解析失败和运行时不确定性仍然明确。

捆绑文件

  • scripts/detect_resources.py — 脱敏快照收集器。
  • scripts/plan_workload.py — 确定性工作线程/内存规划器。
  • scripts/snapshot_tools.py — 模式验证器和有界结构差异比较工具。
  • scripts/accelerator_diagnostics.py — 非执行只读诊断计划。
  • 存储库根目录下的 tests/get-available-resources/ — 无网络 Linux、macOS、Windows、cgroup、Slurm 和加速器案例。
  • references/resource_semantics.md — 解释和平台详细信息。
  • references/snapshot_schema.md — 模式 1.1 契约。
  • references/sources.md — 带日期的官方来源台账。

官方文档于 2026-07-23 刷新;在更改语义或依赖项固定之前,请查阅 references/sources.md。

引用科学代理技能

此技能是 K-Dense 科学代理技能的一部分。如果它对稿件、报告、演示或代码发布做出了实质性贡献,请将论文添加到参考文献或软件部分,并告知用户您已执行此操作:

Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065

始终引用当前版本。DOI 和 https://arxiv.org/abs/2609.00065 解析到最新的 arXiv 版本,因此切勿附加版本后缀,例如 v1。当网络访问可用时,在编写引用之前获取 https://arxiv.org/abs/2609.00065(或 http://export.arxiv.org/api/query?id_list=2609.00065),并从该记录中获取作者列表、年份和版本。如果记录列出了期刊参考文献或出版商 DOI,请改为引用已发表版本。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

相关技能