Skip processes without diagrams

Asked by andlessa

Hi,
I'm trying to generate several processes at once using "add process", but if some of the processes do not have diagrams the "NoDiagramException" is raised and madgraph exits. Would it be possible to simply print the error message and go to the next process without stopping the process generation?
I could work around this issue simply removing the exception.
But if you do not see potential issues with this fix, it would be very helpful if this was incorporated into future MadGraph releases.

Best,

-Andre

Question information

Language:
English Edit question
Status:
Answered
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Olivier Mattelaer (olivier-mattelaer) said :
#1

Hi,

Commenting the error is not a good idea since
1) this is a nice warning for the user (typical usage is that the user did an unintentional error when this occur)
2) this can mess up with the usage of multiparticles (which expects that error to be triggered quite often and react accordingly)

One option is to apply this patch:

> === modified file 'madgraph/interface/common_run_interface.py'
> --- madgraph/interface/common_run_interface.py 2018-11-16 15:22:57 +0000
> +++ madgraph/interface/common_run_interface.py 2018-11-28 19:36:30 +0000
> @@ -3160,7 +3160,13 @@
> raise self.InvalidCmd('Not a valid value for notification_center')
> # True/False formatting
> elif args[0] in ['crash_on_error']:
> - tmp = banner_mod.ConfigFile.format_variable(args[1], bool, 'crash_on_error')
> + try:
> + tmp = banner_mod.ConfigFile.format_variable(args[1], bool, 'crash_on_error')
> + except:
> + if args[1].lower() in ['never']:
> + tmp = args[1].lower()
> + else:
> + raise
> self.options[args[0]] = tmp
> elif args[0] in self.options:
> if args[1] in ['None','True','False']:
>
> === modified file 'madgraph/interface/extended_cmd.py'
> --- madgraph/interface/extended_cmd.py 2018-08-07 11:49:28 +0000
> +++ madgraph/interface/extended_cmd.py 2018-11-28 20:15:45 +0000
> @@ -1321,11 +1321,12 @@
> except Exception:
> pass
>
> -
> - if hasattr(self, 'options') and 'crash_on_error' in self.options and \
> - self.options['crash_on_error']:
> - logger.info('stop computation due to crash_on_error=True')
> - sys.exit(str(error))
> + if hasattr(self, 'options') and 'crash_on_error' in self.options:
> + if self.options['crash_on_error'] is True:
> + logger.info('stop computation due to crash_on_error=True')
> + sys.exit(str(error))
> + elif self.options['crash_on_error'] == 'never':
> + return False
>
> #stop the execution if on a non interactive mode
> if self.use_rawinput == False or self.inputfile:
> @@ -1345,6 +1346,7 @@
> def nice_user_error(self, error, line):
> if self.child:
> return self.child.nice_user_error(error, line)
> +
> # Make sure that we are at the initial position
> os.chdir(self.__initpos)
> if not self.history or line == self.history[-1]:
> @@ -1356,10 +1358,13 @@
> str(error).replace('\n','\n\t'))
> logger_stderr.error(error_text)
>
> - if hasattr(self, 'options') and 'crash_on_error' in self.options and \
> - self.options['crash_on_error']:
> - logger.info('stop computation due to crash_on_error=True')
> - sys.exit(str(error))
> + if hasattr(self, 'options') and 'crash_on_error' in self.options:
> + if self.options['crash_on_error'] is True:
> + logger.info('stop computation due to crash_on_error=True')
> + sys.exit(str(error))
> + elif self.options['crash_on_error'] == 'never':
> + self.history.pop()
> + return False
>
> #stop the execution if on a non interactive mode
> if self.use_rawinput == False or self.inputfile:
> @@ -1378,6 +1383,7 @@
> def nice_config_error(self, error, line):
> if self.child:
> return self.child.nice_user_error(error, line)
> +
> # Make sure that we are at the initial position
> os.chdir(self.__initpos)
> if not self.history or line == self.history[-1]:
> @@ -1399,10 +1405,17 @@
> self.do_display('options', debug_file)
> except Exception, error:
> debug_file.write('Fail to write options with error %s' % error)
> - if hasattr(self, 'options') and 'crash_on_error' in self.options and \
> - self.options['crash_on_error']:
> - logger.info('stop computation due to crash_on_error=True')
> - sys.exit(str(error))
> +
> + if hasattr(self, 'options') and 'crash_on_error' in self.options:
> + if self.options['crash_on_error'] is True:
> + logger.info('stop computation due to crash_on_error=True')
> + sys.exit(str(error))
> + elif self.options['crash_on_error'] == 'never':
> + if self.history:
> + self.history.pop()
> + return False
> +
> +
>
> #stop the execution if on a non interactive mode
> if self.use_rawinput == False or self.inputfile:
> @@ -1488,9 +1501,9 @@
> self.nice_config_error(error, line)
> logger.error(self.keyboard_stop_msg)
>
> -
> if stop:
> self.do_quit('all')
> + return stop
>
>
>
> @@ -1500,7 +1513,7 @@
> try:
> return self.onecmd_orig(line, **opt)
> except BaseException, error:
> - self.error_handling(error, line)
> + return self.error_handling(error, line)
>
>
> def stop_on_keyboard_stop(self):
> @@ -1522,7 +1535,9 @@
> current_interface = self
> if precmd:
> line = current_interface.precmd(line)
> - if errorhandling:
> + if errorhandling or \
> + (hasattr(self, 'options') and 'crash_on_error' in self.options and
> + self.options['crash_on_error']=='never'):
> stop = current_interface.onecmd(line, **opt)
> else:
> stop = Cmd.onecmd_orig(current_interface, line, **opt)
> @@ -1620,6 +1635,7 @@
> if self.history:
> self.history.pop()
>
> +
> #avoid that command of other file interfere with this one.
> previous_store_line = self.get_stored_line()
>
> @@ -1636,6 +1652,7 @@
> # filepath can be overwritten during the run (leading to weird results)
> # Note also that we need a generator and not a list.
> for line in self.inputfile:
> +
> #remove pointless spaces and \n
> line = line.replace('\n', '').strip()
> # execute the line
>
> === modified file 'madgraph/interface/madgraph_interface.py'
> --- madgraph/interface/madgraph_interface.py 2018-09-28 13:35:10 +0000
> +++ madgraph/interface/madgraph_interface.py 2018-11-28 19:36:10 +0000
> @@ -7425,7 +7425,13 @@
> raise self.InvalidCmd('expected bool for notification_center')
> # True/False formatting
> elif args[0] in ['crash_on_error']:
> - tmp = banner_module.ConfigFile.format_variable(args[1], bool, 'crash_on_error')
> + try:
> + tmp = banner_module.ConfigFile.format_variable(args[1], bool, 'crash_on_error')
> + except Exception:
> + if args[1].lower() in ['never']:
> + tmp = args[1].lower()
> + else:
> + raise
> self.options[args[0]] = tmp
> elif args[0] in ['cluster_queue']:
> self.options[args[0]] = args[1].strip()

and then to add the following line to your script:
> set crash_on_error never

In that case, you will still see the error printed on the screen, but the code will continue like if nothing was happening, (i.e. like what is happening with the command line interface).
(Obviously using such command requires that you check the log very carefully since ALL error are ignored by that flag.

Cheers,

Olivier

> On 28 Nov 2018, at 18:16, andlessa <email address hidden> wrote:
>
> New question #676427 on MadGraph5_aMC@NLO:
> https://answers.launchpad.net/mg5amcnlo/+question/676427
>
> Hi,
> I'm trying to generate several processes at once using "add process", but if some of the processes do not have diagrams the "NoDiagramException" is raised and madgraph exits. Would it be possible to simply print the error message and go to the next process without stopping the process generation?
> I could work around this issue simply removing the exception.
> But if you do not see potential issues with this fix, it would be very helpful if this was incorporated into future MadGraph releases.
>
> Best,
>
> -Andre
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Can you help with this problem?

Provide an answer of your own, or ask andlessa for more information if necessary.

To post a message you must log in.