Package empro :: Package toolkit :: Package analysis :: Package ac :: Module pdn
[frames] | no frames]

Source Code for Module empro.toolkit.analysis.ac.pdn

  1  # Copyright 1983-2017 Keysight Technologies, Inc  
  2   
  3  from empro.toolkit import Bunch 
  4   
5 -def _componentLoopImpedance(setup):
6 return []
7
8 -def optimizeDecap(sipiSetup):
9 """ 10 optimizeDecap(sipiSetup) 11 @type sipiSetup: sipiSetup 12 @param sipiSetup: AC analysis of interest 13 @rtype: Bunch 14 @return: In case of 'success' the list of the 10 best decap configurations taking into account the specified target, the excluded decaps, the desired constraints and the model prices. Otherwise a detailed 'reasonOfFailure' is available. 15 """ 16 import _decap_optimization 17 import empro 18 19 nbTargetSamples = 200 20 targetVector = [] # eg. [[100000.0, 0.007], [1000000.0, 0.007], [1000000.0, 0.02], [10000000.0, 0.02], [10000000.0, 0.06], [30000000.0, 0.06], [30000000.0, 0.3], [100000000.0, 0.3]] 21 excludedDecaps = [] # eg. [C110, C109] 22 constraints = {} # eg. {Models: {RowNr: 2, RelImp: 50.0, CheckBox: true, Name: %23 Models, MaxValue: 3.0}, Vendors: {RowNr: 1, RelImp: 0.0, CheckBox: false, Name: %23 Vendors, MaxValue: 0.0}, Decaps: {RowNr: 0, RelImp: 50.0, CheckBox: true, Name: %23 Decaps, MaxValue: 40.0}, Price: {RowNr: 3, RelImp: 0.0, CheckBox: false, Name: Price, MaxValue: 0.0}} 23 modelInfo = {} # eg. {(group1, name1): 2.1, (group1, name2): 1.0} 24 activeTargetType = "" 25 26 # parse setup's meta data 27 metaData = _decap_optimization.parseMetaData(sipiSetup) 28 if 'TargetInformation' in metaData: 29 if hasattr(metaData['TargetInformation'], 'targetVector'): 30 targetVector = metaData['TargetInformation'].targetVector 31 if hasattr(metaData['TargetInformation'], "activeTargetType"): 32 activeTargetType = metaData["TargetInformation"].activeTargetType 33 if 'ExcludedDecaps' in metaData: 34 for decap in metaData['ExcludedDecaps']: 35 excludedDecaps.append(str(decap)) 36 if 'ConstraintsInformation' in metaData: 37 constraints = metaData['ConstraintsInformation'] 38 if 'ModelAndPriceInformation' in metaData: 39 for storedModelInfo in metaData['ModelAndPriceInformation']: 40 if not 'compGroupName' in storedModelInfo or not 'modelName' in storedModelInfo or not 'Price' in storedModelInfo: 41 continue 42 modelInfoKey = (storedModelInfo['compGroupName'], storedModelInfo['modelName']) 43 modelInfo[modelInfoKey] = Bunch(Price=storedModelInfo['Price']) # mimic the output of ResultsTab.initializeModelInfoDict() but with the price only (we don't need the other properties) 44 # do the optimization 45 bunch = optimizeDecapAssignment(sipiSetup, activeTargetType, targetVector, excludedDecaps, constraints, modelInfo) 46 return bunch
47
48 -def saveOptimizationResult(sipiSetup, result):
49 import _decap_optimization 50 _decap_optimization.OptimizationResultFile.save(sipiSetup, result)
51
52 -def loadOptimizationResult(sipiSetup):
53 import _decap_optimization 54 return _decap_optimization.OptimizationResultFile.load(sipiSetup)
55
56 -def optimizeDecapAssignment(sipiSetup, activeTargetType, targetVector, excludedDecapNames, constraints, priceForModels):
57 """ 58 optimizeDecapAssignment(sipiSetup, activeTargetType, targetVector, excludedDecapNames, constraints, priceForModels) 59 @type sipiSetup: sipiSetup 60 @param sipiSetup: AC analysis of interest 61 @type activeTargetType: string 62 @param activeTargetType: the target type 63 @type targetVector: list 64 @param targetVector: The target mask by specifying each [freq, Z] couple as a list 65 @type excludedDecapNames: list 66 @param excludedDecapNames: Names of the decaps that should not be optimized and will thus be placed and enabled in each solution. 67 @type constraints: list 68 @param constraints: List containing the active constraints, together with their maximum value and relative importance, using the Constraints class (Constraints(type,maximum, importance)) 69 @type priceForModels: dictionary 70 @param priceForModels: Overview of the price of each model in the form of a dictionary where (componentModelGroup name, model name) are used as identifier. 71 @rtype: Bunch 72 @return: In case of 'success' the list of decap configurations taking into account the specified target, the excluded decaps, the desired constraints and the model prices. 'optimizationResult' corresponding OptimizationResult object 73 Otherwise a detailed 'reasonOfFailure' is available. 74 """ 75 optimizationResultBunch = getOptimizedSolutions(sipiSetup, activeTargetType, targetVector, excludedDecapNames) 76 if not optimizationResultBunch.success: 77 return optimizationResultBunch 78 applyConstraintsBunch = applyConstraints(optimizationResultBunch.optimizationResult.unconstrainedResults, constraints, priceForModels) 79 if not applyConstraintsBunch.success: 80 return applyConstraintsBunch 81 applyConstraintsBunch.merge(Bunch(optimizationResult=optimizationResultBunch.optimizationResult)) 82 return applyConstraintsBunch
83 -def getOptimizedSolutions(sipiSetup, activeTargetType, targetVector, excludedDecapNames):
84 """ 85 getOptimizedSolutions(sipiSetup, activeTargetType, targetVector, excludedDecapNames) 86 @type sipiSetup: sipiSetup 87 @param sipiSetup: AC analysis of interest 88 @type activeTargetType: string 89 @param activeTargetType: the target type 90 @type targetVector: list 91 @param targetVector: The target mask by specifying each [freq (Hz), Z (Ohm)] couple as a list 92 @type excludedDecapNames: list 93 @param excludedDecapNames: Names of the decaps that should not be optimized and will thus be placed and enabled in each solution. 94 @rtype: OptimizationResult 95 @return: object with three member variables: List containing all the possible decap configurations taking into account the specified target and excluded decaps, specified target and excluded decaps 96 """ 97 import _decap_optimization 98 (validTarget, reason) = _decap_optimization._validateTargetVector(activeTargetType, targetVector) 99 if not validTarget: 100 return Bunch(success=False, reasonOfFailure = "Failed to run optimization: " + reason) 101 optimizationResult = _decap_optimization.findUnconstrainedOptimalDecapConfigurations(sipiSetup, targetVector, excludedDecapNames) 102 if optimizationResult.unconstrainedResults.status() != 2: 103 return Bunch(success=False, reasonOfFailure = "No solution can be found for the given target and set of excluded decaps: " + optimizationResult.unconstrainedResults.reasonOfFailure()) 104 return Bunch(success=True, optimizationResult=optimizationResult)
105
106 -def applyConstraints(optimizedSolutions, constraints, priceForModels):
107 """ 108 optimizeDecap(optimizedSolutions, constraints, priceForModels) 109 @type optimizedSolutions: list 110 @param optimizedSolutions: List of optimized solutions, availabe after calling getOptimizedSolutions 111 @type constraints: list 112 @param constraints: List containing the active constraints, together with their maximum value and relative importance, using the Constraints class (Constraints(type,maximum, importance)) 113 @type priceForModels: dictionary 114 @param priceForModels: Overview of the price of each model in the form of a dictionary where (componentModelGroup name, model name) are used as identifier. 115 @rtype: Bunch 116 @return: In case of 'success' the list of the 10 best decap configurations for the specified constraints and the model prices, given a set of optimized solutions. Otherwise a detailed 'reasonOfFailure' is available. 117 """ 118 import _decap_optimization 119 if not hasattr(optimizedSolutions, 'status') or not hasattr(optimizedSolutions, 'decapOptimizationResult'): 120 return Bunch(success=False, reasonOfFailure= "Entered optimized solution is not of the correct form!") 121 if optimizedSolutions.status() != 2: 122 return Bunch(success=False, reasonOfFailure= "Entered optimized result does not correspond to a succesful optimization result!") 123 return _decap_optimization.applyConstraints(optimizedSolutions.decapOptimizationResult(), constraints, priceForModels)
124
125 -def getImpedanceGraphOfSolution(solution, targetSpecification, sipiSetup):
126 """ 127 showImpedanceGraphOfSolution(solution, targetSpecification, sipiSetup) 128 @type solution: Bunch 129 @param solution: Single solution obtained after the optimization. 130 @type targetSpecification: list 131 @param targetSpecification: The target mask by specifying each [freq (Hz), Z (Ohm)] couple as a list 132 @type sipiSetup: sipiSetup 133 @param sipiSetup: AC analysis of interest 134 @rtype: Bunch 135 @return: In case of 'success' the graph containing the impedance graph of this specific solution and its improvement wrt the original setup. Otherwise a detailed 'reasonOfFailure' is available. 136 """ 137 import _decap_optimization 138 if not hasattr(solution, 'FullResult'): 139 return Bunch(success=False, reasonOfFailure= "Entered solution is not a correct object!") 140 zGraph = _decap_optimization.getImpedanceGraph(solution.FullResult.decapOptModelAssignment(), sipiSetup, targetSpecification) 141 return Bunch(success=True, graph=zGraph.resultGraph)
142
143 -def printDecapAssignmentOfSolution(solution, priceForModels):
144 """ 145 printDecapAssignmentOfSolution(solution, priceForModels) 146 @type solution: list 147 @param solution: Solution obtained after the optimization. 148 @type priceForModels: dictionary 149 @param priceForModels: Overview of the price of each model in the form of a dictionary where (componentModelGroup name, model name) are used as identifier. 150 @rtype: Bunch 151 @return: In case of 'success' the detailed overview of the decap assignment for the specified solution. Otherwise a detailed 'reasonOfFailure' is available. 152 """ 153 import _decap_optimization 154 if not hasattr(solution, 'FullResult'): 155 return Bunch(success=False, reasonOfFailure= "Entered solution is not a correct object!") 156 detailedAssignment = _decap_optimization.getDetailedDecapAssignment(solution.FullResult.decapOptModelAssignment(), priceForModels) 157 return Bunch(success=True, decapAssignment=detailedAssignment.decapAssignmentDetails)
158
159 -def _clearStoredDecapOptimizationSettings(sipiSetup):
160 """ 161 _clearStoredDecapOptimizationSettings(sipiSetup) 162 @type sipiSetup: sipiSetup 163 @param sipiSetup: AC analysis of interest 164 @return: Removal of the settings stored specific for the Decap Optimization (target impedance, excluded decaps, active constraints and model prices) 165 """ 166 import json 167 sipiSetup.metaData = [str(json.dumps({}))]
168
169 -def _generateReport(sipiSetup, targetSpecification, excludedDecapNames, unconstrainedResults, constraints, priceForModels):
170 """ 171 Give a detailed overview of the optimization that has been performed 172 --> The actual prices and constraints used and their effect on the set of unconstrainedResults 173 --> The actual target used, expressed in Hz and/or MHz 174 --> An overview of all the decaps for which is explicitely mentioned whether they were disabled, excluded or simply disabled by the tool 175 """ 176 pass
177
178 -def _loadDecapOptimizationGui(setup):
179 """ 180 loadDecapOptimizationGui(setup) 181 @type setup: sipiSetup 182 @param setup: AC analysis of interest 183 @rtype: none 184 @return: Gui view of Decap Optimization tool 185 """ 186 import _decap_optimization 187 return _decap_optimization.DecapOptimizationGuiHelper(setup)
188
189 -def _loadDecapOptimizationAsTool():
190 """ 191 loadDecapOptimizationAsTool(setup) 192 @rtype: none 193 @return: [NOT SUPPORTED] Dialog which will allow to select the desired AC analysis available for this workspace. 194 """ 195 pass
196 #import _decap_optimization 197 #print " ** Temp solution: Should present a window to select the desired analysis (currently #1 is set hard-coded)" 198 #return _decap_optimization.startDecapOptimizationTool() 199
200 -def _dummyPorgressCallback(intValue, strValue):
201 return True
202 203 constraintMap = {"Decaps" : 0, "Vendors" : 1, "Models" : 2, "Price" : 3}
204 -class Constraint(object):
205 nbDecaps = 0 206 nbVendors = 1 207 nbModels = 2 208 price = 3
209 - def __init__(self, constrType, maximum, importance):
210 self.constrType = constrType 211 self.maximum = maximum 212 self.importance = importance
213