<commit_before># coding=utf-8
# Copyright 2022 Google LLC.
#
# 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 experiment_registry."""
from absl.testing import absltest
from paxml import base_experiment
from paxml import experiment_registry
from paxml.tasks.test.params import synthetic  # pylint: disable=unused-import
from praxis import layers


@experiment_registry.register
class DummyExperiment(base_experiment.BaseExperiment):
  """A docstring.

  @platform: pf_4x4x8
  @foo_tag: foo_value
  """

  def datasets(self):
    return []

  def task(self):
    act_p = layers.Activation.HParams()
    return act_p


@experiment_registry.register()
class SharedNameExperiment(DummyExperiment):
  pass


# This tests that explicit re-register works.
@experiment_registry.register(allow_overwrite=True)
class SharedNameExperiment(DummyExperiment):  # pylint: disable=function-redefined
  pass


class ExperimentRegistryTest(absltest.TestCase):

  def test_get(self):
    # Module name is `__main__` when registering locally like here.
    dummy_experiment_cls = experiment_registry.get('__main__.DummyExperiment')
    dummy_experiment = dummy_experiment_cls()
    self.assertEmpty(dummy_experiment.datasets())
    self.assertIsNotNone(dummy_experiment.task())
    dummy_experiment_cls2 = experiment_registry.get('DummyExperiment')
    self.assertEqual(dummy_experiment_cls2, dummy_experiment_cls)

    self.assertIsNone(experiment_registry.get('DummyExperimentNotDefined'))

  def test_get_docstring_tags(self):
    tags = experiment_registry.get_docstring_tags('DummyExperiment')
    self.assertEqual(tags, {'foo_tag': 'foo_value', 'platform': 'pf_4x4x8'})<commit_msg>fix tests to be order independent.<commit_after># coding=utf-8
# Copyright 2022 Google LLC.
#
# 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 experiment_registry."""
from absl.testing import absltest
from paxml import base_experiment
from paxml import experiment_registry
from paxml.tasks.test.params import synthetic  # pylint: disable=unused-import
from praxis import layers


@experiment_registry.register
class DummyExperiment(base_experiment.BaseExperiment):

  def datasets(self):
    return []

  def task(self):
    act_p = layers.Activation.HParams()
    return act_p


@experiment_registry.register
class DocstringExp(DummyExperiment):
  """A docstring.

  @platform: pf_4x4x8
  @foo_tag: foo_value
  """


@experiment_registry.register()
class SharedNameExperiment(DummyExperiment):
  pass


# This tests that explicit re-register works.
@experiment_registry.register(allow_overwrite=True)
class SharedNameExperiment(DummyExperiment):  # pylint: disable=function-redefined
  pass


class ExperimentRegistryTest(absltest.TestCase):

  def test_get(self):
    # Module name is `__main__` when registering locally like here.
    dummy_experiment_cls = experiment_registry.get('__main__.DummyExperiment')
    dummy_experiment = dummy_experiment_cls()
    self.assertEmpty(dummy_experiment.datasets())
    self.assertIsNotNone(dummy_experiment.task())
    dummy_experiment_cls2 = experiment_registry.get('DummyExperiment')
    self.assertEqual(dummy_experiment_cls2, dummy_experiment_cls)

    self.assertIsNone(experiment_registry.get('DummyExperimentNotDefined'))

  def test_get_docstring_tags(self):
    tags = experiment_registry.get_docstring_tags('DocstringExp')
    self.assertEqual(tags, {'foo_tag': 'foo_value', 'platform': 'pf_4x4x8'})
{'fraction_non_alphanumeric': 0.08609420779806175, 'fraction_numerical': 0.007662835249042145, 'mean_word_length': 5.478832116788321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879608', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1292, 'n_words': 359}