<commit_before>from openpathsampling.experimental.simstore.custom_json import JSONCodec
from openpathsampling.experimental.simstore.attribute_handlers import (
    AttributeHandler, NDArrayHandler
)
import re

from openpathsampling.integration_tools import HAS_SIMTK, unit

if HAS_SIMTK:
    # note that we need to force simstore to not treat this as an iterable
    from openpathsampling.experimental.simstore.class_lookup import \
        is_storage_iterable
    is_storage_iterable.force_false(unit.Quantity)

### JSON SERIALIZATION ###################################################

def unit_to_dict(obj):
    return {p.name: int(power)
            for p, power in obj.iter_base_or_scaled_units()}

def unit_from_dict(dct):
    unit = unit.Unit({})
    for u_name, u_power in dct.items():
        unit *= getattr(unit, u_name) ** u_power
    return unit

def quantity_to_dict(obj):
    return {'value': obj.value_in_unit(obj.unit),
            '__simtk_unit__': unit_to_dict(obj.unit)}

def quantity_from_dict(dct):
    unit = unit_from_dict(dct['__simtk_unit__'])
    return dct['value'] * unit


if HAS_SIMTK:
    simtk_quantity_codec = JSONCodec(
        cls=unit.Quantity,<commit_msg>HAS_SIMTK => HAS_SIMTK_UNIT<commit_after>from openpathsampling.experimental.simstore.custom_json import JSONCodec
from openpathsampling.experimental.simstore.attribute_handlers import (
    AttributeHandler, NDArrayHandler
)
import re

from openpathsampling.integration_tools import HAS_SIMTK_UNIT, unit

if HAS_SIMTK_UNIT:
    # note that we need to force simstore to not treat this as an iterable
    from openpathsampling.experimental.simstore.class_lookup import \
        is_storage_iterable
    is_storage_iterable.force_false(unit.Quantity)

### JSON SERIALIZATION ###################################################

def unit_to_dict(obj):
    return {p.name: int(power)
            for p, power in obj.iter_base_or_scaled_units()}

def unit_from_dict(dct):
    unit = unit.Unit({})
    for u_name, u_power in dct.items():
        unit *= getattr(unit, u_name) ** u_power
    return unit

def quantity_to_dict(obj):
    return {'value': obj.value_in_unit(obj.unit),
            '__simtk_unit__': unit_to_dict(obj.unit)}

def quantity_from_dict(dct):
    unit = unit_from_dict(dct['__simtk_unit__'])
    return dct['value'] * unit


if HAS_SIMTK_UNIT:
    simtk_quantity_codec = JSONCodec(
        cls=unit.Quantity,
{'fraction_non_alphanumeric': 0.126603227141084, 'fraction_numerical': 0.0, 'mean_word_length': 4.45823927765237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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}}
{'dir': 'git-commits-cleaned', 'id': '5101988', 'n_tokens_mistral': 802, 'n_tokens_neox': 766, 'n_words': 166}