Analysis API
Placeholder for analysis API docs.
Public analysis helpers for the unified API.
AnalysisResult
dataclass
Lightweight container used by Monte Carlo helpers for legacy traces.
Source code in spicelab/analysis/result.py
9 10 11 12 13 14 | |
ENOBSpec
dataclass
Effective number of bits estimated from SINAD of a sine wave.
ENOB = (SINAD_dB - 1.76) / 6.02
Source code in spicelab/analysis/measure.py
124 125 126 127 128 129 130 131 132 133 134 | |
GainBandwidthSpec
dataclass
Unity-gain frequency for H = numerator/denominator (GBW for open-loop A).
Source code in spicelab/analysis/measure.py
69 70 71 72 73 74 75 | |
GainMarginSpec
dataclass
Gain margin at phase = -180° (mod 360) for H = numerator/denominator.
Returns the classical GM in dB: GM_dB = -20*log10(|H|) evaluated at the
phase-crossing (closest sample to -180° modulo 360). If no sample is within
tolerance_deg of -180°, returns +inf (no crossing within range).
Source code in spicelab/analysis/measure.py
78 79 80 81 82 83 84 85 86 87 88 89 90 | |
GainSpec
dataclass
Measure the small-signal gain at a given frequency.
Source code in spicelab/analysis/measure.py
23 24 25 26 27 28 29 30 31 | |
MonteCarloResult
dataclass
Source code in spicelab/analysis/montecarlo.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
result_handles()
Return the list of ResultHandle objects backing each run (if available).
Source code in spicelab/analysis/montecarlo.py
136 137 138 139 | |
save_manifest_csv(path, *, index=False, **to_csv_kwargs)
Write a small manifest describing the varied parameters to CSV.
The manifest columns are: label, nominal, dist. The manifest is taken from
mapping_manifest populated by the monte_carlo helper when available.
Source code in spicelab/analysis/montecarlo.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
save_samples_csv(path, *, param_prefix='', index=False, **to_csv_kwargs)
Write only the sampled parameters (and trial index) to CSV.
This is a convenience helper that writes the per-trial sampled parameters
(the entries produced when generating the Monte Carlo samples) to a CSV
file. Columns are the sampled parameter names (optionally prefixed) and
the trial column named 'trial'.
Source code in spicelab/analysis/montecarlo.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
to_csv(path, metric=None, *, trial_name='trial', param_prefix='', y=None, sample_at=None, columns=None, index=False, **to_csv_kwargs)
Write the Monte Carlo per-trial table to CSV.
path: output file path (passed to pandas.DataFrame.to_csv).metric,trial_name,param_prefix,y,sample_atare forwarded to :meth:to_dataframeand behave the same.columns: optional sequence of column names to keep (order preserved).index: whether to write the DataFrame index (default False).to_csv_kwargs: additional keyword args passed to pandas.DataFrame.to_csv.
Raises RuntimeError if pandas is not available.
Source code in spicelab/analysis/montecarlo.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
to_dataframe(metric=None, *, trial_name='trial', param_prefix='', y=None, sample_at=None)
Returns a per-trial DataFrame with columns
- trial (index within this Monte Carlo run)
- one column per sampled parameter (from
samples), optionally prefixed - optional metric columns computed from each AnalysisResult
- optional raw trace columns (final value or sampled at
sample_atseconds)
metric
- callable → result stored in column 'metric' (float or scalar)
- mapping name->callable → adds one column per metric name
y: list of trace names to extract values for each run. If sample_at is given,
the value is linearly interpolated at t=sample_at using the run's time axis;
otherwise, the last value in the trace is used.
Source code in spicelab/analysis/montecarlo.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
OvershootSpec
dataclass
Measure peak overshoot relative to a target value.
Source code in spicelab/analysis/measure.py
34 35 36 37 38 39 40 41 42 | |
PhaseMarginSpec
dataclass
Phase margin at unity-gain crossover of H = numerator/denominator.
Returns the classical PM = 180 + angle(H) [deg] at |H| = 1.
Source code in spicelab/analysis/measure.py
57 58 59 60 61 62 63 64 65 66 | |
RiseTimeSpec
dataclass
10-90 (or custom) rise time between threshold crossings.
Computes the time difference between the first crossings of low and high thresholds, where thresholds are defined relative to baseline/reference and target.
Source code in spicelab/analysis/measure.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
SettlingTimeSpec
dataclass
Measure when a signal stays within a tolerance band.
Source code in spicelab/analysis/measure.py
45 46 47 48 49 50 51 52 53 54 | |
Statistics
dataclass
Statistical summary of a set of values.
Source code in spicelab/analysis/stats.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
max
instance-attribute
Maximum value.
mean
instance-attribute
Arithmetic mean.
median
instance-attribute
Median (50th percentile).
min
instance-attribute
Minimum value.
n
instance-attribute
Number of samples.
p1
instance-attribute
1st percentile.
p5
instance-attribute
5th percentile.
p95
instance-attribute
95th percentile.
p99
instance-attribute
99th percentile.
sigma3_high
instance-attribute
Mean + 3*std (upper 3-sigma bound).
sigma3_low
instance-attribute
Mean - 3*std (lower 3-sigma bound).
std
instance-attribute
Standard deviation (sample, n-1 denominator).
cpk(lsl, usl)
Calculate process capability index Cpk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lsl
|
float
|
Lower specification limit. |
required |
usl
|
float
|
Upper specification limit. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cpk value. Higher is better; Cpk >= 1.33 is typically acceptable. |
Source code in spicelab/analysis/stats.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
yield_estimate(lsl, usl)
Estimate yield (fraction within spec limits).
Uses normal distribution assumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lsl
|
float
|
Lower specification limit. |
required |
usl
|
float
|
Upper specification limit. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Estimated yield as fraction (0.0 to 1.0). |
Source code in spicelab/analysis/stats.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
THDSpec
dataclass
Total Harmonic Distortion of a steady-state tone.
Returns THD in percent. Fundamental can be provided (f0); otherwise the dominant bin (ignoring DC) is used. Uses a Hann window by default via FFT helper.
Source code in spicelab/analysis/measure.py
110 111 112 113 114 115 116 117 118 119 120 121 | |
WcaCorner
dataclass
Represents a single corner in the WCA analysis.
Source code in spicelab/analysis/wca.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
combo
instance-attribute
Component ref -> value mapping for this corner.
corner_name = ''
class-attribute
instance-attribute
Human-readable corner name, e.g., 'R1+, R2-'.
corner_signs
instance-attribute
Component ref -> sign (+1 or -1) indicating tolerance direction.
handle
instance-attribute
Result handle for this corner's simulation.
dataset()
Return the xarray Dataset for this corner.
Source code in spicelab/analysis/wca.py
63 64 65 | |
traces()
Return TraceSet for this corner.
Source code in spicelab/analysis/wca.py
67 68 69 | |
WcaResult
dataclass
Result of worst-case analysis.
Contains all corner simulations plus methods to find extremes.
Source code in spicelab/analysis/wca.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
component_labels = field(default_factory=dict)
class-attribute
instance-attribute
Mapping from component ref to display label.
corners
instance-attribute
All evaluated corners (2^n for n components).
nominal_combo
instance-attribute
Nominal values for each component.
nominal_run = None
class-attribute
instance-attribute
The nominal simulation result (optional, run if include_nominal=True).
tolerances
instance-attribute
Tolerance (as fraction) for each component.
all_values(metric)
Evaluate a metric for all corners and return sorted results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[[WcaCorner], float]
|
Function that extracts a scalar from a WcaCorner. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[WcaCorner, float]]
|
List of (corner, value) tuples sorted by value ascending. |
Source code in spicelab/analysis/wca.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
bounds(metric)
Get min, max, and nominal values for a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[[WcaCorner], float]
|
Function that extracts a scalar from a WcaCorner. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (min_value, max_value, nominal_value). |
float
|
nominal_value is None if nominal_run was not included. |
Source code in spicelab/analysis/wca.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
find_extreme(metric, kind='max')
Find the corner that produces the extreme value for a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[[WcaCorner], float]
|
Function that extracts a scalar from a WcaCorner. |
required |
kind
|
Literal['min', 'max']
|
"min" or "max" to find minimum or maximum. |
'max'
|
Returns:
| Type | Description |
|---|---|
WcaCorner
|
The WcaCorner with the extreme metric value. |
Example
Find corner with maximum Vout
def get_vout(corner): ds = corner.dataset() return float(ds['V(vout)'].values[0])
worst = result.find_extreme(get_vout, kind='max')
Source code in spicelab/analysis/wca.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
handles()
Return all result handles.
Source code in spicelab/analysis/wca.py
94 95 96 | |
summary(metric, metric_name='metric')
Generate a summary of the WCA results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[[WcaCorner], float]
|
Function to extract the metric of interest. |
required |
metric_name
|
str
|
Name of the metric for display. |
'metric'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with min, max, nominal, range, and worst corners. |
Source code in spicelab/analysis/wca.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
to_dataframe(metric=None)
Convert results to a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[[WcaCorner], float | dict[str, Any]] | None
|
Optional function to extract metrics from each corner. Can return a single float or a dict of values. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
DataFrame with columns for corner name, component values, |
Any
|
and optional metric values. |
Source code in spicelab/analysis/wca.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
amplitude_spectrum(x, fs, *, win='hann')
Return (freq, |X(f)|) using rfft_coherent.
The magnitude is 2*|FFT|/sum(window) as in rfft_coherent().
Source code in spicelab/analysis/signal.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
compute_stats(values)
Compute comprehensive statistics for a set of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[float]
|
Sequence of numeric values. |
required |
Returns:
| Type | Description |
|---|---|
Statistics
|
Statistics dataclass with all computed metrics. |
Example
values = [1.0, 1.1, 0.9, 1.05, 0.95] stats = compute_stats(values) print(f"Mean: {stats.mean}, Std: {stats.std}")
Source code in spicelab/analysis/stats.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
create_metric_extractor(trace_name, *, index=-1, at_time=None)
Create a reusable metric extractor function.
Useful for passing to MonteCarloResult.to_dataframe() or similar methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_name
|
str
|
Name of the trace. |
required |
index
|
int
|
Index to extract. |
-1
|
at_time
|
float | None
|
Time to interpolate at. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[AnalysisResult], float]
|
A callable that extracts the specified value from an AnalysisResult. |
Example
from spicelab.analysis import monte_carlo, create_metric_extractor
get_vout = create_metric_extractor('V(vout)')
mc_result = monte_carlo(...) df = mc_result.to_dataframe(metric=get_vout)
Source code in spicelab/analysis/stats.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
extract_from_analysis(result, trace_name, **kwargs)
Extract a trace value from an AnalysisResult.
Convenience wrapper around extract_trace_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
AnalysisResult
|
AnalysisResult containing traces. |
required |
trace_name
|
str
|
Name of the trace. |
required |
**kwargs
|
Any
|
Passed to extract_trace_value. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The extracted scalar value. |
Source code in spicelab/analysis/stats.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
extract_trace_value(traces, trace_name, *, index=-1, at_time=None)
Extract a scalar value from a trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traces
|
TraceSet
|
TraceSet containing simulation results. |
required |
trace_name
|
str
|
Name of the trace (e.g., 'V(vout)', 'I(R1)'). Case-insensitive matching is attempted. |
required |
index
|
int
|
Index to extract if at_time is not specified. Default -1 extracts the final value. |
-1
|
at_time
|
float | None
|
If specified, interpolate the value at this time. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The extracted scalar value. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If trace_name is not found (after case-insensitive search). |
Example
Get final Vout from OP analysis
vout = extract_trace_value(traces, 'V(vout)')
Get value at t=1ms from transient
vout_1ms = extract_trace_value(traces, 'V(vout)', at_time=1e-3)
Source code in spicelab/analysis/stats.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
mc_summary(runs, trace_name, *, index=-1, at_time=None, lsl=None, usl=None)
Generate a summary of Monte Carlo results for a specific trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
Sequence[AnalysisResult]
|
List of AnalysisResult from Monte Carlo. |
required |
trace_name
|
str
|
Name of the trace to analyze. |
required |
index
|
int
|
Index to extract from each trace. |
-1
|
at_time
|
float | None
|
If specified, interpolate at this time. |
None
|
lsl
|
float | None
|
Lower specification limit (optional). |
None
|
usl
|
float | None
|
Upper specification limit (optional). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with statistics and optional yield/Cpk metrics. |
Example
from spicelab.analysis import monte_carlo, mc_summary
mc_result = monte_carlo(circuit, mapping, n=1000, analyses=...)
summary = mc_summary( mc_result.runs, 'V(vout)', lsl=2.4, usl=2.6, )
print(f"Mean Vout: {summary['mean']:.4f} V") print(f"Cpk: {summary['cpk']:.2f}") print(f"Estimated yield: {summary['yield_pct']:.2f}%")
Source code in spicelab/analysis/stats.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
measure_job_result(result, specs, *, return_as='python', param_prefix='param_')
Evaluate measurement specs for each run in a JobResult and aggregate rows.
Each output row includes the measurement fields plus the sweep parameters from the
corresponding combo, prefixed by param_prefix (set to None to avoid prefixing).
The return type mirrors :func:spicelab.analysis.measure.measure (polars or list[dict]).
Source code in spicelab/analysis/pipeline.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
monte_carlo(circuit, mapping, n, seed=None, label_fn=None, workers=1, progress=None, *, analyses=None, engine='ngspice', cache_dir='.spicelab_cache', reuse_cache=True)
Executa Monte Carlo variando valores dos componentes conforme distribuições.
Source code in spicelab/analysis/montecarlo.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
power_spectral_density(x, fs, *, win='hann')
Return (freq, PSD) with a simple window-energy normalization.
PSD here is magnitude-squared normalized by ENBW of the window to yield units ~ V^2/Hz.
Source code in spicelab/analysis/signal.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
rfft_coherent(x, fs, *, win='hann')
One-sided FFT with simple coherent gain correction.
Parameters
x: input samples (1D) fs: sample rate in Hz win: window type
Notes
- Applies window and divides by sum(window) to correct coherent gain (CG).
- Returns frequency axis (0..fs/2) and complex spectrum (one-sided, DC..Nyquist).
Source code in spicelab/analysis/signal.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
run_and_measure(job, specs, *, cache_dir='.spicelab_cache', workers=1, reuse_cache=True, return_as='python', param_prefix='param_')
Execute a job with the orchestrator and measure outputs for each combo.
Convenience wrapper around :func:run_job + :func:measure_job_result.
Source code in spicelab/analysis/pipeline.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
run_param_grid(circuit, variables, analyses, *, engine='ngspice', progress=None, cache_dir=None, workers=1, reuse_cache=True)
Run a Cartesian product of component.value assignments.
variables: sequence of (component, values) pairs.
Source code in spicelab/analysis/sweep_grid.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
run_value_sweep(circuit, component, values, analyses, *, engine='ngspice', progress=None, cache_dir=None, workers=1, reuse_cache=True)
Run multiple simulations varying a single component value.
- Mutates component.value for each run; restores the original value at the end.
- Uses the unified engine API (get_simulator().run(...)).
- Returns lightweight handles; you can pull xarray datasets from each when needed.
Source code in spicelab/analysis/sweep_grid.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
run_wca(circuit, tolerances, analyses, *, engine='ngspice', include_nominal=True, label_fn=None, workers=1, progress=None, cache_dir='.spicelab_cache', reuse_cache=True)
Run worst-case analysis varying components to their tolerance extremes.
For n components with tolerances, this runs 2^n simulations (all combinations of +tolerance and -tolerance). This gives the absolute worst-case bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The circuit to analyze. |
required |
tolerances
|
Mapping[Component, float]
|
Mapping from Component -> tolerance as fraction (e.g., 0.01 for 1%). |
required |
analyses
|
Sequence[AnalysisSpec]
|
List of analyses to run (e.g., [AnalysisSpec(mode='op')]). |
required |
engine
|
EngineName
|
Simulation engine to use. |
'ngspice'
|
include_nominal
|
bool
|
If True, also run the nominal case. |
True
|
label_fn
|
Callable[[Component], str] | None
|
Optional function to generate labels for components. |
None
|
workers
|
int
|
Number of parallel workers. |
1
|
progress
|
bool | Callable[[int, int], None] | None
|
Progress callback or True for default progress. |
None
|
cache_dir
|
str | Path | None
|
Directory for caching results. |
'.spicelab_cache'
|
reuse_cache
|
bool
|
Whether to reuse cached results. |
True
|
Returns:
| Type | Description |
|---|---|
WcaResult
|
WcaResult containing all corner simulations. |
Example
tolerances = { resistor1: 0.01, # 1% resistor2: 0.05, # 5% }
result = run_wca( circuit, tolerances=tolerances, analyses=[AnalysisSpec(mode='op')], )
Find worst case for output voltage
def get_vout(corner): return float(corner.dataset()['V(vout)'].values[0])
worst_high = result.find_extreme(get_vout, kind='max') worst_low = result.find_extreme(get_vout, kind='min')
Source code in spicelab/analysis/wca.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
tolerance_to_normal(tolerance, sigma_multiplier=3.0)
Convert a tolerance specification to a NormalPct sigma_pct value.
By default, assumes 3-sigma specification (99.7% of values within tolerance).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Tolerance as fraction (e.g., 0.01 for 1%). |
required |
sigma_multiplier
|
float
|
Number of sigmas that correspond to tolerance. Default 3.0 means 3σ = tolerance. |
3.0
|
Returns:
| Type | Description |
|---|---|
float
|
sigma_pct value for use with NormalPct. |
Example
from spicelab.analysis import NormalPct, tolerance_to_normal
1% tolerance, 3-sigma -> sigma_pct = 0.333%
sigma = tolerance_to_normal(0.01) # returns 0.00333... dist = NormalPct(sigma)
Source code in spicelab/analysis/wca.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
tolerance_to_uniform(tolerance)
Convert a tolerance specification to a UniformPct pct value.
For uniform distribution, the tolerance directly maps to the pct parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Tolerance as fraction (e.g., 0.01 for 1%). |
required |
Returns:
| Type | Description |
|---|---|
float
|
pct value for use with UniformPct. |
Example
from spicelab.analysis import UniformPct, tolerance_to_uniform
1% tolerance -> uniform distribution ±1%
pct = tolerance_to_uniform(0.01) # returns 0.01 dist = UniformPct(pct)
Source code in spicelab/analysis/wca.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
window(n, kind='hann')
Return a window with n points.
- rect: ones
- hann: 0.5 * (1 - cos(2pin/N))
- hamming: 0.54 - 0.46 * cos(2pin/N)
- blackman: 0.42 - 0.5cos(2pin/N) + 0.08cos(4pin/N)
Source code in spicelab/analysis/signal.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |