Few-Shot Spice Electronics Maker

Few-Shot Spice Electronics Maker

by Javantea
April 4-20, 2025

Notebook Python Source code

Electronics learning and development are an underserved market for Generative AI. In a handful of tests, I determined that leaders in the market do not do a good job of creating valid circuits when the information is readily available on the internet. Generative AI has most of the capabilities necessary to achieve this substantial goal of generating valid circuits from description. In this code I use few-shot prompting with hand-written circuits tested by a hobbyist. The project also demonstrates the opportunity to use image understanding in the context without needing a different provider. Indeed in tests, we found it possible to get Gemini to generate a netlist based on an image.

To achieve this goal, I enrolled in the 5-Day Generative AI Intensive Course at Kaggle. Kaggle has an outstanding reputation for high quality courses and competitions. The course is taught with code labs, livestreams, whitepapers, podcast powered by NotebookLM, and a very chaotic discord1. At the end of the course, they offered a badge for anyone completing the Capstone Project. This small reward I thought would be a good use of my time not only because it would serve to convince me to use my creative skill to create a project of value, but would also measure what I can do with the technology.

So let’s get into the details! First off, I tested a lot of things with Gemini and ChatGPT. Both pretended like they knew what they were doing and showed some pretty impressive understanding of Spice. If you’re not familiar with Spice, it’s an electronics simulator. Imagine that you are an electronics hobbyist and you find yourself with a really strange problem. If you ask in a forum, you will find really wise electronics engineers telling you what you should do. If you ask Gemini, ChatGPT, or another LLM, you’ll find an authoritative voice – but one that can’t back it up with actual ability. This gap is very common among LLMs. I don’t know the official term but I think of it as bugs. In the course, we found a lot of very good tools to deal with bugs and we got to see real-world examples of our peers in industry solving those problems.

One of the first tools that seems a lot like magic is few-shot prompting. It indicates that instead of giving your LLM a request, you can give your AI a few examples of the type of thing you want and it will do its best to copy you. Indeed you can get structured output just by showing it that it should never give you supporting information. That’s another tools provided in Day 1 of the course. Think for a moment where that becomes very useful. What if you just want executable circuits? Well this notebook does just that. By modifying the customer_order value, you can get it to give you different circuits. Using the chat feature (which I chose not to implement), you can avoid having to repeatedly tell it the format. This will make it possible to evaluate the LLM’s ability to generate circuits from their description.

So how did Gemini do in our test? Did it generate a debounce circuit? Yes. Surprisingly, it seems to have made a novel circuit from its understanding of capacitors. That’s not to say that you should expect much more from Gemini.

simple debounce circuit with capacitor
* Simple Debounce Circuit with Capacitor

* Components
R1 1 2 10k ; Pull-up resistor
C1 2 0 1uF  ; Debouncing capacitor
V1 1 0 PULSE(0 5 0 10us 10us 1ms 2ms) ; Input voltage source (simulating switch bounce)

* Output Node
.PRINT TRAN V(1) V(2)

* Simulation Control
.TRAN 10us 10ms

.END

Because the Capstone project requires three capabilities, I chose to add Image understanding to my notebook. Instead of putting effort into having Gemini generate a netlist based on an image, I chose to have it do something else. I thought would be a good example of the type of thing that might end up in a project. It was surprisingly easy to write using example code available on the Gemini API documentation. You can see that the output is not bad, but also not nearly state of the art. The image I chose to have it was a screenshot from my playthrough of Broken Age.

Conclusion

So did we do something really exciting? I suppose that in the grand scheme of things, this is just another piece of code that shows how to get improved results from Generative AI. As I work on ngspice I should be able to make use of this prompt to get more from Gemini.

Permalink

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name