ImportError when "import model" at the current dir

Bug #1698157 reported by Sho Iwamoto
6
This bug affects 1 person
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/__init__.py` 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)
description: updated
Revision history for this message
Olivier Mattelaer (olivier-mattelaer) wrote :

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'
--- madgraph/interface/madgraph_interface.py 2017-04-06 21:08:27 +0000
+++ madgraph/interface/madgraph_interface.py 2017-06-15 15:18:31 +0000
@@ -5057,6 +5057,8 @@
                 try:
                     self._curr_model = import_ufo.import_model(args[1], prefix=prefix,
                         complex_mass_scheme=self.options['complex_mass_scheme'])
+ 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/import_ufo.py'
--- models/import_ufo.py 2017-02-16 15:16:38 +0000
+++ models/import_ufo.py 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):
- logger.info("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)
     else:
         raise UFOImportError("Path %s is not a valid pathname" % model_name)

Changed in mg5amcnlo:
status: New → Fix Committed
Revision history for this message
Sho Iwamoto (misho) wrote :

Hi Olivier,

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

Changed in mg5amcnlo:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.