Julia scientific pro

From findscripter/everything-skills · View interactive version

Julia scientific pro is an AI agent skill from the GitHub repository findscripter/everything-skills. 当用 Julia 1.10+ 写科学计算/数值/高性能代码,需要类型稳定、多重派发设计、性能调优或打包上线时使用;做类型稳定的可上线 Julia 代码、@code_warntype 诊断、BenchmarkTools 基准与 BlueStyle 规范化产物;不适用于一次性脚本、纯基础语法问答或无法引入 Julia 的场景;触发词:Julia、多重派发、类型稳定、@code_warntype、BenchmarkTools、Pkg、CUDA.jl、DifferentialEquations。

How to use this skill

Skill file

何时使用

不该用的边界:

步骤

按「需求 → 设计 → 实现 → 测试 → 调优 → 文档 → 规范化」推进,每步可独立验收:

  1. 分析需求:先问清目标、约束、输入输出;判断是否对类型稳定与性能敏感(决定后续是否需要 @code_warntype / 基准)。
  2. 设计类型层级:用抽象类型 + 多重派发表达问题域;优先参数化类型写泛型;默认 struct(不可变)而非 mutable struct,仅在必须原地修改时才可变。
  3. 类型注解实现:函数参数/返回值按需注解以提升可读性与编译期特化;避免抽象字段类型导致的类型不稳定(用参数化字段而非 Any)。
  4. 写测试:用 Test.jl 组织 @testset,实现前或同步编写;包级质量用 Aqua.jl,静态分析用 JET.jl。
  5. 基准与调优:@btime/@benchmark(BenchmarkTools.jl)测时延与分配,@code_warntype 查类型不稳定(红色 Any/Union 即问题点),Profile/@profile 找热点;按需上 Threads.@threads、@simd、CUDA.jl。
  6. 写文档:docstring + 示例;包文档用 Documenter.jl,文档内代码块可做 doctest。
  7. 规范化:JuliaFormatter.jl 按 BlueStyle 统一格式(提交前必跑)。

指令(给 Agent 的硬性流程)

示例

REPL 包管理(不碰 Project.toml)

julia> ]                      # 进入 Pkg 模式
(MyPkg) pkg> add BenchmarkTools JET Aqua
(MyPkg) pkg> test

类型稳定诊断 + 基准

using BenchmarkTools
f(x) = x > 0 ? x : 0          # 三元保持同类型,稳定
@code_warntype f(1.0)         # 全绿表示类型稳定;出现红色 Any/Union 需修
@btime f(2.0)                 # 测时延与内存分配

多重派发 + 参数化不可变类型

abstract type Shape end
struct Circle{T<:Real} <: Shape   # 参数化,字段具体类型,类型稳定
    r::T
end
struct Square{T<:Real} <: Shape
    side::T
end
area(s::Circle) = π * s.r^2       # 按类型派发,零成本抽象
area(s::Square) = s.side^2

起新包 + 格式化

using PkgTemplates
Template(; user="me", plugins=[Git(), GitHubActions(), Codecov()])("MyPkg")
using JuliaFormatter; format(".")     # BlueStyle

注意事项

互见


本条采编自 sickn33/antigravity-awesome-skills(MIT)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.