Base class for all subcircuits. You'll use me or my many subclasses a lot.

Construct an instance of me with a reference to an Elements object, which you must have in context from a "with ... as" call to a Netlist object. Then call that instance as many times as you like in the same context (important!) to generate a line referencing the subcircuit. The args for the call are the main-circuit nodes to which the subcircuit nodes defined in nodes are attached. Any keywords supplied define values of your params other than the default.

Define the subcircuit name, nodes, and any parameters with the name, nodes and any params attributes, which may be subclass rather than instance attributes. If name is not defined, the class name will be used, but beware that you cannot construct two instance of me with the same name.

Parameter values will be listed on the "X" subcircuit call in the netlist. They override any global parameters with identical names (Ngspice Manual 2.8.4).

You CANNOT access the values of subcircuit parameters in your subclass's setup method, because the user is free to define them differently in each f.X call, which happen after setup is done. Use a brace expression (e.g., "{xxx}") in your setup method to let Ngspice access the value of a parameter (e.g., xxx=1.23 at simulation time.

Usually a better option than relying on params is to define an instance attribute before setup is called, although this parameterizes a subcircuit's behavior for all calls of the instance. You can define the attribute class-wide in the class definition or with a constructor keyword, although you should still provide a class-wide default definition in your code just to make clear that there will be an attribute-type parameter.

To use an Ngspice netlist file as a subcircuit, e.g., a .CIR file provided by an IC vendor, just specify the circuitFile path as an attribute or in my constructor, and don't write your own setup method. (Or, if you set the useDocstring keyword or class/instance attribute True, put the netlist in your subclass's docstring.) I'll take care of putting the netlist into a subcircuit. You still have to specify the subcircuit's name, nodes, and any params as subclass or instance attributes.

For convenience, you can set attributes of an instance of me with constructor keywords (except for circuitFile). Remember, those are different than keywords supplied to a f.X call, which specify non-default values for subcircuit parameters.

NOTE: You can override a subclass's class-wide params attribute by setting a constructor keyword params to a new dict for just that instance, giving it different default parameter values from other instances of the subclass. Not an especially compelling use case, but it's there.

Class Method export Exports me to an Ngspice-compatible netlist. If a file path is specified (as a single argument), writes the netlist to the file. Otherwise, with no arguments, prints it to STDOUT.
Method __init__ Undocumented
Method avSetup If my pf attribute is not defined or None, sets it to an instance of a param.ParameterFinder subclass. But only if:
Method setup Subcircuit definition.
Method __call__ Call this with some nodes for an instance of your subcircuit to connect to and any parameters whose values you'd like to override from their defaults.
Method _parseSubcktLine Undocumented

Inherited from NodeStuff:

Instance Variable shunts A dict of current sensing V elements with the pairs of nodes they connect.
Class Variable debug A Bag that gets set True for all instances to log info about each setup call.
Class Method autoName Undocumented
Method setupResults Undocumented
Method fill Undocumented
Method nodeCheck Call with the circuit building tool f and a sequence of nodes provided to this Include or Subcircuit.
Method rawNetlist Get lines of a raw netlist from a search hierarchy of possible sources.
Method shunt Call to insert a current-measuring shunt and add an entry to my Elements baton's dict of shunts.
Method raw See Elements.raw.
Method iNode See Elements.iNode.
Method ground See Elements.ground.
Method sca See Elements.sca.
Method sca6 See Elements.sca6.
Class Method _libDir Undocumented
Method _strippedLines Undocumented
Method _call_setup Calls my setup method (almost always your override of that method, actually) and processes any return value.
@classmethod
def export(cls, *filePathArg, **kw):

Exports me to an Ngspice-compatible netlist. If a file path is specified (as a single argument), writes the netlist to the file. Otherwise, with no arguments, prints it to STDOUT.

With keywords, you can override default values of pingspice-only simulation options defined in PS_Options. In particular, you'll want to make sure that the value of ts (in seconds) is appropriate for the transient analyses you plan to run. It may be worthwhile to export several copies of the subcircuit to different files for different values of ts.

def __init__(self, f, **kw):
Undocumented
def _parseSubcktLine(self, line):
Undocumented
def avSetup(self):

If my pf attribute is not defined or None, sets it to an instance of a param.ParameterFinder subclass. But only if:

  1. My Finder attribute references a param.ParameterFinder subclass, with
  2. its Setups attribute properly referencing a param.Setups subclass. And
  3. My finderParams attribute is defined and not None. It must reference a dict of param names and values, or a string that I can parse into such a dict.

Otherwise, pf is not set.

def __call__(self, *nodes, **params):

Call this with some nodes for an instance of your subcircuit to connect to and any parameters whose values you'd like to override from their defaults.

If the number of nodes is less than what I was constructed with, "nc_" nodes will be appended as needed, with, presumably, no connections made to them.

There must not be any parameters other than what I was constructed with.

Before doing the f.X call, calls any functions in my callbacks list with f and a dict of the subcircuit parameters. If the callbacks list contains a string, it must name an attribute of my instance that can be called that way. The purpose of any such calls is to add one or more circuit elements, and/or to modify subcircuit parameters, outside the subcircuit before adding the subcircuit "X" device. Nothing in pingspice actually uses this capability, and it's not tested.

Returns a reference to my instance.

A Note about "Instances"

A subcircuit "instance," as the term is used here, is simply a defined group of elements that Ngspice copies into its netlist when it encounters an "X" device. It's not the same as an instance of a Python class.

You can have several different instances of me or a subclass of me, each having their own set of attribute values, and each of those can be called repeatedly to produce several different Ngspice subcircuit instances. See examples.boost.Boost.setup for an example of this flexibility being used to generate a complex circuit.

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