Skip to content

Commit

Permalink
flush streams and files before/after optimization (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewu63 authored Jun 5, 2024
1 parent 4ed7ce9 commit 7a33d77
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyoptsparse/pySNOPT/pySNOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
pySNOPT - A variation of the pySNOPT wrapper specifically designed to
work with sparse optimization problems.
"""

# Standard Python modules
import datetime
import os
import re
import sys
import time
from typing import Any, Dict, Optional, Tuple

Expand Down Expand Up @@ -259,6 +261,9 @@ def __call__(
self.startTime = time.time()
self.callCounter = 0
self.storeSens = storeSens
# flush the output streams
sys.stdout.flush()
sys.stderr.flush()

# Store the starting time if the keyword timeLimit is given:
self.timeLimit = timeLimit
Expand Down Expand Up @@ -513,6 +518,8 @@ def __call__(
"pi": pi,
}

self._on_flushFiles()

else: # We are not on the root process so go into waiting loop:
self._waitLoop()
restartDict = None
Expand Down Expand Up @@ -559,10 +566,7 @@ def _userfg_wrap(self, mode, nnJac, x, fobj, gobj, fcon, gcon, nState, cu, iu, r
elif fail == 2:
mode = -2

# Flush the files to the buffer for all the people who like to
# monitor the residual
snopt.pyflush(self.getOption("iPrint"))
snopt.pyflush(self.getOption("iSumm"))
self._on_flushFiles()

# Check if we've exceeded the timeLimit
if self.timeLimit is not None:
Expand Down

0 comments on commit 7a33d77

Please sign in to comment.