changeset 14:ac2ff6be22f7

Take circuit name in top level function. Print command which failed if it does.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 19 Nov 2023 00:05:58 +1030
parents 7cdfaa0b5ad2
children 49592ce7c669
files sim.py
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sim.py	Sat Nov 18 17:57:00 2023 +1030
+++ b/sim.py	Sun Nov 19 00:05:58 2023 +1030
@@ -5,7 +5,7 @@
 from spicelib.log.ltsteps import LTSpiceLogReader
 from spicelib.editor.spice_editor import SpiceEditor
 #from spicelib.sim.sim_runner import SimRunner
-#import shlex
+import shlex
 import sqlite3
 import subprocess
 
@@ -28,7 +28,6 @@
     cmd = [simexe, '-b']
     cmd.extend(simflags)
     cmd.append(runname.name)
-    #print(' '.join(map(shlex.quote, cmd)))
     then = datetime.datetime.now()
     print(f'Starting run {runname} at {then}')
     p = subprocess.Popen(cmd, cwd = rundir)
@@ -37,7 +36,8 @@
     taken = now - then
 
     if p.returncode != 0:
-        raise Exception('failed')
+        print('Run failed: ' + ' '.join(map(shlex.quote, cmd)))
+        return 100000
 
     #rawpath = rundir / runname.with_suffix('.raw')
     #raw = spicelib.RawRead(rawpath)
@@ -91,7 +91,8 @@
     # Check if this combination has already been tried
     dbh = sqlite3.connect(dsn)
     cur = dbh.cursor()
-    cur.execute('SELECT run, power, efficiency, thd, ipeak FROM GAN190 WHERE duty = ? AND c1 = ? AND c2 = ? AND l1 = ? AND l2 = ?', (duty, c1, c2, l1, l2))
+    cur.execute('SELECT run, power, efficiency, thd, ipeak FROM GAN190 WHERE name = ? AND duty = ? AND c1 = ? AND c2 = ? AND l1 = ? AND l2 = ?',
+                (circ, duty, c1, c2, l1, l2))
     tmp = cur.fetchone()
     if tmp is not None:
         run, power, eff, thd, ipeak = tmp
@@ -119,12 +120,12 @@
     taken = taken.seconds + taken.microseconds / 1e6
     cur.execute('BEGIN DEFERRED')
     cur.execute('REPLACE INTO GAN190 (name, run, start, duration, duty, c1, c2, l1, l2, power, efficiency, thd, ipeak, cost) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
-                 (runname, run, then, taken, duty, c1, c2, l1, l2, power, eff, thd, ipeak, cost))
+                 (circ, run, then, taken, duty, c1, c2, l1, l2, power, eff, thd, ipeak, cost))
     cur.execute('COMMIT')
 
     return cost
 
-def ev():
+def ev(circ):
     # Bounds for parameters
     # Note that the parameters are also constrained to be integral
     bounds = [(10, 80),
@@ -159,5 +160,5 @@
 );''')
 
     return differential_evolution(fn, bounds, x0 = x0,
-                                  args = (dsn, '/Users/oconnd1/bin/runltspice', [], 'tmp', 'pa-GAN190-PP-nodriver.net'),
+                                  args = (dsn, '/Users/oconnd1/bin/runltspice', [], 'tmp', circ),
                                   integrality = True, disp = True, seed = 12345, updating = 'deferred', workers = 4)