Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
9908d249
Commit
9908d249
authored
Sep 26, 2016
by
Peter Eastman
Browse files
Fixed error when CustomIntegrator modifies step size
parent
985d927a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
12 deletions
+52
-12
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+1
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+6
-5
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+1
-1
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+6
-5
tests/TestCustomIntegrator.h
tests/TestCustomIntegrator.h
+38
-0
No files found.
platforms/cuda/include/CudaKernels.h
View file @
9908d249
...
...
@@ -1432,7 +1432,7 @@ private:
void
prepareForComputation
(
ContextImpl
&
context
,
CustomIntegrator
&
integrator
,
bool
&
forcesAreValid
);
Lepton
::
ExpressionTreeNode
replaceDerivFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
OpenMM
::
ContextImpl
&
context
);
void
findExpressionsForDerivs
(
const
Lepton
::
ExpressionTreeNode
&
node
,
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variableNodes
);
void
recordGlobalValue
(
double
value
,
GlobalTarget
target
);
void
recordGlobalValue
(
double
value
,
GlobalTarget
target
,
CustomIntegrator
&
integrator
);
void
recordChangedParameters
(
ContextImpl
&
context
);
bool
evaluateCondition
(
int
step
);
CudaContext
&
cu
;
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
9908d249
...
...
@@ -7309,7 +7309,7 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
}
localValuesAreCurrent
=
false
;
double
stepSize
=
integrator
.
getStepSize
();
recordGlobalValue
(
stepSize
,
GlobalTarget
(
DT
,
dtVariableIndex
));
recordGlobalValue
(
stepSize
,
GlobalTarget
(
DT
,
dtVariableIndex
)
,
integrator
);
for
(
int
i
=
0
;
i
<
(
int
)
parameterNames
.
size
();
i
++
)
{
double
value
=
context
.
getParameter
(
parameterNames
[
i
]);
if
(
value
!=
globalValuesDouble
[
parameterVariableIndex
[
i
]])
{
...
...
@@ -7442,7 +7442,7 @@ void CudaIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrat
expressionSet
.
setVariable
(
uniformVariableIndex
,
SimTKOpenMMUtilities
::
getUniformlyDistributedRandomNumber
());
expressionSet
.
setVariable
(
gaussianVariableIndex
,
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
());
expressionSet
.
setVariable
(
stepEnergyVariableIndex
[
step
],
energy
);
recordGlobalValue
(
globalExpressions
[
step
][
0
].
evaluate
(),
stepTarget
[
step
]);
recordGlobalValue
(
globalExpressions
[
step
][
0
].
evaluate
(),
stepTarget
[
step
]
,
integrator
);
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ComputeSum
)
{
int
randomIndex
=
integration
.
prepareRandomNumbers
(
requiredGaussian
[
step
]);
...
...
@@ -7458,12 +7458,12 @@ void CudaIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrat
if
(
cu
.
getUseDoublePrecision
()
||
cu
.
getUseMixedPrecision
())
{
double
value
;
summedValue
->
download
(
&
value
);
recordGlobalValue
(
value
,
stepTarget
[
step
]);
recordGlobalValue
(
value
,
stepTarget
[
step
]
,
integrator
);
}
else
{
float
value
;
summedValue
->
download
(
&
value
);
recordGlobalValue
(
value
,
stepTarget
[
step
]);
recordGlobalValue
(
value
,
stepTarget
[
step
]
,
integrator
);
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
UpdateContextState
)
{
...
...
@@ -7567,7 +7567,7 @@ double CudaIntegrateCustomStepKernel::computeKineticEnergy(ContextImpl& context,
}
}
void
CudaIntegrateCustomStepKernel
::
recordGlobalValue
(
double
value
,
GlobalTarget
target
)
{
void
CudaIntegrateCustomStepKernel
::
recordGlobalValue
(
double
value
,
GlobalTarget
target
,
CustomIntegrator
&
integrator
)
{
switch
(
target
.
type
)
{
case
DT
:
if
(
value
!=
globalValuesDouble
[
dtVariableIndex
])
...
...
@@ -7575,6 +7575,7 @@ void CudaIntegrateCustomStepKernel::recordGlobalValue(double value, GlobalTarget
expressionSet
.
setVariable
(
dtVariableIndex
,
value
);
globalValuesDouble
[
dtVariableIndex
]
=
value
;
cu
.
getIntegrationUtilities
().
setNextStepSize
(
value
);
integrator
.
setStepSize
(
value
);
break
;
case
VARIABLE
:
case
PARAMETER
:
...
...
platforms/opencl/include/OpenCLKernels.h
View file @
9908d249
...
...
@@ -1419,7 +1419,7 @@ private:
void
prepareForComputation
(
ContextImpl
&
context
,
CustomIntegrator
&
integrator
,
bool
&
forcesAreValid
);
Lepton
::
ExpressionTreeNode
replaceDerivFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
OpenMM
::
ContextImpl
&
context
);
void
findExpressionsForDerivs
(
const
Lepton
::
ExpressionTreeNode
&
node
,
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variableNodes
);
void
recordGlobalValue
(
double
value
,
GlobalTarget
target
);
void
recordGlobalValue
(
double
value
,
GlobalTarget
target
,
CustomIntegrator
&
integrator
);
void
recordChangedParameters
(
ContextImpl
&
context
);
bool
evaluateCondition
(
int
step
);
OpenCLContext
&
cl
;
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
9908d249
...
...
@@ -7598,7 +7598,7 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
}
localValuesAreCurrent
=
false
;
double
stepSize
=
integrator
.
getStepSize
();
recordGlobalValue(stepSize, GlobalTarget(DT, dtVariableIndex));
recordGlobalValue
(
stepSize
,
GlobalTarget
(
DT
,
dtVariableIndex
)
,
integrator
);
for
(
int
i
=
0
;
i
<
(
int
)
parameterNames
.
size
();
i
++
)
{
double
value
=
context
.
getParameter
(
parameterNames
[
i
]);
if
(
value
!=
globalValuesDouble
[
parameterVariableIndex
[
i
]])
{
...
...
@@ -7729,7 +7729,7 @@ void OpenCLIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr
expressionSet
.
setVariable
(
uniformVariableIndex
,
SimTKOpenMMUtilities
::
getUniformlyDistributedRandomNumber
());
expressionSet
.
setVariable
(
gaussianVariableIndex
,
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
());
expressionSet
.
setVariable
(
stepEnergyVariableIndex
[
step
],
energy
);
recordGlobalValue(globalExpressions[step][0].evaluate(), stepTarget[step]);
recordGlobalValue
(
globalExpressions
[
step
][
0
].
evaluate
(),
stepTarget
[
step
]
,
integrator
);
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ComputeSum
)
{
kernels
[
step
][
0
].
setArg
<
cl_uint
>
(
9
,
integration
.
prepareRandomNumbers
(
requiredGaussian
[
step
]));
...
...
@@ -7747,12 +7747,12 @@ void OpenCLIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr
if
(
cl
.
getUseDoublePrecision
()
||
cl
.
getUseMixedPrecision
())
{
double
value
;
summedValue
->
download
(
&
value
);
recordGlobalValue(value, stepTarget[step]);
recordGlobalValue
(
value
,
stepTarget
[
step
]
,
integrator
);
}
else
{
float
value
;
summedValue
->
download
(
&
value
);
recordGlobalValue(value, stepTarget[step]);
recordGlobalValue
(
value
,
stepTarget
[
step
]
,
integrator
);
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
UpdateContextState
)
{
...
...
@@ -7856,7 +7856,7 @@ double OpenCLIntegrateCustomStepKernel::computeKineticEnergy(ContextImpl& contex
}
}
void OpenCLIntegrateCustomStepKernel::recordGlobalValue(double value, GlobalTarget target) {
void
OpenCLIntegrateCustomStepKernel
::
recordGlobalValue
(
double
value
,
GlobalTarget
target
,
CustomIntegrator
&
integrator
)
{
switch
(
target
.
type
)
{
case
DT
:
if
(
value
!=
globalValuesDouble
[
dtVariableIndex
])
...
...
@@ -7864,6 +7864,7 @@ void OpenCLIntegrateCustomStepKernel::recordGlobalValue(double value, GlobalTarg
expressionSet
.
setVariable
(
dtVariableIndex
,
value
);
globalValuesDouble
[
dtVariableIndex
]
=
value
;
cl
.
getIntegrationUtilities
().
setNextStepSize
(
value
);
integrator
.
setStepSize
(
value
);
break
;
case
VARIABLE
:
case
PARAMETER
:
...
...
tests/TestCustomIntegrator.h
View file @
9908d249
...
...
@@ -858,6 +858,43 @@ void testEnergyParameterDerivatives() {
ASSERT_EQUAL_TOL
(
dEdtheta0
,
values
[
2
][
1
],
1e-5
);
}
/**
* Test an integrator that modifies the step size.
*/
void
testChangeDT
()
{
System
system
;
system
.
addParticle
(
1.0
);
CustomIntegrator
integrator
(
0.5
);
integrator
.
addGlobalVariable
(
"dt_global"
,
0.0
);
integrator
.
addPerDofVariable
(
"dt_dof"
,
0.0
);
integrator
.
addComputeGlobal
(
"dt"
,
"dt+1"
);
integrator
.
addComputePerDof
(
"dt_dof"
,
"dt"
);
integrator
.
addComputeGlobal
(
"dt_global"
,
"dt"
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
context
.
setPositions
(
positions
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
integrator
.
step
(
1
);
double
dt
=
1.5
+
i
;
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getStepSize
(),
1e-5
);
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getGlobalVariable
(
0
),
1e-5
);
vector
<
Vec3
>
values
;
integrator
.
getPerDofVariable
(
0
,
values
);
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getGlobalVariable
(
0
),
1e-5
);
}
integrator
.
setStepSize
(
1.0
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
integrator
.
step
(
1
);
double
dt
=
2.0
+
i
;
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getStepSize
(),
1e-5
);
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getGlobalVariable
(
0
),
1e-5
);
vector
<
Vec3
>
values
;
integrator
.
getPerDofVariable
(
0
,
values
);
ASSERT_EQUAL_TOL
(
dt
,
integrator
.
getGlobalVariable
(
0
),
1e-5
);
}
}
void
runPlatformTests
();
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -879,6 +916,7 @@ int main(int argc, char* argv[]) {
testWhileBlock
();
testChangingGlobal
();
testEnergyParameterDerivatives
();
testChangeDT
();
runPlatformTests
();
}
catch
(
const
exception
&
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment