<jupyter_start><jupyter_text>RegistryJust being able to look up a models class by name. Needed to be able to serializeclients and servers to json or database.<jupyter_code># export

from pydantic import BaseModel


CLASS_REGISTRY = {}


def register_model(model_class):
    global CLASS_REGISTRY
    CLASS_REGISTRY[model_class.__name__] = model_class
    return model_class


def get_model_from_registry(class_name):
    return CLASS_REGISTRY[class_name]
@register_model
class StubServer(BaseModel):
    name: str = "stub server"<jupyter_output><empty_output><jupyter_text>Usage<jupyter_code>server = StubServer(name="foobar")
server_class = get_model_from_registry(server.__class__.__name__)<jupyter_output><empty_output><jupyter_text>Tests<jupyter_code>assert StubServer == get_model_from_registry(str(server.__class__.__name__))
server = StubServer(name="foobar")
assert get_model_from_registry("StubServer") == StubServer<jupyter_output><empty_output><jupyter_text>Parameter ModelsThey are used to serialize clients and servers from and to plain python dicts which then could be serialized to json. It's not clear which Server should be created when we accept a BaseServer. Therefore we transfer a model_parameter instance and have a lookup table to choose the right model.<jupyter_code># export


class ModelParameters(BaseModel):
    class_name: str
    parameters: dict

    def to_model(self):
        return get_model_from_registry(self.class_name)(**self.parameters)
@register_model
class StubSerializableServer(BaseModel):
    name: str = "stub server"

    def params(self):
        return {
            "class_name": self.__class__.__name__,
            "parameters": self.dict(),
        }<jupyter_output><empty_output><jupyter_text>Usage<jupyter_code># dont_test

name = "Some Server"
server = StubSerializableServer(name=name)

server_parameters = ModelParameters(**server.params())

server_from_params = server_parameters.to_model()<jupyter_output><empty_output><jupyter_text>Tests<jupyter_code>name = "Test Server"
server = StubSerializableServer(name=name)

server_parameters = ModelParameters(**server.params())
server_from_params = server_parameters.to_model()

assert server == server_from_params
# hide
# dont_test

from nbdev.export import notebook2script

notebook2script()<jupyter_output>Converted 00_host.ipynb.
Converted 01_django_views.ipynb.
Converted 01_fastapi_views.ipynb.
Converted 01_file.ipynb.
Converted 05_epochs.ipynb.
Converted 06_results.ipynb.
Converted 100_benchmark_remote_control_server.ipynb.
Converted 10_registry.ipynb.
Converted 25_core.ipynb.
Converted 27_control_server.ipynb.
Converted 28_control_client.ipynb.
Converted 29_control_cli.ipynb.
Converted 30_servers.ipynb.
Converted 31_local_servers.ipynb.
Converted 32_docker_servers.ipynb.
Converted 40_clients.ipynb.
Converted 41_benchmark_clients.ipynb.
Converted 70_repositories.ipynb.
Converted 71_sqlite_repository.ipynb.
Converted 90_benchmark_without_benchmark.ipynb.
Converted 98_run_benchmark.ipynb.
Converted index.ipynb.
{'fraction_non_alphanumeric': 0.07978898780085723, 'fraction_numerical': 0.01483679525222552, 'mean_word_length': 6.642317380352645, 'pattern_counts': {'":': 2, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '531691', 'license': 'Apache-2.0', 'n_tokens_mistral': 1058, 'n_tokens_neox': 999, 'n_words': 205, 'path': '03_registry.ipynb', 'repo_name': 'ephes/will_it_saturate', 'size': '3033'}