Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposing: removing lines with more than one statements. (v2.10) #1118

Merged
merged 13 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 13 additions & 1 deletion .astyle.options
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
-n --indent=spaces=2 --keep-one-line-statements --keep-one-line-blocks
# long options can be written without the preceding '--'
suffix=none #equivalent to "-n"
style=attach
add-braces
indent=spaces=2
break-one-line-headers

# old options
#suffix=none
#indent=spaces=2
#keep-one-line-statements
#keep-one-line-blocks
# end old options
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .git-blame-ignore-revs
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
# new astyle applied to v2.9.3
2cd41d16623b7a062b2a716eaf5c91a741cc19ea
# new astyle applied to v2.10
df781b48652d8cdde2994dae1197cdb623f3f3fa
24 changes: 16 additions & 8 deletions plugins/cudaCoord/Coordination.cu
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,17 @@ void CudaCoordination<calculateFloat>::calculate() {
}

// in this way we do not resize with additional memory allocation
if (reductionMemoryCoord.size() > cudaCoordination.size())
if (reductionMemoryCoord.size() > cudaCoordination.size()) {
reductionMemoryCoord.swap (cudaCoordination);
if (reductionMemoryVirial.size() > cudaVirial.size())
}
if (reductionMemoryVirial.size() > cudaVirial.size()) {
reductionMemoryVirial.swap (cudaVirial);
}
// this ensures that the memory is fully in the host ram
cudaDeviceSynchronize();
for (unsigned i = 0; i < deriv.size(); ++i)
for (unsigned i = 0; i < deriv.size(); ++i) {
setAtomsDerivatives (i, deriv[i]);
}

setValue (coordination);
setBoxDerivatives (virial);
Expand Down Expand Up @@ -349,8 +352,9 @@ getSelfCoord (const unsigned nat,
// const unsigned j = threadIdx.y + blockIdx.y * blockDim.y;

// Safeguard
if (idx == trueIndexes[j])
if (idx == trueIndexes[j]) {
continue;
}

d_0 = calculatePBC<usePBC> (coordinates[X (j)] - x, myPBC.X);
d_1 = calculatePBC<usePBC> (coordinates[Y (j)] - y, myPBC.Y);
Expand Down Expand Up @@ -493,8 +497,9 @@ getCoordDual (const unsigned natActive,
// const unsigned j = threadIdx.y + blockIdx.y * blockDim.y;

// Safeguard
if (idx == trueIndexes[j])
if (idx == trueIndexes[j]) {
continue;
}

d_0 = calculatePBC<usePBC> (coordLoop[X (j)] - x, myPBC.X);
d_1 = calculatePBC<usePBC> (coordLoop[Y (j)] - y, myPBC.Y);
Expand Down Expand Up @@ -597,8 +602,9 @@ getDerivDual (const unsigned natLoop,
// const unsigned j = threadIdx.y + blockIdx.y * blockDim.y;

// Safeguard
if (idx == trueIndexes[j])
if (idx == trueIndexes[j]) {
continue;
}

d_0 = calculatePBC<usePBC> (coordLoop[X (j)] - x, myPBC.X);
d_1 = calculatePBC<usePBC> (coordLoop[Y (j)] - y, myPBC.Y);
Expand Down Expand Up @@ -880,7 +886,8 @@ CudaCoordination<calculateFloat>::CudaCoordination (const ActionOptions &ao)
}
std::string sw, errors;

{ // loading data to the GPU
{
// loading data to the GPU
int nn_ = 6;
int mm_ = 0;

Expand All @@ -895,8 +902,9 @@ CudaCoordination<calculateFloat>::CudaCoordination (const ActionOptions &ao)
if (mm_ == 0) {
mm_ = 2 * nn_;
}
if (mm_ % 2 != 0 || mm_ % 2 != 0)
if (mm_ % 2 != 0 || mm_ % 2 != 0) {
error (" this implementation only works with both MM and NN even");
}

switchingParameters.nn = nn_;
switchingParameters.mm = mm_;
Expand Down
6 changes: 4 additions & 2 deletions plugins/cudaCoord/Coordination.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ __device__ __forceinline__ calculateFloat pcuda_fastpow (calculateFloat base,
}
calculateFloat result = 1.0;
while (expo) {
if (expo & 1)
if (expo & 1) {
result *= base;
}
expo >>= 1;
base *= base;
}
Expand Down Expand Up @@ -156,8 +157,9 @@ __global__ void getpcuda_Rational (const calculateFloat *rdists,
if (rdists[i] <= 0.) {
res[i] = 1.;
dfunc[i] = 0.0;
} else
} else {
res[i] = pcuda_Rational (rdists[i], NN, MM, dfunc[i]);
}
// printf("stretch: %i: %f -> %f\n",i,rdists[i],res[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/cudaCoord/cudaHelpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct DataInterface {
double *ptr = nullptr;
size_t size = 0;
DataInterface() = delete;

// VectorGeneric is a "memory map" on an n linear array
// &vg[0] gets the pointer to the first double in memory
// C++ vectors align memory so we can safely use the vector variant of
Expand Down
12 changes: 8 additions & 4 deletions plugins/pycv/PlumedPythonEmbeddedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ PYBIND11_EMBEDDED_MODULE(plumedCommunications, m) {
auto retAccessor = atomIndexes.mutable_unchecked<1>();
for (decltype(nat) i=0; i < nat; ++i) {
//at time of writing getAbsoluteIndexes returns const std::vector<AtomNumber> &
retAccessor(i)=self->getAbsoluteIndexes()[i].index();
retAccessor(i)
=self->getAbsoluteIndexes()[i].index();
}
return atomIndexes;
},
Expand All @@ -129,7 +130,8 @@ PYBIND11_EMBEDDED_MODULE(plumedCommunications, m) {
py::array_t<double> masses(shape);
auto retAccessor = masses.mutable_unchecked<1>();
for (decltype(nat) i=0; i < nat; ++i) {
retAccessor(i)=self->getMass(i);
retAccessor(i)
=self->getMass(i);
}
return masses;
},
Expand All @@ -142,7 +144,8 @@ PYBIND11_EMBEDDED_MODULE(plumedCommunications, m) {
py::array_t<double> charges(shape);
auto retAccessor = charges.mutable_unchecked<1>();
for (decltype(nat) i=0; i < nat; ++i) {
retAccessor(i)=self->getCharge(i);
retAccessor(i)
=self->getCharge(i);
}
return charges;
},
Expand Down Expand Up @@ -196,7 +199,8 @@ return toRet;
py::array_t<unsigned long> couples(shape);
auto retAccessor = couples.mutable_unchecked<2>();
for(size_t c=0; c< ncouples; ++c) {
retAccessor(c,0) = self->getClosePair(c).first;
retAccessor(c,0)
= self->getClosePair(c).first;
retAccessor(c,1) = self->getClosePair(c).second;
}
return couples;
Expand Down
51 changes: 34 additions & 17 deletions plugins/pycv/PythonCVInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,21 @@ PythonCVInterface::PythonCVInterface(const ActionOptions&ao) ://the catch only a
std::vector<AtomNumber> groupB;
pyParseAtomList("GROUPB",initDict,groupB);

if(atoms.size() !=0 && groupA.size()!=0)
if(atoms.size() !=0 && groupA.size()!=0) {
error("you can choose only between using the neigbourlist OR the atoms");
}

if(atoms.size()==0&& groupA.size()==0 && groupB.size()==0)
if(atoms.size()==0&& groupA.size()==0 && groupB.size()==0) {
error("At least one atom is required");
}

if (atoms.size() != 0 && groupA.size() != 0)
if (atoms.size() != 0 && groupA.size() != 0) {
error("you can choose only between using the neigbourlist OR the atoms");
}

if (atoms.size() == 0 && groupA.size() == 0 && groupB.size() == 0)
if (atoms.size() == 0 && groupA.size() == 0 && groupB.size() == 0) {
error("At least one atom is required");
}

bool nopbc;
pyParseFlag("NOPBC",initDict, nopbc);
Expand All @@ -551,11 +555,13 @@ PythonCVInterface::PythonCVInterface(const ActionOptions&ao) ://the catch only a
int nl_st = 0;
if (doneigh) {
pyParse("NL_CUTOFF", initDict, nl_cut);
if (nl_cut <= 0.0)
if (nl_cut <= 0.0) {
error("NL_CUTOFF should be explicitly specified and positive");
}
pyParse("NL_STRIDE",initDict, nl_st);
if (nl_st <= 0)
if (nl_st <= 0) {
error("NL_STRIDE should be explicitly specified and positive");
}
}
// endof WIP
if (groupB.size() > 0) {
Expand Down Expand Up @@ -607,8 +613,9 @@ void PythonCVInterface::prepare() {
error("Neighbor lists should be updated on exchange steps - choose a "
"NL_STRIDE which divides the exchange stride!");
}
if (getExchangeStep())
if (getExchangeStep()) {
firsttime = true;
}
}
}
if (hasPrepare) {
Expand Down Expand Up @@ -680,8 +687,9 @@ void PythonCVInterface::readReturn(const py::object &r, Value* valPtr) {
//shape returns long int
auto natoms = static_cast<long int > (getPositions().size());
if (rl.size() > 1) {
if(!valPtr->hasDerivatives())
if(!valPtr->hasDerivatives()) {
error(valPtr->getName()+" was declared without derivatives, but python returned with derivatives");
}
// 2nd return value: gradient: numpy array of (natoms, 3)
py::array_t<pycvComm_t> grad(rl[1]);
// Assert correct gradient shape
Expand All @@ -697,12 +705,14 @@ void PythonCVInterface::readReturn(const py::object &r, Value* valPtr) {
Vector3d gi(grad.at(i, 0), grad.at(i, 1), grad.at(i, 2));
setAtomsDerivatives(valPtr, i, gi);
}
} else if (valPtr->hasDerivatives())
} else if (valPtr->hasDerivatives()) {
error(valPtr->getName()+" was declared with derivatives, but python returned none");
}

if (rl.size() > 2) {
if(!valPtr->hasDerivatives())
if(!valPtr->hasDerivatives()) {
plumed_merror(valPtr->getName()+" was declared without derivatives, but python returned with box derivatives");
}
py::array_t<pycvComm_t> pyBoxDev(rl[2]);
// expecting the box derivatives
Tensor boxDev;
Expand All @@ -724,18 +734,21 @@ void PythonCVInterface::readReturn(const py::object &r, Value* valPtr) {
error("Python CV returned wrong box derivatives shape error");
}
setBoxDerivatives(valPtr, boxDev);
} else if (valPtr->hasDerivatives())
} else if (valPtr->hasDerivatives()) {
warning(valPtr->getName()+" was declared with derivatives, but python returned no box derivatives");
}
} else {
// Only value returned. Might be an error as well.
if (valPtr->hasDerivatives())
if (valPtr->hasDerivatives()) {
warning(BIASING_DISABLED);
}
pycvComm_t value = r.cast<pycvComm_t>();
valPtr->set(value);
}
//TODO: is this ok?
if (!pbc)
if (!pbc) {
setBoxDerivativesNoPbc(valPtr);
}
}


Expand All @@ -750,10 +763,11 @@ void PythonCVInterface::calculateMultiComponent(py::object &r) {
std::string key=component->getName().substr(
2 + getLabel().size()
+PYCV_COMPONENTPREFIX.size());
if (dataDict.contains(key.c_str()))
if (dataDict.contains(key.c_str())) {
readReturn(dataDict[key.c_str()], component);
else
} else {
error( "python did not returned " + key );
}
}
} else {
// In principle one could handle a "list" return case.
Expand All @@ -765,15 +779,18 @@ void PythonCVInterface::pyParseAtomList(const char* key, const ::pybind11::dict
parseAtomList(key,myatoms);

if(initDict.contains(key)) {
if (myatoms.size()>0)
if (myatoms.size()>0) {
error(std::string("you specified the same keyword ").append(key)+ " both in python and in the settings file");
}
auto atomlist=PLMD::Tools::getWords(
py::str(initDict[key]).cast<std::string>(),
"\t\n ,");
interpretAtomList( atomlist, myatoms );
}
}

NeighborList &PythonCVInterface::getNL() { return *nl; }
NeighborList &PythonCVInterface::getNL() {
return *nl;
}
} // namespace pycvs
} // namespace PLMD
14 changes: 9 additions & 5 deletions plugins/pycv/PythonFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ PLUMED_REGISTER_ACTION(PythonFunction,"PYFUNCTION")

void PythonFunction::registerKeywords( Keywords& keys ) {
Function::registerKeywords( keys );
keys.use("ARG"); keys.use("PERIODIC");
keys.use("ARG");
keys.use("PERIODIC");
keys.add("compulsory","IMPORT","the python file to import, containing the function");
keys.add("compulsory","CALCULATE",PYCV_DEFAULTCALCULATE,"the function to call");
keys.add("compulsory","INIT",PYCV_DEFAULTINIT,"the function to call during the construction method of the function");
Expand Down Expand Up @@ -225,8 +226,9 @@ void PythonFunction::readReturn(const py::object &r, Value* valPtr) {
valPtr->set(value);
if (rl.size() > 1) {
auto nargs = getNumberOfArguments();
if(!valPtr->hasDerivatives())
if(!valPtr->hasDerivatives()) {
error(valPtr->getName()+" was declared without derivatives, but python returned with derivatives");
}
// 2nd return value: gradient: numpy array
py::array_t<pycvComm_t> grad(rl[1]);
if(grad.ndim() != 1 || grad.shape(0) != nargs) {
Expand All @@ -240,8 +242,9 @@ void PythonFunction::readReturn(const py::object &r, Value* valPtr) {
for(size_t i=0; i<nargs; i++) {
valPtr->setDerivative(i,grad.at(i));
}
} else if (valPtr->hasDerivatives())
} else if (valPtr->hasDerivatives()) {
plumed_merror(valPtr->getName()+" was declared with derivatives, but python returned none");
}

} else {
// Only value returned. Might be an error as well.
Expand All @@ -262,10 +265,11 @@ void PythonFunction::calculateMultiComponent(py::object &r) {
std::string key=component->getName().substr(
2 + getLabel().size()
+PYCV_COMPONENTPREFIX.size());
if (dataDict.contains(key.c_str()))
if (dataDict.contains(key.c_str())) {
readReturn(dataDict[key.c_str()], component);
else
} else {
error( "python did not returned " + key );
}
}
} else {
// In principle one could handle a "list" return case.
Expand Down
2 changes: 1 addition & 1 deletion python/plumed.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def read_as_pandas(file_or_path,enable_constants=True,enable_conversion=True,ker

# read the rest of the file
# notice that if chunksize was provided the result will be an iterable object
df=pd.read_csv(file_or_path, delim_whitespace=True, comment="#", header=None,names=columns,
df=pd.read_csv(file_or_path, sep='\s+', comment="#", header=None,names=columns,
usecols=usecols,skiprows=skiprows,nrows=nrows,chunksize=chunksize,index_col=index_col)

if chunksize is None:
Expand Down
Loading
Loading