ImportError when "import model" at the current dir
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MadGraph5_aMC@NLO |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Hi MadTeam, On MG5_aMC v2.5.5, importing a model in the current directory may raise ImportError.
Assume I have a model at `~/newmodel/` and executing MG5_aMC from home directory. Then both of `import model ~/newmodel` and `import model ./newmodel` do work, but `import model newmodel` does not work.
This is because `find_ufo_path` in `import_ufo.py` accepts last option (line 80) but `models/
I am not sure which is the expected feature: 1) all the models outside `MG5DIR/models` should be called with an absolute or relative path (i.e., must be specified with at least one `os.sep`), or 2) ["MG5DIR/models", ".", $PYTHONPATH] are equally treated and `import model newmodel` should be interpreted as `import model ./newmodel`. If (1), then it would be nice if `find_ufo_path` returns an error with a nice error message. If (2), it can be patched by prepending `./` in `find_ufo_path` if it has no os.sep.
description: | updated |
Changed in mg5amcnlo: | |
status: | Fix Committed → Fix Released |
Hi,
Thanks for the information, actually both using "newmodel" and "./newmodel" can lead to problem.
So I'm going to change the code for
1) do not allow at all, the "newmodel" option
2) have a full support for "./newmodel"
You can find below the patch that I'm going to apply:
=== modified file 'madgraph/ interface/ madgraph_ interface. py' interface/ madgraph_ interface. py 2017-04-06 21:08:27 +0000 interface/ madgraph_ interface. py 2017-06-15 15:18:31 +0000
try:
self._curr_ model = import_ ufo.import_ model(args[ 1], prefix=prefix,
complex_ mass_scheme= self.options[ 'complex_ mass_scheme' ]) model.get( 'modelpath+ restriction' )
except import_ ufo.UFOImportEr ror, error:
if 'not a valid UFO model' in str(error):
logger_ stderr. warning( 'WARNING: %s' % error)
--- madgraph/
+++ madgraph/
@@ -5057,6 +5057,8 @@
+ if os.path.sep in args[1] and "import" in self.history[-1]:
+ self.history[-1] = 'import model %s' % self._curr_
=== modified file 'models/ import_ ufo.py' import_ ufo.py 2017-02-16 15:16:38 +0000 import_ ufo.py 2017-06-15 15:23:58 +0000
last_model_ path = os.path. join(MG5DIR, p, model_name)
return os.path. join(MG5DIR, p, model_name) isdir(model_ name): join(MG5DIR, model_name): join(os. getcwd( ), model_name)) join(MG5DIR, model_name) "Path %s is not a valid pathname" % model_name) "Path %s is not a valid pathname" % model_name)
--- models/
+++ models/
@@ -78,10 +78,9 @@
if os.path.
- if last_model_path != os.path.
- logger.info("model loaded from: %s", os.path.
- last_model_path = os.path.
- return model_name
+ logger.warning('No model %s found in default path. Did you meant \'import model ./%s\'',
+ model_name, model_name)
+ raise UFOImportError(
else:
raise UFOImportError(