11"""Condition module."""
22
3- from .domain_equation_condition import DomainEquationCondition
4- from .input_equation_condition import InputPointsEquationCondition
5- from .input_output_condition import InputOutputPointsCondition
6- from .data_condition import DataConditionInterface
73import warnings
4+ from .data_condition import DataCondition
5+ from .domain_equation_condition import DomainEquationCondition
6+ from .input_equation_condition import InputEquationCondition
7+ from .input_target_condition import InputTargetCondition
88from ..utils import custom_warning_format
99
1010# Set the custom format for warnings
1111warnings .formatwarning = custom_warning_format
1212warnings .filterwarnings ("always" , category = DeprecationWarning )
1313
1414
15+ def warning_function (new , old ):
16+ """Handle the deprecation warning.
17+
18+ :param new: Object to use instead of the old one.
19+ :type new: str
20+ :param old: Object to deprecate.
21+ :type old: str
22+ """
23+ warnings .warn (
24+ f"'{ old } ' is deprecated and will be removed "
25+ f"in future versions. Please use '{ new } ' instead." ,
26+ DeprecationWarning ,
27+ )
28+
29+
1530class Condition :
1631 """
1732 The class ``Condition`` is used to represent the constraints (physical
@@ -40,16 +55,32 @@ class Condition:
4055
4156 Example::
4257
43- >>> TODO
58+ >>> from pina import Condition
59+ >>> condition = Condition(
60+ ... input=input,
61+ ... target=target
62+ ... )
63+ >>> condition = Condition(
64+ ... domain=location,
65+ ... equation=equation
66+ ... )
67+ >>> condition = Condition(
68+ ... input=input,
69+ ... equation=equation
70+ ... )
71+ >>> condition = Condition(
72+ ... input=data,
73+ ... conditional_variables=conditional_variables
74+ ... )
4475
4576 """
4677
4778 __slots__ = list (
4879 set (
49- InputOutputPointsCondition .__slots__
50- + InputPointsEquationCondition .__slots__
80+ InputTargetCondition .__slots__
81+ + InputEquationCondition .__slots__
5182 + DomainEquationCondition .__slots__
52- + DataConditionInterface .__slots__
83+ + DataCondition .__slots__
5384 )
5485 )
5586
@@ -62,25 +93,30 @@ def __new__(cls, *args, **kwargs):
6293 )
6394
6495 # back-compatibility 0.1
65- if "location" in kwargs .keys ():
96+ keys = list (kwargs .keys ())
97+ if "location" in keys :
6698 kwargs ["domain" ] = kwargs .pop ("location" )
67- warnings .warn (
68- f"'location' is deprecated and will be removed "
69- f"in future versions. Please use 'domain' instead." ,
70- DeprecationWarning ,
71- )
99+ warning_function (new = "domain" , old = "location" )
72100
73- sorted_keys = sorted (kwargs .keys ())
101+ if "input_points" in keys :
102+ kwargs ["input" ] = kwargs .pop ("input_points" )
103+ warning_function (new = "input" , old = "input_points" )
74104
75- if sorted_keys == sorted (InputOutputPointsCondition .__slots__ ):
76- return InputOutputPointsCondition (** kwargs )
77- elif sorted_keys == sorted (InputPointsEquationCondition .__slots__ ):
78- return InputPointsEquationCondition (** kwargs )
79- elif sorted_keys == sorted (DomainEquationCondition .__slots__ ):
105+ if "output_points" in keys :
106+ kwargs ["target" ] = kwargs .pop ("output_points" )
107+ warning_function (new = "target" , old = "output_points" )
108+
109+ sorted_keys = sorted (kwargs .keys ())
110+ if sorted_keys == sorted (InputTargetCondition .__slots__ ):
111+ return InputTargetCondition (** kwargs )
112+ if sorted_keys == sorted (InputEquationCondition .__slots__ ):
113+ return InputEquationCondition (** kwargs )
114+ if sorted_keys == sorted (DomainEquationCondition .__slots__ ):
80115 return DomainEquationCondition (** kwargs )
81- elif sorted_keys == sorted (DataConditionInterface .__slots__ ):
82- return DataConditionInterface (** kwargs )
83- elif sorted_keys == DataConditionInterface .__slots__ [0 ]:
84- return DataConditionInterface (** kwargs )
85- else :
86- raise ValueError (f"Invalid keyword arguments { kwargs .keys ()} ." )
116+ if (
117+ sorted_keys == sorted (DataCondition .__slots__ )
118+ or sorted_keys [0 ] == DataCondition .__slots__ [0 ]
119+ ):
120+ return DataCondition (** kwargs )
121+
122+ raise ValueError (f"Invalid keyword arguments { kwargs .keys ()} ." )
0 commit comments