I'm wondering how can I obtain output files from SLSQP optimizer in openmdao, like those from pyOpt? I've tried with JSONCaseRecorder, but it didn't show me what the optimizer is really doing during each iteration. I'm using python 2.7 and openmdao 0.12.0. Thanks in advance!

asked 04 Aug '15, 18:25

SYY's gravatar image

SYY
122

Could you post some sample code showing us what you are attempting to do?

(05 Aug '15, 06:35) justingray ♦♦ justingray's gravatar image

I think the best you can do is crank up the iprint on your SLSQP driver to its maximum setting. Then it will print some information to stdout. Unfortunately, it doesn't really give the detailed output that pyopt/SNOPT does, but it does give something each iteration.

EDIT -- Though you can use a recorder to record your model executions (so, design vars and obj/constraints each iteration). Is that what you want?

link

answered 05 Aug '15, 09:47

Kenneth%20T%20Moore's gravatar image

Kenneth T Moore ♦
1.1k1212

edited 05 Aug '15, 09:53

Thanks for the prompt reply! My goal is to use openmdao to optimize a RC aircraft design. The problem is that the design does not change much after some iterations, but the program keeps running for a very long time(hours!). I'd like to obtain outputs from SLSQP to debug.

I'm new to openmdao, and here's how i set up the problem:

from openmdao.lib.datatypes.api import FileRef
from openmdao.lib.casehandlers.api import DumpCaseRecorder,JSONCaseRecorder
from openmdao.main.api import Assembly
from openmdao.lib.drivers.api import SLSQPdriver
from geometry import Geometry
from weights import Weights
from Avl_Aero import Avl_Aero
from drag_model import total_drag
from performance import performance
from post_process import post_process
import time
import os
import numpy
import math
import sys
from openmdao.lib.datatypes.api import File, Array, Float,Int

class Constrained_MDO(Assembly):

    b_w = Float(3,iotype='in', desc='Wing Span [m]')
    b_h = Float(1,iotype='in', desc='horizontal Wing Span [m]')
    b_v = Float(0.5,iotype='in', desc='vertical Wing Span [m]')
    fuselage_front = Float(0.1,iotype='in', desc='front fuslage length [m]')
    twist = Float(0,iotype='in', desc='Twist Angle, Pitch Up Positive [degrees]')
    offset_x_hr = Float(2,iotype='in', desc='offset from origin to horizontal/vertical tail leading edge (root)[m]')
    offset_x_ht = Float(2,iotype='in', desc='offset from origin to horizontal tail leading edge (tip) [m]')
    offset_x_vt = Float(2,iotype='in', desc='offset from origin to vertical tail leading edge (tip) [m]')   
    c_r = Float(0.5,iotype='in', desc='Wing Chord [m]')   
    c_r_h = Float(0.3,iotype='in', desc='Horizontal Stabilizer Root Chord [m]') 
    c_t_h =  Float(0.2,iotype='in', desc='Horizontal Stabilizer tip chord length [m]')
    c_t_v = Float(0.2,iotype='in', desc='vertical Stabilizer tip Chord [m]') 
    c_r_v = Float(0.3,iotype='in', desc='vertical Stabilizer Root Chord [m]')               
    f_h = Float(0.1,iotype='in',desc='front fuselage height/width [m]')
    f_h_b = Float(0.05,iotype='in',desc='back fuselage height/width [m]')       
    mass_payload_lb = Float(14,iotype='in', desc='payload mass [lb]')

    def configure(self):

        # Create Optimizer instance
        self.add('driver',SLSQPdriver())
        self.driver.gradient_options.force_fd = True

        # Create AVL component
        self.add('geometry', Geometry())
        self.add('weight', Weights())
        self.add('aerodynamics', Avl_Aero(n=31, m=16, k = 14, p = 22))
        self.add('drag', total_drag(31))
        self.add('performance', performance(31))

        # Iteration Hierarchy
        self.driver.workflow.add(['geometry','weight','aerodynamics','drag','performance'])

        # Design Variables
        self.driver.add_parameter(('b_w'),low=2,high=5)
        self.driver.add_parameter(('b_h'),low=0.1, high = 2)
        self.driver.add_parameter(('b_v'),low=0.1, high = 2)    
        self.driver.add_parameter(('twist'),low=-5, high =5)
        self.driver.add_parameter(('fuselage_front'),low=0.05, high =1) 
        self.driver.add_parameter(('offset_x_hr'),low=0.1, high = 5)
        self.driver.add_parameter(('offset_x_ht'),low=0.1, high = 5)
        self.driver.add_parameter(('offset_x_vt'),low=0.1, high = 5)
        self.driver.add_parameter(('c_r'),low=0.1, high = 1.5)
        self.driver.add_parameter(('c_r_h'),low=0.01, high = 1.5)
        self.driver.add_parameter(('c_t_h'),low=0.01, high = 1.5)
        self.driver.add_parameter(('c_t_v'),low=0.01, high = 1.5)
        self.driver.add_parameter(('c_r_v'),low=0.01, high = 1.5)   
        self.driver.add_parameter(('f_h'),low=0.05, high = 1)
        self.driver.add_parameter(('f_h_b'),low=0.01, high = 1) 
        self.driver.add_parameter(('mass_payload_lb'),low=12, high = 18)

        # Add Connections(design variables)

        self.connect('b_w',['geometry.b_w','weight.b_w'])
        self.connect('b_h',['geometry.b_h','weight.b_h'])
        self.connect('b_v',['geometry.b_v','weight.b_v'])   
        self.connect('fuselage_front',['geometry.fuselage_front','weight.fuselage_front'])  
        self.connect('twist','geometry.twist')  
        self.connect('offset_x_hr',['geometry.offset_x_hr','weight.offset_x_hr'])
        self.connect('offset_x_ht',['geometry.offset_x_ht','weight.offset_x_ht'])   
        self.connect('offset_x_vt',['geometry.offset_x_vt','weight.offset_x_vt'])   
        self.connect('c_r',['geometry.c_r','weight.c_r'])   
        self.connect('c_r_h',['geometry.c_r_h','weight.c_r_h']) 
        self.connect('c_t_h',['geometry.c_t_h','weight.c_t_h']) 
        self.connect('c_t_v',['geometry.c_t_v','weight.c_t_v'])     
        self.connect('c_r_v',['geometry.c_r_v','weight.c_r_v'])
        self.connect('f_h',['geometry.f_h','weight.f_h'])   
        self.connect('f_h_b',['geometry.f_h_b','weight.f_h_b'])
        self.connect('mass_payload_lb','weight.mass_payload_lb')

        # Add Connections (Weights Module)
        self.connect('geometry.S_v','weight.S_v')
        self.connect('geometry.S_h','weight.S_h')
        self.connect('geometry.Sref','weight.Sref')
        self.connect('geometry.SA_fuse','weight.SA_fuse')
        self.connect('geometry.x_cg','weight.x_cg')         
        self.connect('geometry.Lf','weight.Lf')     
        self.connect('geometry.MAC_h','weight.MAC_h')

        # Add Connections (Aerodynamics Module)
        self.connect('geometry.avl_file','aerodynamics.avl_geo_file')
        self.connect('geometry.Sref','aerodynamics.Sref')
        self.connect('geometry.MAC','aerodynamics.MAC') 
        self.connect('weight.mass','aerodynamics.weight')
        self.connect('weight.output_file','aerodynamics.avl_mass_file')

        # Add Connections (Drag Module)
        self.connect('geometry.AR','drag.AR')
        self.connect('geometry.Sref','drag.Sref')
        self.connect('geometry.S_h','drag.S_h')
        self.connect('geometry.S_v','drag.S_v')
        self.connect('geometry.SA_fuse','drag.SA_fuse')
        self.connect('geometry.MAC','drag.MAC')
        self.connect('geometry.MAC_h','drag.MAC_h')
        self.connect('geometry.MAC_v','drag.MAC_v')
        self.connect('geometry.Lf','drag.Lf')
        self.connect('geometry.d_eq','drag.d_eq')   
        self.connect('geometry.b_v','drag.b_v')         
        self.connect('aerodynamics.alpha', 'drag.alpha')
        self.connect('aerodynamics.C_l', 'drag.CL')
        self.connect('aerodynamics.C_d', 'drag.CD')
        self.connect('aerodynamics.velocity', 'drag.velocity')      
        self.connect('aerodynamics.e_invsc','drag.ei')
        self.connect('aerodynamics.Cl_y','drag.Cl_y')
        self.connect('aerodynamics.y_sec_h','drag.y_sec_h')
        self.connect('aerodynamics.y_sect','drag.y_sect')
        self.connect('aerodynamics.ai','drag.ai')
        self.connect('aerodynamics.ai_h','drag.ai_h')   
        self.connect('aerodynamics.ai_v','drag.ai_v')

        # Add Connections (performance Module)
        self.connect('drag.cd_total','performance.cd_total')        
        self.connect('weight.mass','performance.mass')
        self.connect('geometry.Sref','performance.Sref')            
        self.connect('aerodynamics.C_l','performance.CL')   
        self.connect('aerodynamics.alpha','performance.alpha')      
        self.connect('aerodynamics.velocity','performance.velocity')
        self.connect('aerodynamics.cl_stall','performance.cl_stall')            
        self.connect('drag.drag_total','performance.drag_total')

        # Objective Function
        self.driver.add_objective('-weight.score')

        # Add Constraints (Performance & Stability)
        self.driver.add_constraint('geometry.S_v < 0.045*geometry.Sref')
        self.driver.add_constraint('geometry.S_v > 0.04*geometry.Sref')
        self.driver.add_constraint('geometry.c_v < 0.05')
        self.driver.add_constraint('geometry.c_v > 0.02')   
        self.driver.add_constraint('geometry.c_h < 0.6')
        self.driver.add_constraint('geometry.c_h > 0.3')
        self.driver.add_constraint('b_w > b_v')
        self.driver.add_constraint('b_w > b_h')
        self.driver.add_constraint('b_h > b_v') 
        self.driver.add_constraint('geometry.AR < 8')
        self.driver.add_constraint('geometry.AR > 3.5')
        self.driver.add_constraint('geometry.AR_h < 5')
        self.driver.add_constraint('geometry.AR_h > 4')     
        self.driver.add_constraint('geometry.AR_v < 1.8')
        self.driver.add_constraint('geometry.AR_v > 1.2')   
        self.driver.add_constraint('geometry.lambda_v < 0.6')
        self.driver.add_constraint('geometry.lambda_v > 0.4')                                   
        self.driver.add_constraint('aerodynamics.Cm_alpha < 0')
        self.driver.add_constraint('(aerodynamics.Xnp - geometry.x_cg)/geometry.MAC < 0.15')
        self.driver.add_constraint('(aerodynamics.Xnp - geometry.x_cg)/geometry.MAC > 0.05')
        self.driver.add_constraint('aerodynamics.Cl_beta < 0')
        self.driver.add_constraint('aerodynamics.Cn_beta > 0')      
        self.driver.add_constraint('fuselage_front + c_r < offset_x_hr')
        self.driver.add_constraint('c_r > c_r_h')
        self.driver.add_constraint('c_r > c_r_v')
        self.driver.add_constraint('c_r_h > c_t_h')
        self.driver.add_constraint('c_r_v > c_t_v')
        self.driver.add_constraint('weight.score<=1')
        self.driver.add_constraint('weight.s2>0')   
        self.driver.add_constraint('weight.s3>0')               
        self.driver.add_constraint('weight.s2<=1')  
        self.driver.add_constraint('weight.s3<=1')                              
        self.driver.add_constraint('weight.mass_payload_lb>= 12')
        self.driver.add_constraint('weight.mass_payload_lb< 18')
        self.driver.add_constraint('weight.mass_empty_lb<12')
        self.driver.add_constraint('offset_x_hr<=offset_x_ht')
        self.driver.add_constraint('offset_x_hr<=offset_x_vt')

        # Record Output & Verbosity of the Optimizer
        self.driver.iprint = 0
        self.recorders = [JSONCaseRecorder('results.json')]
        self.driver.maxiter = 1000
link

answered 06 Aug '15, 11:20

SYY's gravatar image

SYY
122

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×39
×3

Asked: 04 Aug '15, 18:25

Seen: 1,406 times

Last updated: 06 Aug '15, 11:20

powered by OSQA