timfuz leastsq: write output solution

Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
John McMaster 2018-08-29 14:05:25 -07:00
parent 250e48c7a8
commit f6fb4cb60c
1 changed files with 30 additions and 2 deletions

View File

@ -111,6 +111,34 @@ def run_corner(Anp, b, names, verbose=False, opts={}, meta={}, outfn=None):
print('')
print(res.x)
print('Done')
if outfn:
# ballpark minimum actual observed delay is around 7 (carry chain)
# anything less than one is probably a solver artifact
delta = 0.5
print('Writing resutls')
skips = 0
with open(outfn, 'w') as fout:
# write as one variable per line
# this natively forms a bound if fed into linprog solver
fout.write('ico,fast_max fast_min slow_max slow_min,rows...\n')
for xval, name in zip(res.x, names):
row_ico = 1
# FIXME: only report for the given corner?
# also review ceil vs floor choice for min vs max
# lets be more conservative for now
if xval < delta:
#print('Skipping %s: %0.6f' % (name, xval))
skips += 1
continue
#xvali = round(xval)
xvali = math.ceil(xval)
corners = [xvali for _ in range(4)]
items = [str(row_ico), ' '.join([str(x) for x in corners])]
items.append('%u %s' % (1, name))
fout.write(','.join(items) + '\n')
print('Wrote: skip %u => %u / %u valid delays' % (skips, len(names) - skips, len(names)))
def main():
import argparse
@ -142,7 +170,7 @@ def main():
sub_json = load_sub(args.sub_json)
try:
timfuz_solve.run(run_corner=run_corner, sub_json=sub_json,
timfuz_solve.run(run_corner=run_corner, sub_json=sub_json,
fns_in=fns_in, corner=args.corner, massage=args.massage, outfn=args.out, verbose=args.verbose)
finally:
print('Exiting after %s' % bench)
@ -164,7 +192,7 @@ def test1():
# optimize.leastsq
def test2():
# The function whose square is to be minimised.
# params ... list of parameters tuned to minimise function.
# Further arguments: