-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathramp.py
More file actions
101 lines (85 loc) · 2.86 KB
/
ramp.py
File metadata and controls
101 lines (85 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
# Copyright 2013 DEVSIM LLC
#
# SPDX-License-Identifier: Apache-2.0
import devsim as ds
from devsim.python_packages.simple_physics import GetContactBiasName, PrintCurrents
def rampbias(
device,
contact,
end_bias,
step_size,
min_step,
max_iter,
rel_error,
abs_error,
callback,
):
"""
Ramps bias with assignable callback function
Uses devsim.get_parameter to get the bias currently at the contact being ramped.
Parameters:
-----------
device : name of the device
contact : contact name
end_bias : bias for last step
step_size : initial step size
min_step : minimum step size
max_iter : maximum number of iterations
rel_error : required relative error for convergence
abs_error : required absolute error for convergence
callback : callback function that should be called on success.
See printAllCurrents for an example.
Description:
------------
Uses GetContactBiasName to get the bias being applied at the contact specified.
On each successfull bias, the callback function is called.
Exceptions are raised if there is a failure at the last bias step attempted.
"""
start_bias = ds.get_parameter(device=device, name=GetContactBiasName(contact))
if start_bias < end_bias:
step_sign = 1
else:
step_sign = -1
step_size = abs(step_size)
last_bias = start_bias
while abs(last_bias - end_bias) > min_step:
print(("%s last end %e %e") % (contact, last_bias, end_bias))
next_bias = last_bias + step_sign * step_size
if next_bias < end_bias:
next_step_sign = 1
else:
next_step_sign = -1
if next_step_sign != step_sign:
next_bias = end_bias
print("setting to last bias %e" % (end_bias))
print("setting next bias %e" % (next_bias))
ds.set_parameter(
device=device, name=GetContactBiasName(contact), value=next_bias
)
try:
ds.solve(
type="dc",
absolute_error=abs_error,
relative_error=rel_error,
maximum_iterations=max_iter,
)
except ds.error as msg:
if str(msg).find("Convergence failure") != 0:
raise
ds.set_parameter(
device=device, name=GetContactBiasName(contact), value=last_bias
)
step_size *= 0.5
print("setting new step size %e" % (step_size))
if step_size < min_step:
raise RuntimeError("Minimum step size too small")
continue
print("Succeeded")
last_bias = next_bias
callback(device)
def printAllCurrents(device):
"""
Prints all contact currents on device
"""
for c in ds.get_contact_list(device=device):
PrintCurrents(device, c)