Skip to content

Richer description in check_consistency function #551

@dario-coscia

Description

@dario-coscia

Is your feature request related to a problem? Please describe.
PINA modules heavily rely on the check_consistency function. This function is used to throw errors when passing an invalid instance or class object. The error message, however, is very short and, most of the time, unclear:

>>> from pina.solver import PINN
>>> PINN(2, 3)
ValueError: int must be <class 'pina.problem.abstract_problem.AbstractProblem'>.

Describe the solution you'd like
It would be nice to have a richer and more informative error message, something like:

  1. subclass=true but instance passed
ValueError: You passed <wrong_instance> instance, but a <true_class> class was expected. Please pass a <true_object> class or a derived one. 
  1. subclass=true but wrong classe
ValueError: You passed <wrong_class> class, but a <true_class> class was expected. Please pass a <true_object> class or a derived one. 
  1. subclass=False but class passed
ValueError: You passed <wrong_class> class, but a <true_instance> instance was expected. Please pass a <true_instance> instance. 
  1. subclass=False but wrong instance
ValueError: You passed <wrong_instance> instance, but a <true_instance> instance was expected. Please pass a <true_instance> instance. 

Describe alternatives you've considered
Maybe we should wrap this into a more structured class for handling errors in PINA.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions