ImportError when "import model" at the current dir

Bug #1698157 reported by Sho Iwamoto on 2017-06-15
This bug affects 1 person
Affects Status Importance Assigned to Milestone

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 `` accepts last option (line 80) but `models/` assumes that `model_name` without `/` is located on `MG5DIR/models` and then line 30 raises ImportError.

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.

Sho Iwamoto (misho) on 2017-06-15
description: updated


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/ 2017-04-06 21:08:27 +0000
+++ madgraph/interface/ 2017-06-15 15:18:31 +0000
@@ -5057,6 +5057,8 @@
                     self._curr_model = import_ufo.import_model(args[1], prefix=prefix,
+ if os.path.sep in args[1] and "import" in self.history[-1]:
+ self.history[-1] = 'import model %s' % self._curr_model.get('modelpath+restriction')
                 except import_ufo.UFOImportError, error:
                     if 'not a valid UFO model' in str(error):
                         logger_stderr.warning('WARNING: %s' % error)

=== modified file 'models/'
--- models/ 2017-02-16 15:16:38 +0000
+++ models/ 2017-06-15 15:23:58 +0000
@@ -78,10 +78,9 @@
                     last_model_path = os.path.join(MG5DIR, p, model_name)
                 return os.path.join(MG5DIR, p, model_name)
     if os.path.isdir(model_name):
- if last_model_path != os.path.join(MG5DIR, model_name):
-"model loaded from: %s", os.path.join(os.getcwd(), model_name))
- last_model_path = os.path.join(MG5DIR, model_name)
- return model_name
+ logger.warning('No model %s found in default path. Did you meant \'import model ./%s\'',
+ model_name, model_name)
+ raise UFOImportError("Path %s is not a valid pathname" % model_name)
         raise UFOImportError("Path %s is not a valid pathname" % model_name)

Changed in mg5amcnlo:
status: New → Fix Committed
Sho Iwamoto (misho) wrote :

Hi Olivier,

Thanks for patching, it will be fine/clear; 'Did you meant' would be 'Did you mean'.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers