Skip to content

Commit

Permalink
Closes #1493 - Fix Conjugated Gradient (#1494)
Browse files Browse the repository at this point in the history
* Closes #1493

* removed print statement

* minor other fixes

* restart civet

* Fixed issue #1520. Closes #1520

* Closes #1521

* Update plugin_handler.py

* Update GradientDescent.py

* Update step.tex

Co-authored-by: Andrea Alfonsi <andrea.alfonsi86@gmail.com>
  • Loading branch information
alfoa and aalfonsi authored Oct 13, 2021
1 parent b62160f commit 4c1a360
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 44 deletions.
17 changes: 8 additions & 9 deletions doc/user_manual/step.tex
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ \section{Steps}
%\item \textbf{Function.} The Function role is extremely important, for example, when performing Adaptive Sampling to represent the metric of the transition regions. This role is the role used, for example, to collapse information coming from a Model.
\item \textbf{ROM} defines an acceleration Reduced Order Model to use for a
\textbf{Step}.
\item \textbf{SolutionExport} represents the container of the eventual output
of a step. For the moment, there are two uses: 1) A \textbf{Step} is employing the
search of the Limit Surface (LS), through the class of Adaptive \textbf{Samplers}); in this case, it
contains the coordinates of the LS in the input space; and 2) Some of the post-processors
employ clustering algorithms and the cluster centers will be stored in this file
with the input being the cluster labels.
\item \textbf{SolutionExport} the DataObject to store solutions from Optimizer or Sampler execution
in a Step. For example, a LimitSurfaceSearch Sampler outputs the coordinates of the limit surface;
similarly, an Optimizer outputs the convergence history and optimal points.
See specific Samplers and Optimizers for details.
\end{itemize}
Depending on the \textbf{Step} type, different combinations of these roles can
be used.
Expand Down Expand Up @@ -324,9 +322,10 @@ \subsection{MultiRun}
supported.
\end{itemize}
\nb For Multi-Run, either one \xmlNode{Sampler} or one \xmlNode{Optimizer} is required.
\item \xmlNode{SolutionExport}, \xmlDesc{string, optional parameter} identifies
\item \xmlNode{SolutionExport}, \xmlDesc{string, optional (Sampler) or required (Optimizer) parameter} identifies
an entity to be used for exporting key information coming from the
\textbf{Sampler} or \textbf{Optimizer} object during the simulation.
\textbf{Sampler} or \textbf{Optimizer} object during the simulation. This node is \textbf{Required}
when an \textbf{Optimizer} is used.
This XML node accepts the following attributes:
\begin{itemize}
\item \xmlAttr{class}, \xmlDesc{required string attribute}, main object class
Expand All @@ -342,7 +341,7 @@ \subsection{MultiRun}
\xmlString{HistorySet}, etc. \\
\nb Whether or not it is possible to export the \textbf{Sampler} solution
depends on the \xmlAttr{type}.
Currently, only the Samplers in the \xmlString{Adaptive} category and all Optimizers can
Currently, only the Samplers in the \xmlString{Adaptive} category and all Optimizers will
export their solution into a \xmlNode{SolutionExport} entity. For Samplers, the \xmlNode{Outputs} node
in the \texttt{DataObjects} needs to contain the goal \xmlNode{Function} name.
For example, if \xmlNode{Sampler} is of type \xmlString{Adaptive}, the
Expand Down
3 changes: 3 additions & 0 deletions framework/Optimizers/Optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ def initialize(self, externalSeeding=None, solutionExport=None):
@ In, solutionExport, DataObject, optional, a PointSet to hold the solution
@ Out, None
"""
if solutionExport is None:
self.raiseAnError(IOError, 'Optimizers require a SolutionExport DataObject. Please add a <SolutionExport> node in the Step!')

AdaptiveSampler.initialize(self, externalSeeding=externalSeeding, solutionExport=solutionExport)
# functional constraints
for entry in self.assemblerDict.get('Constraint', []):
Expand Down
5 changes: 3 additions & 2 deletions framework/Optimizers/stepManipulators/ConjugateGradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Step size manipulations based on gradient history
Created 2020-01
@author: zhoujia
@author: zhoujia, alfoa
"""
#for future compatibility with Python 3--------------------------------------------------------------
from __future__ import division, print_function, unicode_literals, absolute_import
Expand Down Expand Up @@ -381,7 +381,7 @@ def _startLineSearch(self, lastStepInfo, curPoint, curObjVal, curGrad, curGradMa
# since we've accepted a pivot, we need to store the old pivot and set up the new one
## first grab the savable params
pivot = lastStepInfo.pop('pivot', None)
if True: #pivot is None:
if pivot is None:
# ONLY RUN ONCE per trajectory! First time ever initialization of line step search
# use the current gradient to back-guess the would-be previous objective value
prevObjVal = curObjVal + curGradMag / 2 # oldOldFVal
Expand Down Expand Up @@ -416,6 +416,7 @@ def _startLineSearch(self, lastStepInfo, curPoint, curObjVal, curGrad, curGradMa
'task': b'START',
'persistence': 0,
})

return lastStepInfo

def _lineSearchStep(self, lastStepInfo, curObjVal):
Expand Down
3 changes: 3 additions & 0 deletions scripts/plugin_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def tellPluginAboutRaven(loc):
root.append(ravenLoc)
ravenFrameworkLoc = os.path.abspath(os.path.expanduser(frameworkDir))
if ravenLoc.text != ravenFrameworkLoc:
# we write only in case the location is either different or the file
# is not present (so, only one processor in case of RAVENrunningRAVEN
# will write the file if not present
ravenLoc.text = ravenFrameworkLoc
xmlUtils.toFile(configFile, root)
return ravenLoc.text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
x,y,const,ans,stepSize,iteration,accepted,conv_gradient,CG_task
2.0,2.0,3.14,356.703125,0.0707106781187,0.0,first,0.0,START
1.70384856647,1.03439432043,3.14,15.9212745395,0.0010237121002,1.0,accepted,0.0,FG
1.68396247804,0.024590109959,3.14,1.22747253369,0.0191548452521,2.0,accepted,0.0,CONV
2.68430410873,0.163933649094,3.14,0.687335505932,0.365356000259,3.0,accepted,0.0,CONV
2.29686751933,0.10996530078,3.14,0.406302738346,0.22385205969,4.0,accepted,0.0,FG
2.15357470297,1.10974886175,3.14,22.230291568,0.407893933481,5.0,accepted,0.0,CONV
2.26891300147,0.305009742761,3.14,0.219630681419,0.0795746677073,6.0,accepted,0.0,FG
3.10231242954,-0.265556110843,3.14,6.57423877541,0.788449441735,7.0,accepted,0.0,CONV
2.34256081143,0.254588631177,3.14,0.167215297471,0.0696755633535,8.0,accepted,0.0,FG
2.71968775918,0.968056572725,3.14,11.948524954,1.0,9.0,accepted,0.0,CONV
2.40652071771,0.375591235064,3.14,0.153189838403,0.169597814898,10.0,accepted,0.0,FG
2.37537558076,0.31666928084,3.14,0.133560833837,0.0870125285916,11.0,accepted,0.0,FG
3.0414638977,0.106816981281,3.14,2.22313229993,1.0,12.0,accepted,0.0,CONV
2.43941639613,0.296493108957,3.14,0.109428785572,0.0961446308932,13.0,accepted,0.0,FG
2.66410541694,0.948735049198,3.14,10.7939300676,1.0,14.0,accepted,0.0,CONV
2.46869910464,0.381496864579,3.14,0.106556702209,0.130325497914,15.0,accepted,0.0,FG
2.45384798749,0.338386073355,3.14,0.0920803288159,0.0642291791029,16.0,accepted,0.0,FG
2.93747884866,0.246660713527,3.14,0.8391234392,1.0,17.0,accepted,0.0,CONV
2.51378774788,0.327017906988,3.14,0.0764374355558,0.12393700486,18.0,accepted,0.0,FG
2.64633505333,0.939973786934,3.14,10.3064978399,1.0,19.0,accepted,0.0,CONV
2.52707899351,0.388482356485,3.14,0.0734924266129,0.100275487204,20.0,accepted,0.0,FG
2.52049337598,0.358027622012,3.14,0.0651900295807,0.0505904520017,21.0,accepted,0.0,FG
2.87967661904,0.330560120705,3.14,0.30492053052,1.0,22.0,accepted,0.0,CONV
2.58494445739,0.353098911675,3.14,0.0534855680247,0.179437884858,23.0,accepted,0.0,FG
2.63038806468,0.970974768765,3.14,12.2069760027,1.0,24.0,accepted,0.0,CONV
2.58959501013,0.41633034135,3.14,0.061477097246,0.102336786507,25.0,accepted,0.0,FG
2.58691364225,0.379873013895,3.14,0.0445463485377,0.0433324945671,26.0,accepted,0.0,FG
2.85912618114,0.367445817834,3.14,0.15349268709,1.0,27.0,accepted,0.0,CONV
2.64188025153,0.377363648114,3.14,0.0368975580255,0.201925339283,28.0,accepted,0.0,FG
2.67533820576,0.897152304938,3.14,8.02636575518,1.0,29.0,accepted,0.0,CONV
2.64365331073,0.404909147687,3.14,0.0315434192087,0.0529936527308,30.0,accepted,0.0,FG
2.91691595088,0.221471238942,3.14,0.936421806112,1.0,31.0,accepted,0.0,CONV
2.65740997523,0.395674465023,3.14,0.0287763942695,0.0503422805448,32.0,accepted,0.0,FG
2.79096989782,0.585403569673,3.14,0.445384679984,1.0,33.0,accepted,0.0,CONV
2.79096989782,0.585403569673,3.14,0.445384679984,1.0,33.0,final,0.0,CONV
1.44680123895,-4.5,3.14,18020.2080624,0.247595287373,2.0,accepted,0.0,CONV
1.62162790178,-3.14072406187,3.14,2727.7043487,0.0791972797243,3.0,accepted,0.0,FG
1.67979102545,-0.187233868809,3.14,1.5127980521,0.0231729068648,4.0,accepted,0.0,FG
3.60001834266,1.93395675089,3.14,798.67360953,1.0,5.0,accepted,0.0,CONV
2.20531728983,0.393291870203,3.14,0.481828535766,0.27367919395,6.0,accepted,0.0,FG
2.48672980521,-0.0882879986157,3.14,1.52099484761,0.149388805361,7.0,accepted,0.0,CONV
2.29035352393,0.247769776392,3.14,0.196241133494,0.0451417784581,8.0,accepted,0.0,FG
2.87206167866,0.725611149876,3.14,2.02197565674,1.0,9.0,accepted,0.0,CONV
2.42679561207,0.359849475236,3.14,0.118657036427,0.234554195311,10.0,accepted,0.0,FG
2.52011405355,0.257146684768,3.14,0.170972786626,0.122870155234,11.0,accepted,0.0,CONV
2.46081266915,0.322411573036,3.14,0.090893859893,0.0447894437336,12.0,accepted,0.0,FG
2.55178531049,0.40675508086,3.14,0.074686471002,0.274418778119,13.0,accepted,0.0,CONV
2.51741870702,0.374892755596,3.14,0.0705952587595,0.170751992227,14.0,accepted,0.0,FG
2.56323128738,0.334913001268,3.14,0.0675758562998,0.0901679797521,15.0,accepted,0.0,CONV
2.54190386137,0.353525034154,3.14,0.0593768121142,0.0481914985888,16.0,accepted,0.0,FG
2.5835924844,0.401764018416,3.14,0.0527028679055,0.179378396809,17.0,accepted,0.0,CONV
2.56931032409,0.38523776122,3.14,0.051206178046,0.117924915432,18.0,accepted,0.0,FG
2.59488490583,0.364374105761,3.14,0.0465399080103,0.0660025702894,19.0,accepted,0.0,CONV
2.58715061232,0.3706837157,3.14,0.0455275620855,0.0460419994155,20.0,accepted,0.0,FG
2.6123413963,0.400018045067,3.14,0.039989918874,0.130337720969,21.0,accepted,0.0,CONV
2.62830109518,0.38389525876,3.14,0.035457496568,0.046008797839,22.0,accepted,0.0,CONV
2.64320926141,0.411098787989,3.14,0.0334321969646,0.105104701218,23.0,accepted,0.0,CONV
2.63743775462,0.400567287919,3.14,0.0325069625379,0.0644147540096,24.0,accepted,0.0,FG
2.6558435096,0.391065190391,3.14,0.0301264524256,0.0719892627745,25.0,accepted,0.0,CONV
2.66013402491,0.404783612024,3.14,0.0275745991482,0.0429651670812,26.0,accepted,0.0,CONV
2.6840216625,0.399808104646,3.14,0.0249881225863,0.115500391601,27.0,accepted,0.0,CONV
2.68704823798,0.414385419075,3.14,0.0226868744107,0.0424252092863,28.0,accepted,0.0,CONV
2.70767469869,0.406231270359,3.14,0.0214936312659,0.105827419347,29.0,accepted,0.0,CONV
2.70072705822,0.408977844015,3.14,0.0211390270491,0.0701814172669,30.0,accepted,0.0,FG
2.7054319511,0.420682567639,3.14,0.0197132772651,0.0508968023745,31.0,accepted,0.0,CONV
2.71766478928,0.414172911185,3.14,0.0185647594652,0.0666725641958,32.0,accepted,0.0,CONV
2.72098597642,0.423751686908,3.14,0.0172628024162,0.0443030015661,33.0,accepted,0.0,CONV
2.72098597642,0.423751686908,3.14,0.0172628024162,0.0443030015661,33.0,final,0.0,CONV

0 comments on commit 4c1a360

Please sign in to comment.