pySpice.parser package¶
The functions in this package work to extract information from the SPICE Netlist and store them in internal defined structures. They also collect necessary information for Solver package’s usage
The result of these phase is stored as global varibales in pySpice.global_data module . And will be used through out the whole program
pySpice.parser.parser module¶
-
pySpice.parser.parser.
parser
(netlist)[source]¶ Top-Level Encapsulation for Parsing Utilities
Returns: - element_DICT: A dictionary containing the structure instance representing the circuit elements. With the element’s name as index
- ANALYSIS_LIST: List containing the instance for analysis comands
- SETTING_LIST: List of instance for setting commands
- PRINT_DICT: PRINT/PLOT command are parsed specially into special-designed structures, the instance of these structures are put into this dictionary. The dictionary has three items, with index of dc, ac and tran resepctively. Each item’s value is a list of the print/plot instances
pySpice.parser.parseline module¶
-
pySpice.parser.parseline.
parse_ctrl
(raw_line)[source]¶ Parsing Control Command in SPICE
Parameters: raw_line – a string represent a control command (start with a dot) describe in Netlist Returns: Modify the SETTING_LIST, ANALYSIS_LSIT, PRINT_DICT in global_data
-
pySpice.parser.parseline.
parse_element
(raw_line, node_dim, branch_dim)[source]¶ Parse a Circuit Element
Parameters: - raw_line – a string represent a element describe in Netlist
- node_dim – The upper layer of this function retains a state counting how many node this circuit have. This value is passed into this function and here it decide whether to modify it or not basing on if encounter new nodes
- branch_dim – similar to node_dim, the variabel counting how many linkages should appear in the matrix
Returns: - node_dim
- branch_dim
-
pySpice.parser.parseline.
parse_timefunc
(string)[source]¶ Parsing time-varient source into internal representation
In transient analysis, stimulates may take the form like PULSE, SIN, etc.This sub-utility to parseline function extract these part into designed data structures.
Parameters: string – a slice of the element string like: “SIN(-1 1 1M)” Returns: a instance of the respctive data structure.
pySpice.parser.internalize module¶
-
pySpice.parser.internalize.
internalize
(node_dim)[source]¶ Convert External Node Name to Internal Node Number
While parsing element, the practice of counting the total node number actually has an implicit function to convert the node name used by Netlist into internal representations of continuious integers, which will make it much easier to generate the matrix representing the circuit in solver phase. Essentially, thses integers are the row and coloum number representging that node in the matrix.
However, in parsing, we count node and branch(links between nodes) seperately, but in matrix they are processed as a whole. So this function modifies these number to give them a uniform sequence.
By the way, since we already got the information about the PRINT/PLOT commands, at this stage we also take notes of which nodes/branch’s states are required in generating the final output report. Then we only log the states of these points in the solver phase to reduce intermediate data.
Parameters: node_dim – the total node number of the circuit Returns: Will modify the branch number to form an uniform sequence with node_dim. This will modify the ELEMENT_DICT and add content for the watch_list in global data
pySpice.parser.utils module¶
-
pySpice.parser.utils.
address_transform
(label, node_dim)[source]¶ Transform External Node Name into Internal Node Representation
Basically, it check whether the label has already assigned an internal, if so, it will just return this internal representation. Otherwise, it will generate a new internal node number and plus the total node counter by 1
Parameters: - label – External node name, a string
- node_dim – How many nodes the circuit current have
Returns: The previous node_dim and current node_dim
-
pySpice.parser.utils.
dec_generator
(start, stop, step)[source]¶ Make a python generator based on the parameter. This generator will output data with decimal interval
-
pySpice.parser.utils.
extract
(unit_value)[source]¶ Extrace Spice Format Value
The number used in Netlist often have a postfix unit, this function extrace this representation.
Parameters: unit_value – value represent in SPICE Netlist fashion Returns: value in scientific representation