DC Sensitivity Analysis#
Compute sensitivity of DC operating point to device parameters.
import os
import sys
from pathlib import Path
# Set working directory to the PDK root if running from scripts/
if Path.cwd().name == "scripts":
os.chdir(Path.cwd().parent)
# Ensure ngspice shared library can be found (macOS homebrew)
if sys.platform == "darwin" and "/opt/homebrew/lib" not in os.environ.get(
"DYLD_LIBRARY_PATH", ""
):
os.environ["DYLD_LIBRARY_PATH"] = "/opt/homebrew/lib:" + os.environ.get(
"DYLD_LIBRARY_PATH", ""
)
import numpy as np
from nyancad.watch import watch_project_dir, file_schematic
from nyancad.netlist import inspice_netlist
from InSpice import Simulator
Parameters#
SCHEMATIC = "rcfilter" # stem of the .nyancir file
CORNER = "mos_tt"
# -- DC sensitivity parameters --
OUTPUT_VAR = "v(P2)" # output variable to analyze sensitivity for
Load schematic and build netlist#
project = watch_project_dir(".")
schem_data = await file_schematic(project, SCHEMATIC)
spice = await inspice_netlist(SCHEMATIC, schem_data, corner=CORNER)
print(spice)
.title schematic
VV1 net0 GND DC 0 AC 1
CC1 P2 net0 1u
RR1 P2 GND 1k
Run DC sensitivity analysis#
simulator = Simulator.factory(simulator="ngspice-shared")
for osdi in [
"ihp/models/ngspice/osdi/psp103.osdi",
"ihp/models/ngspice/osdi/psp103_nqs.osdi",
"ihp/models/ngspice/osdi/r3_cmc.osdi",
"ihp/models/ngspice/osdi/mosvar.osdi",
]:
simulator._ngspice_shared.exec_command(f"osdi {osdi}")
simulation = simulator.simulation(spice)
analysis = simulation.dc_sensitivity(
output_variable=OUTPUT_VAR,
)
print("DC sensitivity analysis complete.")
Warning: can't find the initialization file spinit.
Newer Ngspice version that could be unsupported 46
DC sensitivity analysis complete.
Results#
print(f"DC sensitivity of {OUTPUT_VAR}:")
for key in analysis.nodes.keys():
val = np.array(analysis[key]).item()
if abs(val) > 1e-12:
print(f" {key} = {val:.6g}")
DC sensitivity of v(P2):