Ejemplo n.º 1
0
def simulation(sim_vec, targets, do_plot=False):
	'''
	perform a single simulation programatically.

	@input: simulation_vector - a vector of all simulation variables
	@return: a cost value related to the fitness function defined internally		
	'''
	

	dv = {"Rbias1": str(sim_vec[0]),
		"Rbias2": str(sim_vec[1]),
		"Rfb": str(sim_vec[2])
		}
	open(TMP_CIRCUIT_FILE,"wt").write(template.safe_substitute(dv))
	os.system("ngspice -b %s >/dev/null 2>/dev/null"%(TMP_CIRCUIT_FILE))
	#os.system("ngspice -b %s "%(TMP_CIRCUIT_FILE))	

	p = spice_read.spice_read(RESULTS_FILE).get_plots()[0]
	time = p.get_scalevector().get_data()
	utp = p.get_datavector(2).get_data()[0]
	ltp = p.get_datavector(3).get_data()[0]
	results = {'utp': utp, 'ltp':ltp}
	cost = fitness(results, targets)


	#plot and print results
	if do_plot:
		print "Simulation Inputs"
		print "Rbias1: %s; Rbias2: %s; Rfb: %s"%(str(sim_vec[0]), str(sim_vec[1]), str(sim_vec[2]))
		print
		print "Simulation Results"
		print "Upper Trip Point: %sV"%(str(utp))
		print "Lower Trip Point: %sV"%(str(ltp))
		print
		print "Cost: %s"%(str(cost))
		vin = p.get_datavector(0)
		vout = p.get_datavector(1)
		
		plot(time, vin.get_data(), label=vin.name)
		plot(time, vout.get_data(), label=vout.name)
		text(0, 3.5, "Rbias1: %.2e"%(float(dv["Rbias1"])), bbox={'facecolor':'red', 'alpha':0.9})
		text(0, 3.3, "Rbias2: %.2e"%(float(dv["Rbias2"])), bbox={'facecolor':'red', 'alpha':0.9})
		text(0, 3.1, "Rfb: %.2e"%(float(dv["Rfb"])), bbox={'facecolor':'red', 'alpha':0.9})
		text(0, 2.9, "UTP: %.2fV"%(float(results["utp"])), bbox={'facecolor':'blue', 'alpha':0.9},color='white')
		text(0, 2.7, "LTP: %.2fV"%(float(results["ltp"])), bbox={'facecolor':'blue', 'alpha':0.9},color='white')
		title("Schmitt Trigger Results")
		grid()
		legend()
		savefig("./img/schmitt.trigger.atuogen.png")
		close()
	
	return cost
Ejemplo n.º 2
0
    help="Spice DC margin vector")
parser.add_argument('-M', '--margin', type=str,
    help="Spice margin vector")

parser.add_argument('-S', '--start', default='0', type=str,
    help="Simulation start time")

parser.add_argument('-n', '--number', default=10, type=int,
    help="Number of violations to print (-1 for all)")

violations = dict()
slacks = dict()
worst = dict()

args = parser.parse_args()
vectors = spice_read.spice_read(args.input).get_plots()[0]

if args.violation:
    violations["Spec"] = []
    violation = get_vector(vectors, args.violation)
time_vector = vectors.get_scalevector().get_data()

rising_clock = None
falling_clock = None

if args.rising:
    rising_clock = get_vector(vectors, args.rising)
    if args.falling or args.both:
        raise Exception("Specify only one clock")
elif args.falling:
    falling_clock = get_vector(vectors, args.falling)
Ejemplo n.º 3
0
        options['verbose'] = True
    elif k in ('-o', '--outfile'):
        options['outfile'] = v
    elif k in ('-p', '--pathprefix'):
        options['pathprefix'] = v
    elif k in ('-f', '--format'):
        if v not in FORMAT_OPTIONS:
            usage()
            sys.exit(2)
        options['format'] = v

## now execute the commands
args.sort()
for infile in args:
    filename = os.path.basename(infile)
    plots = spice_read.spice_read(infile).get_plots()
    path = options['pathprefix']
    if len(args) > 1:
        ## need to add the filename as path
        path = path + '/' + filename

    if len(plots) > 1:
        ## need to add a plot number to the path
        for i, p in enumerate(plots):
            insert_spiceplot(p, path=path, name="plot_%i"%i,
                             outfile=options['outfile'], format=options['format'])
    else:
        toks = path.split('/')
        if len(toks) == 2:
            path = '/'
        else:
Ejemplo n.º 4
0
def __parse_file(infile):
    plots = spice_read.spice_read(infile).get_plots()
    return __read_spiceplot(plots[0])
Ejemplo n.º 5
0
        options['verbose'] = True
    elif k in ('-o', '--outfile'):
        options['outfile'] = v
    elif k in ('-p', '--pathprefix'):
        options['pathprefix'] = v
    elif k in ('-f', '--format'):
        if v not in FORMAT_OPTIONS:
            usage()
            sys.exit(2)
        options['format'] = v

## now execute the commands
args.sort()
for infile in args:
    filename = os.path.basename(infile)
    plots = spice_read.spice_read(infile).get_plots()
    path = options['pathprefix']
    if len(args) > 1:
        ## need to add the filename as path
        path = path + '/' + filename

    if len(plots) > 1:
        ## need to add a plot number to the path
        for i, p in enumerate(plots):
            insert_spiceplot(p,
                             path=path,
                             name="plot_%i" % i,
                             outfile=options['outfile'],
                             format=options['format'])
    else:
        toks = path.split('/')