<commit_before>"""Drudge for wick-style algebraic systems.

In this module, we have a abstract base class for Wick-style algebraic systems,
as well as function helpful for its subclasses.
"""

import abc
import collections
import typing

from pyspark import RDD
from sympy import Expr

from .drudge import Drudge
from .term import Term, Vec, simplify_deltas_in_expr, compose_simplified_delta
from .utils import sympy_key


class WickDrudge(Drudge, abc.ABC):
    """Drudge for Wick-style algebras.

    A Wick-style algebra is an algebraic system where the commutator between any
    generators of the algebra is a simple scalar value.  This drudge will
    attempt to put the vectors into normal order based on the given comparator
    and contractor by Wick theorem.

    """

    @abc.abstractproperty
    def contractor(self) -> typing.Callable[[Vec, Vec, Term], Expr]:
        """Get the contractor for the algebraic system.

        The contractor is going to be called with two vectors to return the
        value of their contraction.

        """
        pass

    @abc.abstractproperty
    def phase(self):
        """Get the phase for the commutation rule.
<commit_msg>Add option for Wick parallelization levels<commit_after>"""Drudge for wick-style algebraic systems.

In this module, we have a abstract base class for Wick-style algebraic systems,
as well as function helpful for its subclasses.
"""

import abc
import collections
import typing

from pyspark import RDD
from sympy import Expr

from .drudge import Drudge
from .term import Term, Vec, simplify_deltas_in_expr, compose_simplified_delta
from .utils import sympy_key


class WickDrudge(Drudge, abc.ABC):
    """Drudge for Wick-style algebras.

    A Wick-style algebra is an algebraic system where the commutator between any
    generators of the algebra is a simple scalar value.  This drudge will
    attempt to put the vectors into normal order based on the given comparator
    and contractor by Wick theorem.

    """

    def __init__(self, *args, **kwargs):
        """Initialize the Wick drudge.

        This level just have one option to handle, the parallelism option.
        """
        super().__init__(*args, **kwargs)
        self._wick_parallel = 0

    @property
    def wick_parallel(self):
        """Get the Wick parallelism level."""
        return self._wick_parallel

    def set_wick_parallel(self, level):
        """Set the Wick parallelism level.

        Valid values are ``0``, for normal problems, ``1``, for harder problems,
        and ``2``, for really hard expressions containing just a few terms.

        """

        if level not in {0, 1, 2}:
            raise ValueError(
                'Invalid parallel level for Wick expansion', level
            )
        self._wick_parallel = level
        return self

    @abc.abstractproperty
    def contractor(self) -> typing.Callable[[Vec, Vec, Term], Expr]:
        """Get the contractor for the algebraic system.

        The contractor is going to be called with two vectors to return the
        value of their contraction.

        """
        pass

    @abc.abstractproperty
    def phase(self):
        """Get the phase for the commutation rule.

{'fraction_non_alphanumeric': 0.06816059757236227, 'fraction_numerical': 0.002178649237472767, 'mean_word_length': 2.919512195121951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '566944', 'n_tokens_mistral': 901, 'n_tokens_neox': 819, 'n_words': 380}