Package pyspectre

Python interface for Cadence Spectre

Expand source code
""" Python interface for Cadence Spectre """

from collections.abc       import Iterable
from multiprocessing       import cpu_count
from multiprocessing.dummy import Pool
from typing                import Callable, Union
from pandas                import DataFrame
from .                     import core

def _run(num: int, fun: Callable, *args):
    """
    Run function in parallel or not
    """
    num_par = min(num, cpu_count())
    if num > 1:
        with Pool(num_par) as pool:
            res = pool.starmap(fun, zip(*args))
    else:
        res = fun(*args)
    return res

def simulate( net_path: Union[str,Iterable[str]]
            , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
            , raw_path: Union[str,Iterable[str]] = None
            ) -> Union[ dict[str, DataFrame]
                      , Iterable[dict[str, DataFrame]] ]:
    """
    Passes the given netlists to spectre instances and reads the results in.
    """
    num = 1 if isinstance(net_path, str) else len(net_path)
    return _run(num, core.simulate, net_path, includes, raw_path)

def simulate_netlists( netlist: Union[str,Iterable[str]]
                     , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
                     , raw_path: Union[str,Iterable[str]] = None
                     ) -> Union[ dict[str, DataFrame]
                               , Iterable[dict[str, DataFrame]] ]:
    """
    Passes the given netlists to spectre instances and reads the results in.
    """
    num = 1 if isinstance(netlist, str) else len(netlist)
    return _run(num, core.simulate_netlist, netlist, includes, raw_path)

def start_session( net_path: Union[str, Iterable[str]]
                 , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
                 , raw_path: Union[str, Iterable[str]] = None
                 ) -> Union[core.Session, Iterable[core.Session]]:
    """
    Start spectre interactive session(s)
    """
    num = 1 if isinstance(net_path, str) else len(net_path)
    raws = num * [raw_path] if num > 1 else raw_path
    return _run(num, core.start_session, net_path, includes, raws)

def start_n_sessions( net_path: str, includes: Iterable[str] = None
                    , raw_path: str = None, num: int = 1
                    ) -> Iterable[core.Session]:
    """
    Start n parallel sessions with the same netlist
    """
    nets = num * [net_path]
    incs = num * [includes]
    raws = num * [raw_path]
    return start_session(nets, incs, raws)

def run_all( session: Union[core.Session, Iterable[core.Session]]
           ) -> Union[ dict[str, DataFrame]
                     , Iterable[dict[str, DataFrame]] ]:
    """
    Run all simulation analyses
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.run_all, session)

def get_analyses( session: core.Session
                ) -> Union[dict[str, str], Iterable[dict[str, str]]]:
    """
    Retrieve all simulation analyses from current netlist
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.get_analyses, session)

def run_analysis( session: Union[core.Session, Iterable[core.Session]]
                , analysis: Union[str, Iterable[str]]
                ) -> Union[ dict[str, DataFrame]
                          , Iterable[dict[str, DataFrame]] ]:
    """
    Run only the given analysis.
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.run_analysis, session, analysis)

def set_parameters( session: Union[core.Session, Iterable[core.Session]]
                  , params: Union[dict[str, float], Iterable[dict[str, float]]]
                  ) -> Union[bool, Iterable[bool]]:
    """
    Set a list of parameters
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.set_parameters, session, params)

def get_parameters( session: Union[core.Session, Iterable[core.Session]]
                  , params: Union[Iterable[str], Iterable[Iterable[str]]]
                  ) -> Union[dict[str, float], Iterable[dict[str, float]]]:
    """
    Get a parameter in the netlist.
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.get_parameters, session, params)

def stop_session( session: Union[core.Session,Iterable[core.Session]]
                , remove_raw: bool = True
                ) -> Union[bool, Iterable[bool]]:
    """
    Stop spectre interactive session(s)
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    rem  = num * [remove_raw] if num > 1 else remove_raw
    return _run(num, core.stop_session, session, rem)

Sub-modules

pyspectre.core

Python interface for Cadence Spectre

Functions

def get_analyses(session: Session) ‑> Union[dict[str, str], collections.abc.Iterable[dict[str, str]]]

Retrieve all simulation analyses from current netlist

Expand source code
def get_analyses( session: core.Session
                ) -> Union[dict[str, str], Iterable[dict[str, str]]]:
    """
    Retrieve all simulation analyses from current netlist
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.get_analyses, session)
def get_parameters(session: Union[Session, collections.abc.Iterable[Session]], params: Union[collections.abc.Iterable[str], collections.abc.Iterable[collections.abc.Iterable[str]]]) ‑> Union[dict[str, float], collections.abc.Iterable[dict[str, float]]]

Get a parameter in the netlist.

Expand source code
def get_parameters( session: Union[core.Session, Iterable[core.Session]]
                  , params: Union[Iterable[str], Iterable[Iterable[str]]]
                  ) -> Union[dict[str, float], Iterable[dict[str, float]]]:
    """
    Get a parameter in the netlist.
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.get_parameters, session, params)
def run_all(session: Union[Session, collections.abc.Iterable[Session]]) ‑> Union[dict[str, pandas.core.frame.DataFrame], collections.abc.Iterable[dict[str, pandas.core.frame.DataFrame]]]

Run all simulation analyses

Expand source code
def run_all( session: Union[core.Session, Iterable[core.Session]]
           ) -> Union[ dict[str, DataFrame]
                     , Iterable[dict[str, DataFrame]] ]:
    """
    Run all simulation analyses
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.run_all, session)
def run_analysis(session: Union[Session, collections.abc.Iterable[Session]], analysis: Union[str, collections.abc.Iterable[str]]) ‑> Union[dict[str, pandas.core.frame.DataFrame], collections.abc.Iterable[dict[str, pandas.core.frame.DataFrame]]]

Run only the given analysis.

Expand source code
def run_analysis( session: Union[core.Session, Iterable[core.Session]]
                , analysis: Union[str, Iterable[str]]
                ) -> Union[ dict[str, DataFrame]
                          , Iterable[dict[str, DataFrame]] ]:
    """
    Run only the given analysis.
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.run_analysis, session, analysis)
def set_parameters(session: Union[Session, collections.abc.Iterable[Session]], params: Union[dict[str, float], collections.abc.Iterable[dict[str, float]]]) ‑> Union[bool, collections.abc.Iterable[bool]]

Set a list of parameters

Expand source code
def set_parameters( session: Union[core.Session, Iterable[core.Session]]
                  , params: Union[dict[str, float], Iterable[dict[str, float]]]
                  ) -> Union[bool, Iterable[bool]]:
    """
    Set a list of parameters
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    return _run(num, core.set_parameters, session, params)
def simulate(net_path: Union[str, collections.abc.Iterable[str]], includes: Union[collections.abc.Iterable[str], collections.abc.Iterable[collections.abc.Iterable[str]]] = None, raw_path: Union[str, collections.abc.Iterable[str]] = None) ‑> Union[dict[str, pandas.core.frame.DataFrame], collections.abc.Iterable[dict[str, pandas.core.frame.DataFrame]]]

Passes the given netlists to spectre instances and reads the results in.

Expand source code
def simulate( net_path: Union[str,Iterable[str]]
            , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
            , raw_path: Union[str,Iterable[str]] = None
            ) -> Union[ dict[str, DataFrame]
                      , Iterable[dict[str, DataFrame]] ]:
    """
    Passes the given netlists to spectre instances and reads the results in.
    """
    num = 1 if isinstance(net_path, str) else len(net_path)
    return _run(num, core.simulate, net_path, includes, raw_path)
def simulate_netlists(netlist: Union[str, collections.abc.Iterable[str]], includes: Union[collections.abc.Iterable[str], collections.abc.Iterable[collections.abc.Iterable[str]]] = None, raw_path: Union[str, collections.abc.Iterable[str]] = None) ‑> Union[dict[str, pandas.core.frame.DataFrame], collections.abc.Iterable[dict[str, pandas.core.frame.DataFrame]]]

Passes the given netlists to spectre instances and reads the results in.

Expand source code
def simulate_netlists( netlist: Union[str,Iterable[str]]
                     , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
                     , raw_path: Union[str,Iterable[str]] = None
                     ) -> Union[ dict[str, DataFrame]
                               , Iterable[dict[str, DataFrame]] ]:
    """
    Passes the given netlists to spectre instances and reads the results in.
    """
    num = 1 if isinstance(netlist, str) else len(netlist)
    return _run(num, core.simulate_netlist, netlist, includes, raw_path)
def start_n_sessions(net_path: str, includes: collections.abc.Iterable[str] = None, raw_path: str = None, num: int = 1) ‑> collections.abc.Iterable[Session]

Start n parallel sessions with the same netlist

Expand source code
def start_n_sessions( net_path: str, includes: Iterable[str] = None
                    , raw_path: str = None, num: int = 1
                    ) -> Iterable[core.Session]:
    """
    Start n parallel sessions with the same netlist
    """
    nets = num * [net_path]
    incs = num * [includes]
    raws = num * [raw_path]
    return start_session(nets, incs, raws)
def start_session(net_path: Union[str, collections.abc.Iterable[str]], includes: Union[collections.abc.Iterable[str], collections.abc.Iterable[collections.abc.Iterable[str]]] = None, raw_path: Union[str, collections.abc.Iterable[str]] = None) ‑> Union[Session, collections.abc.Iterable[Session]]

Start spectre interactive session(s)

Expand source code
def start_session( net_path: Union[str, Iterable[str]]
                 , includes: Union[Iterable[str], Iterable[Iterable[str]]] = None
                 , raw_path: Union[str, Iterable[str]] = None
                 ) -> Union[core.Session, Iterable[core.Session]]:
    """
    Start spectre interactive session(s)
    """
    num = 1 if isinstance(net_path, str) else len(net_path)
    raws = num * [raw_path] if num > 1 else raw_path
    return _run(num, core.start_session, net_path, includes, raws)
def stop_session(session: Union[Session, collections.abc.Iterable[Session]], remove_raw: bool = True) ‑> Union[bool, collections.abc.Iterable[bool]]

Stop spectre interactive session(s)

Expand source code
def stop_session( session: Union[core.Session,Iterable[core.Session]]
                , remove_raw: bool = True
                ) -> Union[bool, Iterable[bool]]:
    """
    Stop spectre interactive session(s)
    """
    num = 1 if isinstance(session, core.Session) else len(session)
    rem  = num * [remove_raw] if num > 1 else remove_raw
    return _run(num, core.stop_session, session, rem)