Skip to content

Python API

pepijndevos edited this page Aug 18, 2022 · 12 revisions

pyttoresque

pyttoresque.simserver

This module handles communication with a simulation server. The underlying protocol is described in https://github.com/NyanCAD/SimServer/blob/main/Simulator.capnp

Basic usage of this module:

con = await connect("localhost", simulator=Xyce)
fs = loadFiles(con, "test.cir")
res = fs.commands.run(["V(*)", "I(*)"])
print(await readAll(res))

For streaming plots, have a look at holoviews.streams.Buffer and https://holoviews.org/user_guide/Streaming_Data.html.

connect

async def connect(host, port=5923, simulator=Ngspice, autostart=True)

Connect to a simulation server at the given host:port, which should be a simulator such as Ngspice or Xyce.

If host is set to "localhost" and no server is running, we will attempt to start one automatically, unless autostart=False.

loadFiles

def loadFiles(sim, *names)

Load the specified filenames into the simulation server. The first file is the entrypoint for the simulator. Returns a handle to run simulation commands on.

For in-memory data, directly call sim.loadFiles. The data should be of the form [{"name": name, "contents": contents}]

For files already present on the simulator use sim.loadPath.

read

async def read(response, io=stdout)

Read one chunk from a simulation command

stream

async def stream(response,
                 streamdict,
                 newkey=lambda k: None,
                 io=stdout,
                 suffix="")

Stream simulation data into a Buffer (DataFrame)

streamdict is a dictionary, where Buffers are added as needed. This is done because some simulation commands have multiple results.

The newkey function is called when a new Buffer is added.

Additionally, a custom "file-like" object can be passed for logging, and a suffix can be passed that is appended to the dictionary key.

readAll

async def readAll(response, io=stdout, suffix="")

Read all the simulation data from a simulation command.

pyttoresque.netlist

This module communicates with CouchDB to fetch schematics, and generate SPICE netlists out of them.

Basic usage:

async with SchematicService("http://localhost:5984/offline") as service:
    name = "top$top"
    seq, docs = await service.get_all_schem_docs(name)
    print(spice_netlist(name, docs))

The sequence number can later be used to efficiently update the netlist with update_schem. For live updates, use live_schem_docs.

StatusError Objects

class StatusError(ClientError)

Non-200 response

SchematicService Objects

class SchematicService(AbstractAsyncContextManager)

A context manager for getting schematics from a CouchDB database

__init__

def __init__(url)

Create a HTTP session with the given database URL

dbget

async def dbget(path, **kwargs)

Do a GET request to the given database endpoint and query parameters

dbpost

async def dbpost(path, json, **kwargs)

Do a POST request to the given database endpoint, JSON data, and query parameters

dbput

async def dbput(path, json, **kwargs)

Do a PUT request to the given database endpoint, data, and query parameters

dbstream

async def dbstream(path, json, **kwargs)

Stream data from the given database endpoint, JSON data, and query parameters

get_docs

async def get_docs(name)

Get all the documents with the specified schematic ID

get_all_schem_docs

async def get_all_schem_docs(name)

Recursively get all the documents of the specified schematic and all the subcircuits inside it. And all the model definitions. Returns a sequence number and a dictionary of schematic ID: documents.

update_schem

async def update_schem(seq, schem)

Take a sequence number and dictionary as returned by get_all_schem_docs and update it.

live_schem_docs

async def live_schem_docs(name)

A live stream of updated dictionaries, as returned by get_all_schem_docs

save_simulation

async def save_simulation(name, data)

takes a schematic name and data as populated by pyttoresque.simserver.stream and saves it to the database. Additional keys can be added as the designer sees fit.

netlist

def netlist(docs, models)

Turn a collection of documents as returned by get_docs into a netlist structure. Returns a dictionary of device ID: {port: net} Usage:

async with SchematicService("http://localhost:5984/offline") as service:
    name = "top$top"
    seq, docs = await service.get_all_schem_docs(name)
    print(netlist(docs[name], models))

spice_netlist

def spice_netlist(name,
                  schem,
                  extra="",
                  corner='tt',
                  temp=None,
                  sim="NgSpice",
                  **params)

Generate a spice netlist, taking a dictionary of schematic documents, and the name of the top level schematic. It is possible to pass extra SPICE code and specify the simulation corner.

ngspice_vectors

def ngspice_vectors(name, schem, path=())

Extract all the relevant vectors from the schematic, and format them in NgSpice syntax. Saves label/port net names, and vectors indicated on spice models.

pyttoresque.app.main

pyttoresque.app

pyttoresque.api

pyttoresque.api.examples.blink_multisim

pyttoresque.analysis