I launch and run a single instance of Ngspice, communicating with it via stdio using an instance np of NgspiceProtocol.

Construct me with an instance of Config with any non-default global run-time options set the way you want. Typically, the same Config object is used in my constructor and the constructors of other higher-level objects that may indirectly use me, like ParameterFinder. Similarly, I pass a reference to my own Config object cfg to my NgspiceProtocol and Commander objects when I construct them.

My shutdown method gets called automatically before reactor shutdown.

ParameterstimeoutThe timeout in seconds for my NgspiceProtocol to provide a complete response to any command. The default is 60 seconds but you can set that to whatever you want, or set it to None for infinite patience.
waitingHow long to wait for an Ngspice command to finish before logging a "WAITING..." message in verbose mode. Default is 2 seconds. Set is to None to never log such a message, even in verbose mode.
Instance Variable filePath The file path of a temporary netlist file that Ngspice has sourced. None if Ngspice hasn't sourced anything yet or my Sourcer instance has shut down and removed the file.
Instance Variable employedByAnalyzer True if an instance of analysis.sim.Analyzer has constructed my instance.
Method __init__ NgspiceRunner(cfg, timeout=None, waiting=None)
Method __repr__ Undocumented
Method shutdown Call this to shut me down gracefully, terminating my Ngspice process.
Method cancel Call this to try to interrupt Ngspice. (It doesn't always listen.)
Method call This is the saddle on top of Commander, which does the hard work of Python-Ngspice integration.
Method cnr Ngpice command with no response expected. Returns a Deferred that fires with a Result that contains info about any error.
Method sync Ensures that Ngspice's command-line processor is up to date.
Method source Has Ngspice source and run the netlist in the supplied text, or the netlist file named in the supplied text.
Method memUsage On a proper operating system, returns a Deferred that fires once the Ngspice process is running with its (int) memory usage of my in kilobytes.
Method clearData Sends the simulator a destroy all command to "release the memory holding the output data."
Method option Sets one or more Ngspice options specified as name/value keywords.
Method setting Sets an Ngspice variable name to value, just sets it as a flag if value is True.
Method setSavedVectors Tells Ngspice to discard outputs other than those named in the args and those included in any previous calls to this method.
Method waitForAlterations Call to wait for Ngspice to do all pending alterations. Call with no args to clear pending alterations.
Method alter Alters a device value or parameter in a loaded circuit.
Method altermod Alters a model parameter.
Method show Returns a Deferred that fires with a dict having parameters for the device specified in refDes.
Method showmod Returns a Deferred that fires with a dict having model parameters for the device specified in refDes.
Method get Returns a Deferred that fires with a list containing one or more 1-D numpy arrays containing the values of the specified Ngspice vectors.
Method getVector Returns a Deferred that fires with a single 1-D numpy array containing the values of the specified Ngspice vector.
Method tran Tells Ngspice to run a transient analysis, returning a Deferred to its Result.
Method dc Tells Ngspice to run a DC analysis, returning a Deferred to its Result.
Method ac Tells Ngspice to run a small-signal AC analysis, returning a Deferred to its Result.
Method op Tells Ngspice to run an operating point (OP) analysis, returning a Deferred to its Result.
Method _cmdAndCheckResult Called by tran, ac, and dc with their Ngspice command name and *args to run the Ngspice command and deal with a possible error from it.
filePath =
The file path of a temporary netlist file that Ngspice has sourced. None if Ngspice hasn't sourced anything yet or my Sourcer instance has shut down and removed the file.
employedByAnalyzer =
True if an instance of analysis.sim.Analyzer has constructed my instance.
def __init__(self, cfg, timeout=-1, waiting=None):

NgspiceRunner(cfg, timeout=None, waiting=None)

def __repr__(self):
Undocumented
@defer.inlineCallbacks
def shutdown(self):

Call this to shut me down gracefully, terminating my Ngspice process.

Repeated calls have no effect.

def cancel(self):

Call this to try to interrupt Ngspice. (It doesn't always listen.)

def call(self, *args, **kw):

This is the saddle on top of Commander, which does the hard work of Python-Ngspice integration.

Once the simulator is running, has Commander write a single-line command to the simulator via STDIN by passing the supplied args and kw to my instance of it cmd. Obtains a Deferred that fires with a Result. Returns the Deferred, but first tells my waiter not to shut down before the Deferred fires.

If Ngspice isn't running, the Deferred fires immediately with a Result that has its notRunning flag set.

Specify the number of response lines cmd_N to be received on STDOUT if you know the exact number. If you expect no response (the "set" command produces none, for example), set cmd_N to zero. Don't use cmd_N=None because that indicates you don't know how many lines to expect. cnr does this for you, since it is a fairly common use case.

If cfg.verbose is set, an Ngspice error will cause the error message to be printed.

If cfg.console or the cmd_console keyword is set, an Ngspice error is supposed to drop the user to a command console interacting with Ngspice. (However, this currently doesn't work.)

If cfg.stop or the cmd_stop keyword is set, an Ngspice error will cause Ngspice and pingspice, and all other instances of Ngspice it's running, to shut down.

The keywords listed here are preceded by "cmd_" because any other keywords not beginning with that are converted into <name=val> parameters on the Ngspice command line.

Parameterscmd_NThe number of response lines expected from Ngspice. Set to zero if no response is expected.
cmd_funcA single-argument callable to be called with each line as it arrives. If the callable returns a value (i.e., not None), that value will be appended to the result list instead of the line itself.
cmd_failInstead of the Result, return an instance of twisted.python.failure.Failure with an NgspiceError describing the result on error, even if the cfg.console option is not set.
cmd_consoleSet True to use the error console on error even if the cfg.console option is not set.
cmd_stopSet True to abort on error even if the cfg.stop option is not set.
def cnr(self, *args, **kw):

Ngpice command with no response expected. Returns a Deferred that fires with a Result that contains info about any error.

Shortcut for calling call with the keyword cmd_N set to 0, a fairly common use case.

def sync(self, *args):

Ensures that Ngspice's command-line processor is up to date.

Returns a Deferred that fires with any lines of output left over from previous commands (there should be none) when all pending commands have completed.

Calls NgspiceProtocol.response of my np object with no fixed a number of response lines or STDOUT callback function specified, relying on its use of the echo command and its wait for an echoed response.

Calling this should only be necessary after one or more commands have been sent that don't provide any output, like alter.

Accepts but ignores any arguments supplied, which makes it convenient as a Deferred callback.

@defer.inlineCallbacks
def source(self, netlistFileOrText, **kw):

Has Ngspice source and run the netlist in the supplied text, or the netlist file named in the supplied text.

Returns a Deferred that fires when Ngspice is all ready and has sourced and run the file. If everything went OK, my waiter's 'sourced' event is set, my filePath attribute is set to the file path, and the Deferred fires.

The deferred result is the Result object of the call to Commander.

See Alsosourcery.Sourcer.make.
def memUsage(self):

On a proper operating system, returns a Deferred that fires once the Ngspice process is running with its (int) memory usage of my in kilobytes.

Fires with None if the process is not running.

def clearData(self):

Sends the simulator a destroy all command to "release the memory holding the output data."

Returns a Deferred that fires with a Result that contains info about any error.

Called by analysis.sim.Analyzer.__call__.

def option(self, **kw):

Sets one or more Ngspice options specified as name/value keywords.

Returns a Deferred that fires with a Result that contains info about any error.

def setting(self, name, value):

Sets an Ngspice variable name to value, just sets it as a flag if value is True.

Returns a Deferred that fires with a Result that contains info about any error.

def setSavedVectors(self, *args):

Tells Ngspice to discard outputs other than those named in the args and those included in any previous calls to this method.

Returns a Deferred that fires with a Result that contains the cmd and info about any error.

def waitForAlterations(self, *args):

Call to wait for Ngspice to do all pending alterations. Call with no args to clear pending alterations.

Returns a Deferred that fires when pending alterations have been implemented.

Any arguments supplied are ignored.

def alter(self, dev, *args):

Alters a device value or parameter in a loaded circuit.

Forms:

 alter(dev, expr)  -->  alter dev = expr
 alter(dev, param, expr)  -->  alter dev param = expr

The expr can be a number (float or int) or, for an Ngspice vector, a list of numbers.

Device and parameter names are forced to lowercase to comply with weird case behavior of Ngspice.

Returns a Deferred that fires with a Result that contains info about any error.

def altermod(self, mod, param, expr):

Alters a model parameter.

Device and parameter names are forced to lowercase to comply with weird case behavior of Ngspice.

Returns a Deferred that fires with a Result that contains info about any error.

def show(self, refDes, parameter=None):

Returns a Deferred that fires with a dict having parameters for the device specified in refDes.

If there's an error, the Deferred fires with the Result of the underlying 'show' call instead.

ParametersparameterSpecify a single parameter by name and only its value will be returned, as a float.
def showmod(self, refDes):

Returns a Deferred that fires with a dict having model parameters for the device specified in refDes.

If there's an error, the Deferred fires with the Result of the underlying 'show' call instead.

def get(self, *vectors, **kw):

Returns a Deferred that fires with a list containing one or more 1-D numpy arrays containing the values of the specified Ngspice vectors.

If there was a problem, the Deferred fires with an error-status Result object instead.

See Alsongspice.getter.Getter and its instance callable method __call__.
def getVector(self, vector, **kw):

Returns a Deferred that fires with a single 1-D numpy array containing the values of the specified Ngspice vector.

If there was a problem, the Deferred fires with an error-status Result object instead.

def _cmdAndCheckResult(self, cmdName, *args):

Called by tran, ac, and dc with their Ngspice command name and *args to run the Ngspice command and deal with a possible error from it.

If all went OK, clears the active vectors if the analysis was of a different type or has a different number of samples than the last one run.

Returns a Deferred that fires with the result after it arrives, and after shutting me down if there was an error.

def tran(self, tstep, tstop, *args):

Tells Ngspice to run a transient analysis, returning a Deferred to its Result.

An optional third argument (right after tstop) is tstart. An optional fourth argument (right after tstart) is tmax, a guaranteed maximum computing interval smaller than tstep.

Note that nodes are not vectors. A vector of voltage at node 1 is 'V(1)'.

You can include a 'uic' string at the end of your args if you have set initial conditions in your netlist and want those used instead of having Ngspice calculate initial conditions. See 15.2.2, 15.3.9 of the Ngspice manual.

def dc(self, srcnam, vstart, vstop, vincr, *secondSet):

Tells Ngspice to run a DC analysis, returning a Deferred to its Result.

def ac(self, variation, N, fstart, fstop):

Tells Ngspice to run a small-signal AC analysis, returning a Deferred to its Result.

def op(self):

Tells Ngspice to run an operating point (OP) analysis, returning a Deferred to its Result.

API Documentation for pingspice, generated by pydoctor at 2021-09-18 08:41:11.