Constraint(约束条件) 模块¶
ppsci.constraint
¶
Constraint
¶
Base class for constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
Dataset
|
Dataset. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
name |
str
|
Name of constraint. |
required |
Source code in ppsci/constraint/base.py
BoundaryConstraint
¶
Bases: Constraint
Class for boundary constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
Geometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified boundaries. Defaults to None. |
None
|
evenly |
bool
|
Whether to use evenly distribution sampling. Defaults to False. |
False
|
weight_dict |
Optional[Dict[str, Union[float, Callable]]]
|
Define the weight of each constraint variable. Defaults to None. |
None
|
name |
str
|
Name of constraint object. Defaults to "BC". |
'BC'
|
Examples:
>>> import ppsci
>>> rect = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> bc = ppsci.constraint.BoundaryConstraint(
... {"u": lambda out: out["u"]},
... {"u": 0},
... rect,
... {
... "dataset": "IterableNamedArrayDataset",
... "iters_per_epoch": 1,
... "batch_size": 16,
... },
... ppsci.loss.MSELoss("mean"),
... name="BC",
... )
Source code in ppsci/constraint/boundary_constraint.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
InitialConstraint
¶
Bases: Constraint
Class for initial interior constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
TimeXGeometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified boundaries. Defaults to None. |
None
|
evenly |
bool
|
Whether to use evenly distribution sampling. Defaults to False. |
False
|
weight_dict |
Optional[Dict[str, Callable]]
|
Define the weight of each constraint variable. Defaults to None. |
None
|
compute_sdf_derivatives |
Optional[bool]
|
Whether compute derivatives for SDF. Defaults to False. |
False
|
name |
str
|
Name of constraint object. Defaults to "IC". |
'IC'
|
Examples:
>>> import ppsci
>>> rect = ppsci.geometry.TimeXGeometry(
... ppsci.geometry.TimeDomain(0, 1),
... ppsci.geometry.Rectangle((0, 0), (1, 1)),
... )
>>> ic = ppsci.constraint.InitialConstraint(
... {"u": lambda out: out["u"]},
... {"u": 0},
... rect,
... {
... "dataset": "IterableNamedArrayDataset",
... "iters_per_epoch": 1,
... "batch_size": 16,
... },
... ppsci.loss.MSELoss("mean"),
... name="IC",
... )
Source code in ppsci/constraint/initial_constraint.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
IntegralConstraint
¶
Bases: Constraint
Class for integral constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
Geometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified boundaries. Defaults to None. |
None
|
weight_dict |
Optional[Dict[str, Callable]]
|
Define the weight of each constraint variable. Defaults to None. |
None
|
name |
str
|
Name of constraint object. Defaults to "IgC". |
'IgC'
|
Examples:
>>> import ppsci
>>> rect = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> igc = ppsci.constraint.IntegralConstraint(
... {"u": lambda out: out["u"]},
... {"u": 0},
... rect,
... {
... "dataset": "IterableNamedArrayDataset",
... "iters_per_epoch": 1,
... "batch_size": 16,
... "integral_batch_size": 8,
... },
... ppsci.loss.MSELoss("mean"),
... name="IgC",
... )
Source code in ppsci/constraint/integral_constraint.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
InteriorConstraint
¶
Bases: Constraint
Class for interior constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
Geometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified boundaries. Defaults to None. |
None
|
evenly |
bool
|
Whether to use evenly distribution sampling. Defaults to False. |
False
|
weight_dict |
Optional[Dict[str, Union[Callable, float]]]
|
Define the weight of each constraint variable. Defaults to None. |
None
|
compute_sdf_derivatives |
Optional[bool]
|
Whether compute derivatives for SDF. Defaults to False. |
False
|
name |
str
|
Name of constraint object. Defaults to "EQ". |
'EQ'
|
Examples:
>>> import ppsci
>>> rect = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> pde_constraint = ppsci.constraint.InteriorConstraint(
... {"u": lambda out: out["u"]},
... {"u": 0},
... rect,
... {
... "dataset": "IterableNamedArrayDataset",
... "iters_per_epoch": 1,
... "batch_size": 16,
... },
... ppsci.loss.MSELoss("mean"),
... name="EQ",
... )
Source code in ppsci/constraint/interior_constraint.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
PeriodicConstraint
¶
Bases: Constraint
Class for periodic constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
Geometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
periodic_key |
str
|
Name of dimension which periodic constraint applied to. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified boundaries. Defaults to None. |
None
|
evenly |
bool
|
Whether to use evenly distribution sampling. Defaults to False. |
False
|
weight_dict |
Optional[Dict[str, Callable]]
|
Define the weight of each constraint variable. Defaults to None. |
None
|
name |
str
|
Name of constraint object. Defaults to "PeriodicBC". |
'PeriodicBC'
|
Source code in ppsci/constraint/periodic_constraint.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
SupervisedConstraint
¶
Bases: Constraint
Class for supervised constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
output_expr |
Optional[Dict[str, Callable]]
|
List of label expression. Defaults to None. |
None
|
name |
str
|
Name of constraint object. Defaults to "Sup". |
'Sup'
|
Examples:
>>> import ppsci
>>> bc_sup = ppsci.constraint.SupervisedConstraint(
... {
... "dataset": {
... "name": "IterableCSVDataset",
... "file_path": "/path/to/file.csv",
... "input_keys": ("x", "y"),
... "label_keys": ("u", "v"),
... },
... },
... ppsci.loss.MSELoss("mean"),
... name="bc_sup",
... )