pdkmaster.io.spice package

pdkmaster.io.spice.spice_

This module contains support for direct SPICE input and output.

class pdkmaster.io.spice.spice_.SpicePrimsParamSpec[source]

Bases: Dict[_DevicePrimitive, Dict[str, Any]]

SpicePrimsParamSpec is a structure to declare extra parameters related to DevicePrimitiveT object of a technology that are needed specifically to generate SPICE/PySpice circuits.

This class is used by first generating an empty object and then adding SPICE parameters for primitives using the add_device_params() method.

add_device_params(*, prim: Resistor, model: str | None = None, is_subcircuit: bool | None = False, subcircuit_paramalias: Dict[str, str] | None = None, sheetres: float | None = None)[source]
add_device_params(*, prim: MIMCapacitor | Diode, model: str | None = None, is_subcircuit: bool | None = True, subcircuit_paramalias: Dict[str, str] | None = None)
add_device_params(*, prim: MOSFET, model: str | None = None, is_subcircuit: bool | None = False)
add_device_params(*, prim: Bipolar, model: str | None = None, is_subcircuit: bool | None = False)

The add_device_params() method is called at most once for each device primitive one wants to add params for. The params that can be specified depend on the device primitive type.

Parameters:
  • model

    alternative model name for use in SPICE circuit.

    By default the name of the primitive is also used as the SPICE model name

  • is_subcircuit

    wether the model is a SPICE subcircuit or element

    Default is True for a MIMCapacitor and False for the other device primitives.

  • subcircuit_paramalias (for Resistor, MIMCapacitor and Diode) –

    alias for parameters for the subcircuit model.

    This value is a dict that specifies the alias for the parameters of the primitive. The keys the names of the parameter for the DevicePrimitiveT the values the name of the parameter used by the SPICE subcircuit.

    Either no parameter has to be specified are all of them. It may not be specified when is_subcircuit is False.

    Default values:

    • for Resistor: {"width": "w", "length": "l"},

    • for MIMCapacitor: {"width": "w", "height": "h"},

    • for Diode: {"width": "w", "height": "h"},

  • sheetres (for Resistor) – the sheet resistance for the Resistor primitive

pdkmaster.io.spice.pyspice

This module allows to convert PDKMaster based circuits into PySpice circuits.

Currently PDKMaster only supports to create circuits with primitives from the technology and does not allow to also SPICE generic elements like a generic resistor or capacitance. This means that these elements need to be added to the circuit after they have been converted to PySpice.

This is planned to be tackled in #40

API Notes

  • This module is WIP and has no stable API; backwards compatibility may be broken at any time.

class pdkmaster.io.spice.pyspice.PySpiceFactory(*, libfile: str, corners: Iterable[str], conflicts: Dict[str, Tuple[str, ...]], prims_params: SpicePrimsParamSpec)[source]

Bases: object

The PySpiceFactory allows to convert _Circuit objects generated through CircuitFactory object to PySpice circuits and sub circuits.

Typically the PDK provider will also provide a PySpiceFactory object that allows to convert to PySpice objects that use the SPICE simulation files provided by the PDK.

Parameters:
  • libfile – the full path to the SPICE lib file to include in the generated SPICE objects

  • corners – A list of valid corners for this lib file.

  • conflicts

    For a given corner it gives the conrers with which it conflicts, e.g. if you have:

    "typ": ("ff", "ss"),

    as an element in the dict it means that you can’t specify "typ" corner with the "ff" and "ss" corner.

  • prims_params – extra parameters for the models of DevicePrimitiveT object. See SpicePrimsParamSpec for more information.

API Notes

  • The API of PySpiceFactory is in flux and no backwards compatiblity guarantees are given at this moment.

new_pyspicecircuit(*, corner: str | Iterable[str], top: _Circuit, subckts: Iterable[_Circuit] | None = None, title: str | None = None, gnd: str | None = None)[source]

This method converts a PDKMaster _Circuit object to a PySpice Circuit object.

The returned object type is actually a cubclass of the PySpice Circuit class.

Parameters:
  • corner – The corner(s) valid for the Circuit. This needs to be a valid corner as specified during PySpiceFactory init.

  • top – The top circuit for the generated PySpice Circuit object. The top circuit will be included in the PySpice Circuit as a subcircuit and then instantiated as Xtop. For each of the pins a net in the SPICE top level will be generated with the same name.

  • subckts – An optional list of subcircuits. These will be included in the generated object as PySpice subcircuits. If not provided a list will be generated hierarchically from the given top Circuit.

  • title – An optional title to set in the generated PySpice object.

  • gnd – An optional name of the ground net name in the circuit.

new_pyspicesubcircuit(*, circuit: _Circuit, lvs: bool = False)[source]

This method convert a PDKMaster _Circuit object to a PySpice SubCircuit object.

The returned object type is actually a subclass of the PySpice SubCircuit class.

Parameters:
  • circuit – The circuit to make a PySpice Circuit for.

  • lvs – wether to generate a subcircuit for (klayout) based. lvs generated circuit may use other device primitive in the generated netlists than the other ones that are mainly to be used in simulation.