Changeset 1b64b2f


Ignore:
Timestamp:
May 8, 2017, 2:04:19 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_goodresults, ForceAnnealing_tocheck
Children:
7ee4b5
Parents:
485eea
git-author:
Frederik Heber <heber@…> (04/06/17 05:09:37)
git-committer:
Frederik Heber <frederik.heber@…> (05/08/17 14:04:19)
Message:

ForceAnnealing now uses step width according to Barzilai-Borwein method.

  • this is not as good as what MPQC does but as long as Actions don't have an internal state, we cannot do anything better, e.g. a real line-search.
  • removed paramater delta from optimize-structure.
  • DOCU: Updated entry in user guide and noted Barzilai-Borwein method.
  • TESTS: removed deltat from force annealing regression tests.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doc/userguide/userguide.xml

    r485eea r1b64b2f  
    22072207    combines the same Actions as <emphasis role="bold">molecular-dynamics</emphasis> does. However, it
    22082208    uses the <emphasis role="bold">force-annealing</emphasis> action instead of <emphasis role="bold">verlet-integration</emphasis>.</para>
     2209          <remark>Because it is a MacroAction we cannot use any more elaborate
     2210          line search method during the optimization. In essence, we minimize the
     2211          energy function that depends on the nuclei coordinates. The function is
     2212          non-linear and non-convex. The best choice, given that we have gradient
     2213          information, would be the Conjugate Gradient method (such as Fletcher-
     2214          Reeves which work well also for non-linear functions). However, these
     2215          methods perform a line search along the gradient direction which we
     2216          cannot as our Actions do not contain any internal information (apart
     2217          from the state for Undo/Redo). Therefore, we are restricted to the
     2218          method of Barzilai-Borwein where no line-search is needed but that also
     2219          works well for high-dimensional minimization problems.</remark>
    22092220          <para>The command below performs a structure optimization of the
    22102221    currently selected atoms (may also be a subset) for up to 100 time
     
    22192230          --order 3 \
    22202231          --distance 3. \
    2221           --deltat 0.5 \
    22222232          --keep-fixed-CenterOfMass 1 \
    22232233          --fragment-executable mpqc \
     
    22272237    Otherwise only two time steps would be created: the initial and
    22282238    the final one containing the optimized structure.</para>
     2239        <para>Because of the use of Barzilai-Borwein for computing the
     2240        stepwidth  we do not need any 'deltat' parameters. If the computed
     2241        step width is zero, we use a default step width of 1.</para>
    22292242        </section>
    22302243        <section xml:id="dynamics.step-world-time">
  • src/Actions/MoleculeAction/ForceAnnealingAction.cpp

    r485eea r1b64b2f  
    9292  ForceAnnealing<std::vector<atom *> > optimizer(
    9393      set,
    94       params.Deltat.get(),
    9594      true,
    9695      params.steps.get());
  • src/Actions/MoleculeAction/ForceAnnealingAction.def

    r485eea r1b64b2f  
    1616// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1717// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    18 #define paramtypes (boost::filesystem::path)(double)(unsigned int)(bool)
    19 #define paramtokens ("forces-file")("deltat")("steps")("output-every-step")
    20 #define paramdescriptions ("file containing")("time step width")("fixed number of optimization steps to be performed")("whether WorldTime should be increased and output written after every step, useful if optimization might hang")
    21 #define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT(0.1))(NOPARAM_DEFAULT)(PARAM_DEFAULT("0"))
    22 #define paramreferences (forcesfile)(Deltat)(steps)(DoOutput)
     18#define paramtypes (boost::filesystem::path)(unsigned int)(bool)
     19#define paramtokens ("forces-file")("steps")("output-every-step")
     20#define paramdescriptions ("file containing")("fixed number of optimization steps to be performed")("whether WorldTime should be increased and output written after every step, useful if optimization might hang")
     21#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT("0"))
     22#define paramreferences (forcesfile)(steps)(DoOutput)
    2323#define paramvalids \
    2424(DummyValidator< boost::filesystem::path >()) \
    25 (PositiveValidator< double >()) \
    2625(NotZeroValidator< unsigned int >()) \
    2726(DummyValidator<bool>())
  • src/Dynamics/ForceAnnealing.hpp

    r485eea r1b64b2f  
    3232 *
    3333 * Sadly, we have to use some static instances as so far values cannot be passed
    34  * between actions. Hence, we need to store the current step and the adaptive
     34 * between actions. Hence, we need to store the current step and the adaptive-
    3535 * step width (we cannot perform a linesearch, as we have no control over the
    3636 * calculation of the forces).
     
    4242  /** Constructor of class ForceAnnealing.
    4343   *
     44   * \note We use a fixed delta t of 1.
     45   *
    4446   * \param _atoms set of atoms to integrate
    4547   * \param _Deltat time step width in atomic units
     
    4951  ForceAnnealing(
    5052      AtomSetMixin<T> &_atoms,
    51       double _Deltat,
    5253      bool _IsAngstroem,
    5354      const size_t _maxSteps) :
    54     AtomicForceManipulator<T>(_atoms, _Deltat, _IsAngstroem),
     55    AtomicForceManipulator<T>(_atoms, 1., _IsAngstroem),
    5556    maxSteps(_maxSteps)
    5657  {}
     
    8990        iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
    9091      // atom's force vector gives steepest descent direction
     92      const Vector oldPosition = (*iter)->getPositionAtStep(NextStep-2 >= 0 ? NextStep - 2 : 0);
    9193      const Vector currentPosition = (*iter)->getPosition();
     94      const Vector oldGradient = (*iter)->getAtomicForceAtStep(NextStep-2 >= 0 ? NextStep - 2 : 0);
    9295      const Vector currentGradient = (*iter)->getAtomicForce();
    9396      LOG(4, "DEBUG: Force for atom " << **iter << " is " << currentGradient);
    9497
    95       // artificial update: deltat may be considered as 1/2 s^2 units, mass
    96       // is neglected deliberately as this makes all atoms equally fast or
    97       // hydrogens slower (and they need to wait for other atoms to arrive at
    98       // final position).
    99       Vector PositionUpdate = currentDeltat * currentGradient;
     98      // we use Barzilai-Borwein update with position reversed to get descent
     99      const Vector GradientDifference = (currentGradient - oldGradient);
     100      const double stepwidth =
     101          fabs((currentPosition - oldPosition).ScalarProduct(GradientDifference))/
     102          GradientDifference.NormSquared();
     103      Vector PositionUpdate = stepwidth * currentGradient;
     104      if (fabs(stepwidth) < 1e-10) {
     105        // dont' warn in first step, deltat usage normal
     106        if (currentStep != 1)
     107          ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
     108        PositionUpdate = currentDeltat * currentGradient;
     109      }
    100110      LOG(3, "DEBUG: Update would be " << PositionUpdate);
    101111
  • tests/GuiChecks/Molecules/ForceAnnealing/testsuite-molecules-force-annealing.at

    r485eea r1b64b2f  
    2525AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    2626AT_CHECK([chmod u+w $file], 0)
    27 AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01 --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
     27AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
    2828AT_CHECK([grep -v "Command.*DryRun" session-molecules-force-annealing.py >session-molecules-force-annealing_new.py], 0, [ignore], [ignore])
    2929AT_CHECK([../../molecuilderguitest session-molecules-force-annealing_new.py], 0, [stdout], [stderr])
     
    4040AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    4141AT_CHECK([chmod u+w $file], 0)
    42 AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01 --undo --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
     42AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --undo --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
    4343AT_CHECK([grep -v "Command.*DryRun" session-molecules-force-annealing.py >session-molecules-force-annealing_new.py], 0, [ignore], [ignore])
    4444AT_CHECK([../../molecuilderguitest session-molecules-force-annealing_new.py], 0, [stdout], [stderr])
     
    5555AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    5656AT_CHECK([chmod u+w $file], 0)
    57 AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01 --undo --redo --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
     57AT_CHECK([../../molecuilder --dry-run -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --undo --redo --no-dry-run --store-session session-molecules-force-annealing.py --session-type python], 0, [stdout], [stderr])
    5858AT_CHECK([grep -v "Command.*DryRun" session-molecules-force-annealing.py >session-molecules-force-annealing_new.py], 0, [ignore], [ignore])
    5959AT_CHECK([../../molecuilderguitest session-molecules-force-annealing_new.py], 0, [stdout], [stderr])
  • tests/regression/Molecules/ForceAnnealing/testsuite-molecules-force-annealing.at

    r485eea r1b64b2f  
    2525AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    2626AT_CHECK([chmod u+w $file], 0)
    27 AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01], 0, [stdout], [stderr])
     27AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1], 0, [stdout], [stderr])
    2828AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/post/test.conf], 0, [ignore], [ignore])
    2929
     
    3838AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    3939AT_CHECK([chmod u+w $file], 0)
    40 AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01 --undo], 0, [stdout], [stderr])
     40AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --undo], 0, [stdout], [stderr])
    4141AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/post/test-undo.conf], 0, [ignore], [ignore])
    4242
     
    5151AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/pre/test.forces .], 0)
    5252AT_CHECK([chmod u+w $file], 0)
    53 AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --deltat 0.01 --undo --redo], 0, [stdout], [stderr])
     53AT_CHECK([../../molecuilder -i $file --select-all-atoms --force-annealing --forces-file test.forces --steps 1 --undo --redo], 0, [stdout], [stderr])
    5454AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Molecules/ForceAnnealing/post/test.conf], 0, [ignore], [ignore])
    5555
Note: See TracChangeset for help on using the changeset viewer.