Skip to content

idobenamram/spicy

Repository files navigation

Spicy 🌶️🌶️🌶️

Spicy is a small Rust project for running basic circuit simulations using Modified Nodal Analysis (MNA).

Tui example

Crates

  • Parser: see crates/spicy_parser (README)
  • Simulator: see crates/spicy_simulate (README)
  • CLI/TUI: see crates/spicy_cli (README)

Quickstart

  1. Run the TUI on a sample netlist
cargo run -p spicy_cli -- --tui crates/spicy_simulate/tests/op_dc/simple_resistor.spicy

Testing

Run the test suites:

cargo test -p spicy_parser
cargo test -p spicy_simulate

we use cargo-insta for snapshot testing in a lot of the parser tests. to update the snapshot use:

cargo insta review

Fuzzing support exists under fuzz/ (requires cargo-fuzz).

Vibe Coding

A lot of the surrounding code in this project is vibe coded, like:

  1. the binaries klu_mtx.rs klu_solve_cmp, some scripts
  2. spicy_cli, visualizations

Those files are not for the faint of heart, human eyes should not lay eyes on them.

The parser and main simulation code are hand crafted by human intelligence, and only assisted by ai. Those should be readable.

TODO:

Parser

  • output raw files
  • support libs in parser
  • support models in parser
  • add diodes
  • add BJT transistor
  • support underscore in names (maybe we over complicated the lexer)

Simulation

  • implementation of KLU
  • refactor errors and metrics in klu
  • test KLU implementation - [x] make sure the output is bit exact to c - [x] make sure solve close - [x] make sure unroll optimization doesn't lose numerical stability
  • hook up to simulation code
  • cleanup device function use
  • implement basic newton iteration
  • implement diode model
  • implement transistor model
  • support UIC again (using a simulation mode)
  • make from_spec nicer with getting values and defaults somehow
  • creating netlist validation step
  • implement gmin stepping
  • implement source stepping

KLU

  • implement klu statistics and use them to know when to fully factorize the matrix again.
  • implement bench marks for all algorithms and the full algorithms - [x] analyze
  • make sure singular matricies work (when not using halt_if_singular)
  • refactor the functions and structs of KLU (mostly numeric) to something a little nicer
  • support KLU complex?

Optimizations

  • create spicyVec for boundary checks

visualizations

  • merge the recorder macro
  • generate nice visualizations for btf and amd

License

MIT (see LICENSE).

This repository also includes solver code derived from SuiteSparse (AMD/BTF/KLU) under BSD-3-Clause and LGPL-2.1-or-later; see THIRD_PARTY_NOTICES.md.

About

rust implementation of a spice like simulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors