-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PiperOrigin-RevId: 732238534
- Loading branch information
Showing
32 changed files
with
130 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+32.7 KB
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector.nc
Binary file not shown.
Binary file modified
BIN
+16.3 KB
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_clip_inputs.nc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...sts/test_data/test_iterhybrid_predictor_corrector_constant_fraction_impurity_radiation.nc
Binary file not shown.
Binary file modified
BIN
+33 KB
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_cyclotron.nc
Binary file not shown.
Binary file modified
BIN
-66.9 KB
(92%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_ec_linliu.nc
Binary file not shown.
Binary file modified
BIN
+32.7 KB
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_eqdsk.nc
Binary file not shown.
Binary file modified
BIN
+16.3 KB
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_set_pped_tpedratio_nped.nc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_timedependent_isotopes.nc
Binary file not shown.
Binary file modified
BIN
+54.8 KB
(110%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_tungsten.nc
Binary file not shown.
Binary file modified
BIN
+206 KB
(130%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_zeffprofile.nc
Binary file not shown.
Binary file modified
BIN
-405 KB
(51%)
torax/tests/test_data/test_iterhybrid_predictor_corrector_zi2.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2024 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests for qlknn_model_wrapper.""" | ||
|
||
import tempfile | ||
|
||
from absl.testing import absltest | ||
from absl.testing import parameterized | ||
import jax.numpy as jnp | ||
from torax.transport_model import qlknn_model_wrapper | ||
# pylint: disable=g-import-not-at-top | ||
try: | ||
from fusion_transport_surrogates import qlknn_model_test_utils | ||
except ImportError: | ||
qlknn_model_test_utils = None | ||
# pylint: enable=g-import-not-at-top | ||
|
||
|
||
def _get_test_flux_name_map(): | ||
if qlknn_model_test_utils is None: | ||
return {} | ||
return dict( | ||
(flux_name, f'torax_{flux_name}') | ||
for flux_name in qlknn_model_test_utils.get_test_flux_map().keys() | ||
) | ||
|
||
|
||
class QlknnModelWrapperTest(parameterized.TestCase): | ||
"""Tests for qlknn_model_wrapper.""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
if qlknn_model_test_utils is None: | ||
self.skipTest('fusion_transport_surrogates is not available.') | ||
# Create a test model on disk to be loaded by the wrapper. | ||
self._config = qlknn_model_test_utils.get_test_model_config() | ||
self._batch_dim = 10 | ||
batch_dims = (1, self._batch_dim) | ||
model = qlknn_model_test_utils.init_model(self._config, batch_dims) | ||
self._model_file = tempfile.NamedTemporaryFile( | ||
'wb', suffix='.pkl', delete=False | ||
) | ||
self._flux_name_map = _get_test_flux_name_map() | ||
model.export_model(self._model_file.name) | ||
self._qlknn_model_wrapper = qlknn_model_wrapper.QLKNNModelWrapper( | ||
path=self._model_file.name, | ||
flux_name_map=self._flux_name_map | ||
) | ||
|
||
def test_predict_shape(self): | ||
"""Tests model output shape.""" | ||
inputs = jnp.empty((self._batch_dim, len(self._config.input_names))) | ||
outputs = self._qlknn_model_wrapper.predict(inputs) | ||
self.assertLen(outputs, len(self._flux_name_map)) | ||
for output in outputs.values(): | ||
self.assertEqual(output.shape, (self._batch_dim, 1)) | ||
|
||
def test_predict_names(self): | ||
"""Tests model output names are the TORAX flux names.""" | ||
inputs = jnp.empty((self._batch_dim, len(self._config.input_names))) | ||
outputs = self._qlknn_model_wrapper.predict(inputs) | ||
for flux_name in self._flux_name_map.values(): | ||
self.assertIn(flux_name, outputs) | ||
|
||
# TODO(b/381134347): Add tests for get_model_inputs_from_qualikiz_inputs | ||
# and inputs_and_ranges. | ||
|
||
|
||
if __name__ == '__main__': | ||
absltest.main() |