Skip to content

Commit

Permalink
Simplified the way that the task list is built
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Aug 26, 2024
1 parent 59b2212 commit d207200
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 51 deletions.
14 changes: 0 additions & 14 deletions src/core/ActionWithMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ void ActionWithMatrix::setupMatrixStore() {
if( next_action_in_chain ) next_action_in_chain->setupMatrixStore();
}

int ActionWithMatrix::checkTaskIsActive( const unsigned& itask ) const {
int nm = getNumberOfMasks(); if( nm<0 ) return 1;

// This checks for matrices that are masking some elements
unsigned nargs = getNumberOfArguments();
if( nm==1 && getPntrToArgument(nargs-1)->getRank()==2 ) return 1;

for(unsigned j=nargs-nm; j<nargs; ++j) {
plumed_assert( getPntrToArgument(j)->getRank()==1 );
if( fabs(getPntrToArgument(j)->get(itask))>0 ) return 1;
}
return 0;
}

void ActionWithMatrix::calculate() {
if( actionInChain() ) return ;
// Update all the neighbour lists
Expand Down
2 changes: 0 additions & 2 deletions src/core/ActionWithMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class ActionWithMatrix : public ActionWithVector {
virtual ~ActionWithMatrix();
///
virtual bool isAdjacencyMatrix() const { return false; }
///
virtual int checkTaskIsActive( const unsigned& itask ) const ;
///
void getAllActionLabelsInMatrixChain( std::vector<std::string>& mylabels ) const override ;
/// Get the first matrix in this chain
Expand Down
34 changes: 28 additions & 6 deletions src/core/ActionWithVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,34 @@ void ActionWithVector::prepare() {
}

int ActionWithVector::checkTaskIsActive( const unsigned& itask ) const {
for(unsigned i=0; i<getNumberOfArguments(); ++i) {
Value* myarg = getPntrToArgument(i);
if( myarg->getRank()==0 ) continue;
else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) {
if( fabs(myarg->get(itask))>0 ) return 1;
} else plumed_merror("should not be in action " + getName() );
unsigned nargs = getNumberOfArguments();
if( nmask>0 ) {
for(unsigned j=nargs-nmask; j<nargs; ++j) {
Value* myarg = getPntrToArgument(j);
if( myarg->getRank()==1 && !myarg->hasDerivatives() ) {
if( fabs(myarg->get(itask))>0 ) return 1;
} else if( myarg->getRank()==2 && !myarg->hasDerivatives() ) {
unsigned ncol = myarg->getRowLength(itask);
unsigned base = itask*myarg->getNumberOfColumns();
for(unsigned k=0; k<ncol; ++k) {
if( fabs(myarg->get(base+k,false))>0 ) return 1;
}
} else plumed_merror("only matrices and vectors should be used as masks");
}
} else {
for(unsigned i=0; i<nargs; ++i) {
Value* myarg = getPntrToArgument(i);
if( myarg->getRank()==0 ) continue;
else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) {
if( fabs(myarg->get(itask))>0 ) return 1;
} else if( myarg->getRank()==2 && !myarg->hasDerivatives() ) {
unsigned ncol = myarg->getRowLength(itask);
unsigned base = itask*myarg->getNumberOfColumns();
for(unsigned k=0; k<ncol; ++k) {
if( fabs(myarg->get(base+k,false))>0 ) return 1;
}
} else plumed_merror("should not be in action " + getName() );
}
}
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ActionWithVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class ActionWithVector:
bool atomsWereRetrieved;
/// This is used to build the argument store when we cannot use the chain
unsigned reallyBuildArgumentStore( const unsigned& argstart );
/// Determine if a particular task is active based on the values of the input argument
int checkTaskIsActive( const unsigned& itask ) const ;
protected:
/// A vector that contains the start point for the argument derivatives
std::vector<unsigned> arg_deriv_starts;
Expand Down Expand Up @@ -131,8 +133,6 @@ class ActionWithVector:
/// Check if a mask has been set
int getNumberOfMasks() const ;
void calculateNumericalDerivatives(ActionWithValue* av) override;
/// Determine if a particular task is active based on the values of the input argument
virtual int checkTaskIsActive( const unsigned& itask ) const ;
/// Turn off the calculation of the derivatives during the forward pass through a calculation
bool doNotCalculateDerivatives() const override ;
/// Are we running this command in a chain
Expand Down
13 changes: 0 additions & 13 deletions src/function/FunctionOfMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class FunctionOfMatrix : public ActionWithMatrix {
void turnOnDerivatives() override;
/// Get the number of derivatives for this action
unsigned getNumberOfDerivatives() override ;
/// Check if the task is active
int checkTaskIsActive( const unsigned& itask ) const override ;
/// Resize the matrices
void prepare() override ;
/// This gets the number of columns
Expand Down Expand Up @@ -232,17 +230,6 @@ unsigned FunctionOfMatrix<T>::getNumberOfColumns() const {
plumed_error(); return 0;
}

template <class T>
int FunctionOfMatrix<T>::checkTaskIsActive( const unsigned& itask ) const {
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(0)->getPntrToAction() );
unsigned status=1; if( av ) status = av->checkTaskIsActive( itask );
for(unsigned i=1; i<getNumberOfArguments(); ++i) {
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(i)->getPntrToAction() );
if( av && status!=av->checkTaskIsActive( itask ) ) plumed_merror("this doesn't work");
}
return status;
}

template <class T>
void FunctionOfMatrix<T>::setupForTask( const unsigned& task_index, std::vector<unsigned>& indices, MultiValue& myvals ) const {
int ncols = -1, basemat=-1; bool redo=false;
Expand Down
14 changes: 0 additions & 14 deletions src/matrixtools/MatrixTimesVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MatrixTimesVector : public ActionWithMatrix {
unsigned getNumberOfColumns() const override { plumed_error(); }
void getNumberOfStreamedDerivatives( unsigned& nderivatives, Value* stopat ) override ;
unsigned getNumberOfDerivatives() override ;
int checkTaskIsActive( const unsigned& itask ) const override ;
void prepare() override ;
void performTask( const unsigned& task_index, MultiValue& myvals ) const override ;
bool isInSubChain( unsigned& nder ) override { nder = arg_deriv_starts[0]; return true; }
Expand Down Expand Up @@ -169,19 +168,6 @@ void MatrixTimesVector::prepare() {
std::vector<unsigned> shape(1); shape[0] = getPntrToArgument(0)->getShape()[0]; myval->setShape(shape);
}

int MatrixTimesVector::checkTaskIsActive( const unsigned& itask ) const {
if( getPntrToArgument(1)->getRank()==1 ) {
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(0)->getPntrToAction() );
plumed_assert( am ); return am->checkTaskIsActive(itask);
} else {
unsigned n=getNumberOfArguments()-1;
for(unsigned i=0; i<n; ++i) {
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(i)->getPntrToAction() );
plumed_assert( am ); if( am->checkTaskIsActive(itask)>0 ) return 1;
}
}
}

void MatrixTimesVector::getNumberOfStreamedDerivatives( unsigned& nderivatives, Value* stopat ) {
if( actionInChain() ) { ActionWithVector::getNumberOfStreamedDerivatives( nderivatives, stopat ); return; }

Expand Down

1 comment on commit d207200

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.