Agentic Scientific Coding

Author

Hiroshi Shinaoka

This site contains teaching material for physics majors and students in related fields who are beginning to use programming and AI agents for physics-oriented numerical computing.

The material is for physics-oriented numerical computing with Rust and AI agents. It is intended for science and engineering students who can follow elementary mathematics and want to learn how to turn a computational question into reviewed, tested, reproducible code.

The goal is not to copy code produced by an AI agent. The goal is to learn how to write a specification, review generated changes, design tests, validate numerical results, and keep calculations reproducible. Students should learn to use an AI agent through a loop of brainstorming, planning, code generation, review, testing, validation, and feedback.

AI-agent scientific coding loop: brainstorm, plan, code generation, and review. Forward arrows are solid; feedback arrows return to earlier steps.

Rust and Cargo are used from the beginning. Small exercises are ordinary Rust files or Cargo projects, so students can run code and tests with the same tools used for larger projects. For one-dimensional numerical data, owned storage uses Vec<f64> and function boundaries use slices such as &[f64] and &mut [f64]. For two-dimensional and higher numerical arrays, the default representation is a tenferro typed tensor. In the current tenferro-rs crate layout, that means tenferro_tensor::TypedTensor from the tenferro-tensor crate. The Rust ecosystem also includes alternatives such as ndarray and ndarray-linalg, which are useful when an exercise or external library fits those crates better.

Non-goal: this is not a course where students write every line of code by hand without AI assistance. Code generation and editing are done together with an AI agent. The student’s responsibility is to understand the generated code, review the changes, design checks, run tests, judge whether the result is scientifically correct, give feedback, and if needed improve the code with the AI agent.

This material is not a complete Rust textbook. It is a concept map for the parts of programming, computer systems, numerical computing, and AI-agent workflow that students need in order to work safely on scientific code. Each subsection gives:

How to read this site

Start with Download the material. Then move through the pages in order.

The basic workflow is:

  1. Read the short explanation.
  2. Inspect the concrete syntax or example.
  3. Look up unfamiliar terms.
  4. Solve the exercise by hand.
  5. Use Rust and Cargo when a small coding check helps.
  6. If an AI agent edits files, read the diff and run checks.

For each “Things to look up” list, do not only memorize definitions. Look up the term, then write one sentence in your own words and one example related to scientific computing.

Chapters

  • Section 1: Safe Workflow Before Coding
  • Section 2: Learning with AI and Web Search
  • Section 3: Essential Computer Model
  • Section 4: Rust Basics for Scientific Code
  • Section 5: Correctness and Validation
  • Section 6: Algorithmic Thinking
  • Section 7: Scientific Computing with Rust and tenferro
  • Section 8: Advanced Scientific Topics
  • Section 9: Reproducible Scientific Workflow and Projects