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

Added a simple module map #1063

Merged
merged 4 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions regtest/basic/rt-make-moduleMap/Makefile
@@ -0,0 +1 @@
include ../../scripts/test.make
1 change: 1 addition & 0 deletions regtest/basic/rt-make-moduleMap/config
@@ -0,0 +1 @@
type=make
19 changes: 19 additions & 0 deletions regtest/basic/rt-make-moduleMap/main.cpp
@@ -0,0 +1,19 @@
#include "plumed/core/ModuleMap.h"
#include "plumed/core/ActionRegister.h"

#include <fstream>


int main(){
const auto actionList=PLMD::actionRegister().getActionNames();
//just checking that all the default-registered actions are in the module map;
//output should be empty, the diff will be clear
//this test may break in case of adding a new LOAD mechanism on startup
std::ofstream file("output");
for (const auto & name: actionList){
if(PLMD::getModuleMap().count(name)==0){
file << name << "is not in the ModuleMap\n";
}
}
return 0;
}
Empty file.
6 changes: 5 additions & 1 deletion src/core/Makefile
Expand Up @@ -3,7 +3,7 @@ USE=config tools lepton
# generic makefile
include ../maketools/make.module

CLEANLIST:=$(CLEANLIST) PlumedMainMap.inc PlumedMainEnum.inc GREXMap.inc GREXEnum.inc CLToolMainMap.inc CLToolMainEnum.inc
CLEANLIST:=$(CLEANLIST) PlumedMainMap.inc PlumedMainEnum.inc GREXMap.inc GREXEnum.inc CLToolMainMap.inc CLToolMainEnum.inc ModuleMap.inc

PlumedMain.o: PlumedMainMap.inc PlumedMainEnum.inc

Expand All @@ -29,3 +29,7 @@ CLToolMainMap.inc: CLToolMain.cpp
CLToolMainEnum.inc: CLToolMain.cpp
../maketools/makecmd enum < CLToolMain.cpp > CLToolMainEnum.inc

ModuleMap.o: ModuleMap.inc

ModuleMap.inc: ../*/*.cpp
../maketools/makeModuleMap > $@
31 changes: 31 additions & 0 deletions src/core/ModuleMap.cpp
@@ -0,0 +1,31 @@
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2024-2024 The plumed team
(see the PEOPLE file at the root of the distribution for a list of names)

See http://www.plumed.org for more information.

This file is part of plumed, version 2.

plumed is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

plumed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "ModuleMap.h"

namespace PLMD {
const std::map<std::string,std::string> & getModuleMap() {
static const std::map<std::string,std::string> actionToModule= {
#include "ModuleMap.inc"
};
return actionToModule;
}
} // namespace PLMD
30 changes: 30 additions & 0 deletions src/core/ModuleMap.h
@@ -0,0 +1,30 @@
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2024-2024 The plumed team
(see the PEOPLE file at the root of the distribution for a list of names)

See http://www.plumed.org for more information.

This file is part of plumed, version 2.

plumed is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

plumed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#ifndef __PLUMED_core_ModuleMap_h
#define __PLUMED_core_ModuleMap_h
#include <map>
#include <string>
namespace PLMD {
const std::map<std::string,std::string> & getModuleMap();
} // namespace PLMD

#endif //__PLUMED_core_ModuleMap_h
59 changes: 59 additions & 0 deletions src/maketools/makeModuleMap
@@ -0,0 +1,59 @@
#! /usr/bin/env bash
# shellcheck disable=SC2059

problems=""
toPrint=' {"%s", "%s"}'
#regex are scary, here's a link with the flow of the regex
# https://regexper.com/#PLUMED_REGISTER_ACTION%5Cs*%5C%28%5Cs*%5B0-9a-zA-Z_%5D%2B%5Cs*%2C%5Cs*%22%28%5B0-9a-zA-Z_%5D%2B%29%22%5Cs*%5C%29
regex='PLUMED_REGISTER_ACTION\s*\(\s*[0-9a-zA-Z_]+\s*,\s*"([0-9a-zA-Z_]+)"\s*\)'
Copy link
Member Author

Choose a reason for hiding this comment

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

In the mac CI seems to ignore the action regitered like these:

PLUMED_REGISTER_ACTION(Dimer, "DIMER")
PLUMED_REGISTER_ACTION(DynamicReferenceRestraining, "DRR")
PLUMED_REGISTER_ACTION(EDS, "EDS")
PLUMED_REGISTER_ACTION(FuncPathGeneral, "FUNCPATHGENERAL")
PLUMED_REGISTER_ACTION(JCoupling, "JCOUPLING")
PLUMED_REGISTER_ACTION(Loss, "MAZE_LOSS")
PLUMED_REGISTER_ACTION(Memetic, "MAZE_MEMETIC_SAMPLING")
PLUMED_REGISTER_ACTION(OptimizerBias, "MAZE_OPTIMIZER_BIAS")
PLUMED_REGISTER_ACTION(Random_Acceleration_MD, "MAZE_RANDOM_ACCELERATION_MD")
PLUMED_REGISTER_ACTION(Random_Walk, "MAZE_RANDOM_WALK")
PLUMED_REGISTER_ACTION(Simulated_Annealing, "MAZE_SIMULATED_ANNEALING")
PLUMED_REGISTER_ACTION(Steered_MD, "MAZE_STEERED_MD")
PLUMED_REGISTER_ACTION(fusionPoreExpansionP, "FUSIONPOREEXPANSIONP")
PLUMED_REGISTER_ACTION(fusionPoreNucleationP, "FUSIONPORENUCLEATIONP")
PLUMED_REGISTER_ACTION(memFusionP, "MEMFUSIONP")

with only a space after the ","


for module in ../*/module.type; do
moduledir=${module%%/module.type}
modulename=${moduledir##*/}
{
for file in "$moduledir"/*.cpp; do
if grep -q PLUMED_REGISTER_ACTION "${file}"; then
# gawk and perl implementation in case your bash dialect do not process correctly the regex
# actionName=$(gawk 'match($0,/PLUMED_REGISTER_ACTION\s*\(\s*[0-9_a-zA-Z]+\s*,\s*"([0-9a-zA-Z_]+)"\s*\)/, captured){print captured[1]}' "${file}" )
# # in case gawk does not work, here's the perl implementation:
# # actionName=$(perl -ln -e'print $1 if /PLUMED_REGISTER_ACTION\s*\(\s*[0-9_a-zA-Z]+\s*,\s*"([0-9a-zA-Z_]+)"\s*\)/' "${file}")
# ng=$(grep -c PLUMED_REGISTER_ACTION "${file}")
# nawk=$(
# cat <<EOF | wc -l
# $b
# EOF
# )
# if [[ $ng -ne $nawk ]]; then
# problems="$problems ${modulename}:${file}"
# fi
# for a in $actionName; do
# printf "$toPrint" "$a" "$modulename"
# # echo -ne "$init {\"$a\", \"$modulename\"}"
# toPrint=',\n {"%s", "%s"}'
# done
# fi

grep PLUMED_REGISTER_ACTION "${file}" | while read -r action; do
# echo $action
if [[ $action =~ $regex ]]; then
actionName=${BASH_REMATCH[1]}
printf "$toPrint" "$actionName" "$modulename"

toPrint=',\n {"%s", "%s"}'
fi
done
#also here becasue while spawns a subshell and toPrint do not get updated
toPrint=',\n {"%s", "%s"}'
fi
done
}

done
echo -e '\n'
if [[ -n $problems ]]; then
echo >&2 some problems in the following:
for p in $problems; do
echo >&2 $p
done
exit 1
fi