Example #1
0
def exportOcp(ocp, CXX):
    # write the ocp exporter cpp file
    genfiles = [('export_ocp.cpp', writeAcadoOcpExport.generateAcadoOcp(ocp)),
                ('Makefile',makeMakefile(CXX))]
    exportpath = memoizeFiles(genfiles)

    # compile the ocp exporter
    p = subprocess.Popen(['make'], stdout=subprocess.PIPE, cwd=exportpath)
    ret = p.wait()
    if ret != 0:
        print "stdout: "+p.stdout.read()
        raise Exception("integrator compilation failed, return code "+str(ret))
    
    # load the ocp exporter
    Ni = 5
    print os.path.join(exportpath, 'export_ocp.so')
    lib = ctypes.cdll.LoadLibrary(os.path.join(exportpath, 'export_ocp.so'))
    
    # run the ocp exporter
    def runOcpExporter(path):
        ret = lib.exportOcp(ocp._nk,
                            Ni,
                            ctypes.c_double(ocp._ts),
                            ctypes.c_char_p(path))
        if ret != 0:
            raise Exception("call to export_ocp.so failed")
    files = withTempdir(runOcpExporter)
    print "exported files: "+str([name for (name,_) in files])
Example #2
0
def runPhase1(ocp, phase1Options, integratorOptions, ocpOptions):
    # write the ocp exporter cpp file
    genfiles = {
        'export_ocp.cpp':
        writeAcadoOcpExport.generateAcadoOcp(ocp, integratorOptions,
                                             ocpOptions),
        'Makefile':
        makeExportMakefile(phase1Options)
    }
    # add a file which just runs the export in the current directory
    genfiles['run_export.cpp'] = '''\
extern "C" int exportOcp(const char * exportDir);

int main(void){
    return exportOcp(".");
}
'''
    exportpath = codegen.memoizeFiles(genfiles,
                                      prefix=phase1Options['hashPrefix'] +
                                      '_phase1__')

    # compile the ocp exporter
    (ret, msgs) = subprocess_tee.call(['make', codegen.makeJobs()],
                                      cwd=exportpath)
    if ret != 0:
        raise Exception("exportOcp phase 1 compilation failed:\n\n" + msgs)

    # run the ocp exporter
    def runOcpExporter(path):

        lib = ctypes.cdll.LoadLibrary(os.path.join(exportpath,
                                                   'export_ocp.so'))

        ret = lib.exportOcp(ctypes.c_char_p(path))

        if ret != 0:
            print open(os.path.join(path, '_stdout.txt')).read()
            raise Exception("call to export_ocp.so failed")

    def callExporterInProcess(q):
        try:
            q.put(codegen.withTempdir(runOcpExporter))
        finally:
            q.put(None)

    q = Queue()

    p = Process(target=callExporterInProcess, args=(q, ))
    p.start()
    ret = q.get()
    p.join()

    assert (0 == p.exitcode) and (ret is not None), \
        "error exporting ocp, see stdout/stderr above"

    return ret
Example #3
0
def runPhase1(ocp, phase1Options, integratorOptions, ocpOptions):
    # write the ocp exporter cpp file
    genfiles = {'export_ocp.cpp': writeAcadoOcpExport.generateAcadoOcp(ocp, integratorOptions, ocpOptions),
                'Makefile': makeExportMakefile(phase1Options)}
    # add a file which just runs the export in the current directory
    genfiles['run_export.cpp'] = '''\
extern "C" int exportOcp(const char * exportDir);

int main(void){
    return exportOcp(".");
}
'''
    exportpath = codegen.memoizeFiles(genfiles,prefix=phase1Options['hashPrefix']+'_phase1__')

    # compile the ocp exporter
    (ret, msgs) = subprocess_tee.call(['make',codegen.makeJobs()], cwd=exportpath)
    if ret != 0:
        raise Exception("exportOcp phase 1 compilation failed:\n\n"+msgs)

    # run the ocp exporter
    def runOcpExporter(path):
        
        lib = ctypes.cdll.LoadLibrary(os.path.join(exportpath, 'export_ocp.so'))

        ret = lib.exportOcp(ctypes.c_char_p(path))
        
        if ret != 0:
            print open(os.path.join(path, '_stdout.txt')).read()
            raise Exception("call to export_ocp.so failed")

    def callExporterInProcess(q):
        try:
            q.put(codegen.withTempdir(runOcpExporter))
        finally:
            q.put(None)
            
    q = Queue()
    
    p = Process(target = callExporterInProcess, args=(q, ))
    p.start()
    ret = q.get()
    p.join()
    
    assert (0 == p.exitcode) and (ret is not None), \
        "error exporting ocp, see stdout/stderr above"

    return ret