From 9feb1ec84e31865e96d47b5c6dd188b626bbf55b Mon Sep 17 00:00:00 2001 From: Carlo Camilloni Date: Fri, 11 Oct 2024 10:43:12 +0200 Subject: [PATCH 1/4] ci checkout v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16a28bbaa5..6446d780d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -231,7 +231,7 @@ jobs: rocky8: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build and run tests run: | make -C docker rocky8 From 1dec0e0380824c9c650359c0f7081ef65b9480e0 Mon Sep 17 00:00:00 2001 From: Guillaume Fraux Date: Thu, 10 Oct 2024 15:41:08 +0200 Subject: [PATCH 2/4] Do not hold Python's GIL when running commands --- python/cplumed.pxd | 20 ++++++++++---------- python/plumed.pyx | 19 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/python/cplumed.pxd b/python/cplumed.pxd index 440b03981a..f2aa5af6a6 100644 --- a/python/cplumed.pxd +++ b/python/cplumed.pxd @@ -31,7 +31,7 @@ cdef extern from "Plumed.h": size_t nelem size_t* shape size_t flags - # ignore other + # ignore other ctypedef struct plumed_nothrow_handler: void* ptr void (*handler)(void*,int,const char*,const void*) @@ -46,12 +46,12 @@ cdef extern from "Plumed.h": plumed_error_filesystem_path path1 plumed_error_filesystem_path path2 # ignore other members - void plumed_cmd_safe_nothrow(plumed p,const char*key,plumed_safeptr safe,plumed_nothrow_handler nothrow) - void plumed_error_set(void*ptr,int code,const char*what,const void* opt) - void plumed_error_init(plumed_error* error) - void plumed_error_finalize(plumed_error error) - plumed plumed_create() - plumed plumed_create_dlopen(const char*path) - plumed plumed_create_invalid() - void plumed_finalize(plumed p) - int plumed_valid(plumed p) + void plumed_cmd_safe_nothrow(plumed p,const char*key,plumed_safeptr safe,plumed_nothrow_handler nothrow) nogil + void plumed_error_set(void*ptr,int code,const char*what,const void* opt) nogil + void plumed_error_init(plumed_error* error) nogil + void plumed_error_finalize(plumed_error error) nogil + plumed plumed_create() nogil + plumed plumed_create_dlopen(const char*path) nogil + plumed plumed_create_invalid() nogil + void plumed_finalize(plumed p) nogil + int plumed_valid(plumed p) nogil diff --git a/python/plumed.pyx b/python/plumed.pyx index 20b6232152..37cecd981a 100644 --- a/python/plumed.pyx +++ b/python/plumed.pyx @@ -36,6 +36,7 @@ import sys import warnings import types +import cython from cython.operator import dereference if sys.version_info < (3,): @@ -185,7 +186,8 @@ cdef class Plumed: cplumed.plumed_error_init(&error) nothrow.ptr=&error nothrow.handler=cplumed.plumed_error_set - cplumed.plumed_cmd_safe_nothrow(self.c_plumed,ckey,safe,nothrow) + with cython.nogil(): + cplumed.plumed_cmd_safe_nothrow(self.c_plumed,ckey,safe,nothrow) if(error.code): try: self.raise_exception(error) @@ -507,7 +509,7 @@ def read_as_pandas(file_or_path,enable_constants=True,enable_conversion=True,ker convert=_build_convert_function(kernel) # if necessary, set convert_all if enable_conversion=='all': convert_all=convert - + # handle file file_or_path=_fix_file(file_or_path,'rt') @@ -588,7 +590,7 @@ def write_pandas(df,file_or_path=None): colvar=plumed.read_as_colvar("COLVAR") colvar["distance"]=colvar["distance"]*2 plumed.write_pandas(colvar) - + """ # importing pandas is pretty slow, so we only do it when needed import pandas as pd @@ -787,7 +789,7 @@ def _readvimdict(plumedroot=None,kernel=None): # read dictionary for opt in plumedDictionary[action]: # skip label (it is added automatically) - if opt["menu"] != "(label)": + if opt["menu"] != "(label)": ret[action][re.sub("=$","",opt["word"])]=opt["menu"] return ret,doc @@ -916,7 +918,7 @@ def _format_at_one_residue(builder,name,residue,chain): return "@" + name + "-" + chain + str(residue) else: assert False - + def _format_at_one_chain(builder,name,residue,chain): res="" if hasattr(residue,'__iter__') and not isinstance(residue,str): @@ -924,7 +926,7 @@ def _format_at_one_chain(builder,name,residue,chain): res+=builder._separator + _format_at_one_residue(builder,name,x,chain) else: res+=builder._separator + _format_at_one_residue(builder,name,residue,chain) - + return res def _format_at(builder,name,residue,chain=""): @@ -1074,7 +1076,7 @@ def _format_anything(builder,name,arg): ret="" if name == "verbatim": ret+=_format_verbatim(builder,arg) - elif isinstance(arg,bool) : + elif isinstance(arg,bool) : ret+=_format_flag(builder,name,arg) elif isinstance(arg,_numbered): ret+=_format_numbered(builder,name,arg) @@ -1236,6 +1238,3 @@ class InputBuilder: Accepts a list/tuple. """ return _replicas(arg) - - - From b377dc6e1100063511769576bc873c345d092612 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Mon, 14 Oct 2024 13:50:57 +0200 Subject: [PATCH 3/4] doc --- python/cplumed.pxd | 2 ++ python/plumed.pyx | 1 + 2 files changed, 3 insertions(+) diff --git a/python/cplumed.pxd b/python/cplumed.pxd index f2aa5af6a6..b4b1917b1a 100644 --- a/python/cplumed.pxd +++ b/python/cplumed.pxd @@ -46,6 +46,8 @@ cdef extern from "Plumed.h": plumed_error_filesystem_path path1 plumed_error_filesystem_path path2 # ignore other members + # C functions declared as nogil + # see https://github.com/plumed/plumed2/pull/1129#issuecomment-2410867829 void plumed_cmd_safe_nothrow(plumed p,const char*key,plumed_safeptr safe,plumed_nothrow_handler nothrow) nogil void plumed_error_set(void*ptr,int code,const char*what,const void* opt) nogil void plumed_error_init(plumed_error* error) nogil diff --git a/python/plumed.pyx b/python/plumed.pyx index 37cecd981a..ad40c9b6e1 100644 --- a/python/plumed.pyx +++ b/python/plumed.pyx @@ -186,6 +186,7 @@ cdef class Plumed: cplumed.plumed_error_init(&error) nothrow.ptr=&error nothrow.handler=cplumed.plumed_error_set + # see https://github.com/plumed/plumed2/pull/1129#issuecomment-2410867829 with cython.nogil(): cplumed.plumed_cmd_safe_nothrow(self.c_plumed,ckey,safe,nothrow) if(error.code): From b0ffcb55ad8cc3c71ec5c30a1bd46f68dd33bceb Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Mon, 14 Oct 2024 13:51:02 +0200 Subject: [PATCH 4/4] changelog --- CHANGES/v2.10.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES/v2.10.md b/CHANGES/v2.10.md index e4cae820e8..1282e5b776 100644 --- a/CHANGES/v2.10.md +++ b/CHANGES/v2.10.md @@ -71,3 +71,4 @@ Before switching to version 2.10, users are invited to carefully read the follow - You can use ActionShortcut to create complex inputs from a simpler initial input. The nest will then allow users to explore these more complex inputs. - You can use \ref show_graph to create diagrams showing how values and forces are passed between the various actions in your input files. - Complete refactor of SwitchingFunction.cpp and SwitchingFunction.h, now adding new switching function is more straightforward and all the "book-keeping" can be done within a single class + - Python (cython) wrappers now use `nogil`. This should facilitate integration with Python. See https://github.com/plumed/plumed2/pull/1129#issuecomment-2410867829 (thanks to Guillaume Fraux).