<commit_before>from __future__ import print_function

__all__ = ['Options', 'Odeoptions', 'Odedata', 'ExpectOps']

import os
import sys
import warnings
import datetime
import numpy as np
from qutip.qobjevo import QobjEvo
from collections import OrderedDict
from qutip import __version__
from qutip.qobj import Qobj
import qutip.settings as qset
from types import FunctionType, BuiltinFunctionType

solver_safe = {}


class SolverSystem():
    pass


class ExpectOps:
    """
        Contain and compute expectation values
    """
    def __init__(self, e_ops=[], super_=False):
        # take care of expectation values, if any
        self.isfunc = False
        self.e_ops_dict = False
        self.raw_e_ops = e_ops
        self.e_ops_qoevo = []
        self.e_num = 0
        self.e_ops_isherm = []

        if isinstance(e_ops, (Qobj, QobjEvo)):
            e_ops = [e_ops]
        elif isinstance(e_ops, dict):
            self.e_ops_dict = e_ops
            e_ops = [e for e in e_ops.values()]

        self.e_ops = e_ops
        if isinstance(e_ops, list):
            self.e_num = len(e_ops)
            self.e_ops_isherm = [e.isherm for e in e_ops]
            if not super_:
                self.e_ops_qoevo = np.array([QobjEvo(e) for e in e_ops],
                                            dtype=object)
            else:
                self.e_ops_qoevo = np.array([QobjEvo(spre(e)) for e in e_ops],
                                            dtype=object)
            [op.compile() for op in self.e_ops_qoevo]
        elif callable(e_ops):
            self.isfunc = True
            self.e_num = 1

    def init(self, tlist):
        self.tlist = tlist
        if self.isfunc:
            self.raw_out = []
        else:
            self.raw_out = np.zeros((self.e_num, len(tlist)), dtype=complex)

    def copy(self):
        out = ExpectOps.__new__(ExpectOps)
        out.isfunc = self.isfunc
        out.e_ops_dict = self.e_ops_dict
        out.raw_e_ops = self.raw_e_ops
        out.e_ops = self.e_ops
        out.e_num = self.e_num
        out.e_ops_isherm = self.e_ops_isherm
        out.e_ops_qoevo = self.e_ops_qoevo
        return out

    def step(self, iter_, state):
        if self.isfunc:
            self.raw_out.append(self.e_ops(t, state))
        else:
            t = self.tlist[iter_]
            for ii in range(self.e_num):
                self.raw_out[ii, iter_] = \
                    self.e_ops_qoevo[ii].compiled_qobjevo.expect(t, state)

    def finish(self):
        if self.isfunc:
            result = self.raw_out
        else:
            result = []
            for ii in range(self.e_num):
                if self.e_ops_isherm[ii]:
                    result.append(np.real(self.raw_out[ii, :]))
                else:
                    result.append(self.raw_out[ii, :])
            if self.e_ops_dict:
                result = {e: result[n]
                          for n, e in enumerate(self.e_ops_dict.keys())}
        return result

    def __eq__(self, other):
        if isinstance(other, ExpectOps):
            other = other.raw_e_ops
        return self.raw_e_ops == other

    def __ne__(self, other):
        return not (self == other)

    def __bool__(self):
        return bool(self.e_num)


class Options():<commit_msg>drafting the implementation of passing multiple callable functions for performing measurements<commit_after>from __future__ import print_function

__all__ = ['Options', 'Odeoptions', 'Odedata', 'ExpectOps']

import os
import sys
import warnings
import datetime
import numpy as np
from qutip.qobjevo import QobjEvo
from collections import OrderedDict
from qutip import __version__
from qutip.qobj import Qobj
import qutip.settings as qset
from types import FunctionType, BuiltinFunctionType

solver_safe = {}


class SolverSystem():
    pass


class ExpectOps:
    """
        Contain and compute expectation values
    """
    def __init__(self, e_ops=[], super_=False):
        # take care of expectation values, if any
        self.isfunc = False
        self.e_ops_dict = False
        self.raw_e_ops = e_ops
        self.e_ops_qoevo = []
        self.e_num = 0
        self.e_ops_isherm = []

        if isinstance(e_ops, (Qobj, QobjEvo)):
            e_ops = [e_ops]
        elif isinstance(e_ops, dict):
            self.e_ops_dict = e_ops
            e_ops = [e for e in e_ops.values()]

        self.e_ops = e_ops
        if isinstance(e_ops, list):
            self.e_num = len(e_ops)
            e_ops_qoevo = []
            e_ops_isherm = []
            for e in e_ops:
                if isinstance(e, (Qobj, QobjEvo)):
                    e_ops_isherm.append(e.isherm)
                    e_ops_qoevo_entry = None
                    if not super_:
                        e_ops_qoevo_entry = QobjEvo(e)
                    else:
                        e_ops_qoevo_entry = QobjEvo(spre(e))
                    e_ops_qoevo_entry.compile()
                    e_ops_qoevo.append(e_ops_qoevo_entry)
                elif callable(e):
                    e_ops_isherm.append(None)
                    e_ops_qoevo.append(e)
                else:
                    raise TypeError("Expectation value list entry needs to be either a function either an operator")
            self.e_ops_isherm = e_ops_isherm
            self.e_ops_qoevo = np.array(e_ops_qoevo, dtype=object)
        elif callable(e_ops):
            self.isfunc = True
            self.e_num = 1

    def init(self, tlist):
        self.tlist = tlist
        if self.isfunc:
            self.raw_out = []
        else:
            self.raw_out = np.zeros((self.e_num, len(tlist)), dtype=complex)

    def copy(self):
        out = ExpectOps.__new__(ExpectOps)
        out.isfunc = self.isfunc
        out.e_ops_dict = self.e_ops_dict
        out.raw_e_ops = self.raw_e_ops
        out.e_ops = self.e_ops
        out.e_num = self.e_num
        out.e_ops_isherm = self.e_ops_isherm
        out.e_ops_qoevo = self.e_ops_qoevo
        return out

    def step(self, iter_, state):
        if self.isfunc:
            self.raw_out.append(self.e_ops(t, state))
        else:
            t = self.tlist[iter_]
            for ii in range(self.e_num):
                if isinstance(ii, (Qobj, QobjEvo)):
                    self.raw_out[ii, iter_] = \
                        self.e_ops_qoevo[ii].compiled_qobjevo.expect(t, state)
                elif callable(ii):
                    self.raw_out[ii, iter_] = \
                        self.e_ops_qoevo[ii](t, state)
    def finish(self):
        if self.isfunc:
            result = self.raw_out
        else:
            result = []
            for ii in range(self.e_num):
                if self.e_ops_isherm[ii]:
                    result.append(np.real(self.raw_out[ii, :]))
                else:
                    result.append(self.raw_out[ii, :])
            if self.e_ops_dict:
                result = {e: result[n]
                          for n, e in enumerate(self.e_ops_dict.keys())}
        return result

    def __eq__(self, other):
        if isinstance(other, ExpectOps):
            other = other.raw_e_ops
        return self.raw_e_ops == other

    def __ne__(self, other):
        return not (self == other)

    def __bool__(self):
        return bool(self.e_num)


class Options():
{'fraction_non_alphanumeric': 0.09141842033342443, 'fraction_numerical': 0.0005465974309920743, 'mean_word_length': 1.7027326440177253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6091211', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2322, 'n_words': 521}