Contents
Circuit Element Parameter Change
Circuit Element Parameter Change
Uses the MWO built-in example project, LPF_Lumped.emp. This example modifies the inductance value of one of the inductors in the circuit schematic and then simulates.
''' pyawr_utils example for circuit schematics Open MWO built-in example LPF_Lumped.emp ''' from pyawr_utils import awrde_utils #Import pyawr_uilts module awrde = awrde_utils.establish_link() #Establish link between Python and AWRDE Project = awrde_utils.Project(awrde) #Assign object variable to Project class # ProjectName = Project.project_name #Get name of currently open project print(ProjectName) # circuit_schmatics_name_list = Project.circuit_schematics_name_list #Get list of schematic names print(circuit_schmatics_name_list) # circuit_schematics_dict = Project.circuit_schematics_dict #Get dictionary of schematics schem = circuit_schematics_dict['LPF'] #Assign schematic object print(schem.circuit_schematic_name) #Selected schematic name # element_name_list = schem.element_names_list #Get list of element names print(element_name_list) # elements_dict = schem.elements_dict #Get dictionary of element in selected schematic elem = elements_dict[element_name_list[4]] #Assign element object # param_name_list = elem.parameter_names_list #Get list of parameter names print(param_name_list) # params = elem.parameters_dict #Get dictionary of parameters for the selected element Inductance_str = params['L'].value_str #Get parameter value as string print(Inductance_str) params['L'].value_str = '25' #Set parameter value as string Project.simulate_analyze() #Simulate
Graphing Example
Uses the MWO built-in example project, LPF_Lumped.emp. This example adds a new graph, sets the graph axis limits, adds a marker, reads the marker value, and reads trace data. This example requires matplotlib module.
''' pyawr_utils example for graphing Open MWO built-in example LPF_Lumped.emp Required Python modules: matplotlib ''' # from pyawr_utils import awrde_utils #Import pyawr_uilts module import matplotlib.pyplot as plt # awrde = awrde_utils.establish_link() #Establish link between Python and AWRDE Project = awrde_utils.Project(awrde) #Assign object variable to Project class # Project.add_rectangular_graph('s21') #Add rectangular graph # graph_name_list = Project.graph_name_list #Get list of graph names print(graph_name_list) # graphs_dict = Project.graph_dict #Get dictionary of graphs graph = graphs_dict['s21'] #Set graph object variable print(graph.graph_name) #Print graph name to confirm print(graph.graph_type) #Print graph type # graph.add_measurement('LPF','DB(|S(2,1)|)') #Add measurement to graph # Project.simulate_analyze() #Simulate # print(graph.axes_name_list) #Print axis names axes_dict = graph.axes_dict #Get dictionary of graph axes axis = axes_dict['Left1'] #Set axis object variable for left y-axis axis.axis_minimum_scale = -40 #Set minimum y-axis scale to -40 dB axis.axis_grid_step = 5 #Set y-axis step size to 5 dB/div # graph.add_marker('LPF:DB(|S(2,1)|)', 500e6) #Add marker to graph at x-axis value of 500 MHz marker_dict = graph.markers_dict #Get dictionary of markers marker = marker_dict[0] #Set marker object variable print(marker.marker_measurement) #Print measurement associated with marker print(marker.marker_data_text) #Print marker text print(marker.marker_data_value_x) #Print marker x-xis value in base units print(marker.marker_data_value_y1) #Print marker y-xis value # meas_dict = graph.measurements_dict #Get measurements dictionary meas = meas_dict[0] #Set measurement object trace_data_list = meas.trace_data #Read trace data trace_data_ay = trace_data_list[0] plt.figure() #Setup plot Xdata = trace_data_ay[:,0] Ydata = trace_data_ay[:,1] plt.plot(Xdata, Ydata) #Plot data plt.show() #Display plot #
SWPVAR Example
Uses the MWO built-in example project, LPF_Lumped.emp. This example adds an equation, adds a SWPVAR element, and plots a multiple trace measurement. This example requires matplotlib module.
''' pyawr_utils example for using SWPVAR with graphing Open MWO built-in example LPF_Lumped.emp Required Python modules: matplotlib ''' # from pyawr_utils import awrde_utils #Import pyawr_uilts module import matplotlib.pyplot as plt # awrde = awrde_utils.establish_link() #Establish link between Python and AWRDE Project = awrde_utils.Project(awrde) #Assign object variable to Project class # circuit_schematics_dict = Project.circuit_schematics_dict #Get dictionary of schematics schem = circuit_schematics_dict['LPF'] #Assign schematic object # schem.add_equation('L2','Variable definition','31.9', -300, -800) #Add equation L2 = 31.9 elem_dict = schem.elements_dict #Get element dictonary elem = elem_dict['INDQ.L2'] #Set element object param_dict = elem.parameters_dict #Get parameter dictionary param = param_dict['L'] #Set parameter object param.value_str = 'L2' #Change parameter value # schem.add_element('SWPVAR', -300, -1500) #Add SWPVAR element elem = elem_dict['SWPVAR.SWP1'] #Set element object param_dict = elem.parameters_dict #Get parameter dictionary param = param_dict['VarName'] #Update SWPVAR VarName param.value_str ='"L2"' param = param_dict['Values'] #Update SWPVAR Values param.value_str ='{25,30,35}' # Project.add_rectangular_graph('s21') #Add rectangular graph graphs_dict = Project.graph_dict #Get dictionary of graphs graph = graphs_dict['s21'] #Set graph object variable # graph.add_measurement('LPF','DB(|S(2,1)|)') #Add measurement to graph meas_dict = graph.measurements_dict #Get measurements dictionary meas = meas_dict[0] #Set measurement object # Project.simulate_analyze() #Simulate # print(meas.num_traces) #Number of traces associated with measurement trace_info_list = meas.sweep_var_trace_info #Print trace information for trace_info_dict in trace_info_list: for sweep_var_name, sweep_var_value in trace_info_dict.items(): print(sweep_var_name, ' : ',sweep_var_value) #end for print('') #end for # trace_data_list = meas.trace_data #Plot all traces plt.figure() plt.grid(True, linestyle=':') for trace_data_ay in trace_data_list: Xdata = trace_data_ay[:,0] Ydata = trace_data_ay[:,1] plt.plot(Xdata, Ydata) #end for plt.show() # print('') print('Done . . . ')
Optimization Example
Uses the MWO built-in example project, LPF_Lumped.emp. This example sets up variables for optimization, adds optimization goal and then performs an optimization.
''' pyawr_utils example for using Optimization Open MWO built-in example LPF_Lumped.emp ''' # from pyawr_utils import awrde_utils #Import pyawr_uilts module import time # awrde = awrde_utils.establish_link() #Establish link between Python and AWRDE Project = awrde_utils.Project(awrde) #Assign object variable to Project class # circuit_schematics_dict = Project.circuit_schematics_dict #Get dictionary of schematics schem = circuit_schematics_dict['LPF'] #Assign schematic object elements_dict = schem.elements_dict #Get dictionary of element in selected schematic elem = elements_dict['INDQ.L4'] #Assign element object params = elem.parameters_dict #Get dictionary of parameters for the selected element param = params['Q'] #Assign parameter object # param.optimize_enabled = True #Enable parameter for optimization param.constrain = True #Enable constriants param.lower_constraint = 90 #Set lower constraint param.upper_constraint = 110 #Set upper constraint param.step_size = 1 #Set constraint step size # opt_var_dict = Project.optimization_variables_dict #Get dictionary of all variables setup for optimization Project.print_optimization_variables(opt_var_dict) #Print the opt variables dictionary # active_meas_list = Project.get_all_active_measurements #Get list of all active measurements Project.add_optimization_goal(active_meas_list[1], '<', (600e6, 700e6), (-10, -25), 1,2) #Add goal # opt_goals_dict = Project.optimization_goals_dict #Get dictionary of all the goals for goal in opt_goals_dict.values(): #Print goal parameters print('goal name: ', goal.goal_name) print('goal type: ', goal.goal_type) print('goal xrange: ', goal.goal_xrange) print('goal_yrange: ', goal.goal_yrange) print('goal weight: ', goal.goal_weight) print('goal L Factor: ',goal.goal_l_factor) print('goal measurement name: ',goal.goal_measurement_name) print('goal source document: ',goal.goal_source_document) print('') #end for # opt_type_list = Project.optimization_type_list #Get list of optimization types available for type_name in opt_type_list: print(type_name) #end for #Project.optimization_type = opt_type_list[3] #Set optimization type print(Project.optimization_type) #Confirm optimization type Project.optimization_max_iterations = 100 #Set max iterations Project.optimization_show_all_iterations = True #Show all iterations Project.optimization_stop_at_minimum_error = True #Stop on min error Project.optimization_cancel_on_stop_request = True #Stop on cancel request Project.optimization_log_to_file = True #Output optimization results to log file # Project.optimization_start = True #Start optimization OptimizationRunning = Project.optimization_start while OptimizationRunning: #Monitor optimization running state time.sleep(0.5) OptimizationRunning = Project.optimization_start #end while # print(Project.optimization_cost, Project.optimization_best_cost) #Print optimization costs