10.4.8. Plotting the circuit’s response during optimization

This demo shows how to plot the circuit’s response during optimization. Read chapter Optimizing a circuit to learn more about circuit optimization.

The problem definition in the main file runme.py in folder demo/evaluation/06-iteration-plotter/ is identical to the one in chapter Optimizing a circuit. Only the differences are given in this document.

First we import the the things we need.

from pyopus.evaluator.performance import PerformanceEvaluator, updateAnalysisCount
from pyopus.evaluator.aggregate import *
from pyopus.evaluator.auxfunc import listParamDesc
from pyopus.optimizer import optimizerClass
from pyopus.plotter.evalplotter import EvalPlotter
from pyopus.plotter.optplugin import IterationPlotter
from pyopus.plotter import interface as plt

In the main program we insert an iteration plotter plugin in the optimizer.

	# Performance and cost evaluators
	pe=PerformanceEvaluator(heads, analyses, measures, corners, variables=variables, debug=0)

	# Input parameter order in vector x is defined by inOrder. 
	ce=Aggregator(pe, costDefinition, inOrder, debug=0)

	# Vectors of initial, low, and high values of input parameters. 
	xlow=listParamDesc(costInput, inOrder, "lo")
	xhi=listParamDesc(costInput, inOrder, "hi")
	xinit=listParamDesc(costInput, inOrder, "init")
	# Optimizer (Hooke-Jeeves). xlo and xhi must be numpy arrays. 
	opt=optimizerClass("HookeJeeves")(ce, xlo=xlow, xhi=xhi, maxiter=1+1*1000)

	# Set initial point. Must be a numpy array; xinit is a Python list. 

	# Install reporter plugin. 
	# Print cost. Print performance every time cost is decreased. 

	# Install stopper plugin. 
	# Stop when all requirements are satisfied (all cost contributions are 0). 

	# Plotter
	plotter=EvalPlotter(visualisation, pe)

	# Create and install iteration plotter plugin 

	# Run

	# Optimization result
	# Final evaluation at xresult. 
	plotter("Final result")
	# Print results. 
	print("\n\nFinal cost: "+str(cf)+", found in iter "+str(iterresult)+", total "+str(opt.niter)+" iteration(s)")
	print(ce.formatResults(nMeasureName=10, nCornerName=15))
	print("Performance in corners")
	print(pe.formatResults(outOrder, nMeasureName=10, nCornerName=15))
	# Every call to pe results in the same analysis count. 
	# Therefore we can multiply the analysis count of a single pe call
	# with the number of calls to get the actual analysis count. 
	updateAnalysisCount(acnt, pe.analysisCount, opt.niter+1)
	print("Analysis count: "+str(acnt))
	# Cleanup intemediate files
	# Wait for plot windows to close