<commit_before>import pycqed.utilities.general as gen
import logging

log = logging.getLogger(__name__)

def reload_settings(timestamp=None, timestamp_filters=None, load_flux_bias=True,
                    virtual_setup=False,
                    qubits=None, dev=None,
                    DCSources=None,
                    **kw):
    """
    Reload settings from the database.
    """
    if dev is None:
        raise ValueError('dev must be specified')
    else:
        qubits = dev.get_qubits()

    qbs = kw.get('qubits', kw.get('qbs', None))
    if qbs is None:
        qbs = qubits

    gen.load_settings(dev, timestamp=timestamp)
    for qb in qbs:
        gen.load_settings(qb, timestamp=timestamp)
        if timestamp_filters is not None:
            gen.load_settings(qb, timestamp=timestamp_filters,
                              params_to_set=[f'flux_distortion'])
        # set offsets and create filters in pulsar based on settings in the qubits
        try:
            qb.configure_pulsar()
        except Exception:
            if not virtual_setup:
                raise
    try:
        dev.configure_pulsar()
    except Exception:
        if not virtual_setup:
            raise

    if load_flux_bias:  # reload and set flux bias

        if DCSources is None:
            ts = f"({timestamp}) " if timestamp is not None else ""
            log.warning(f"DCSources must be specified if user wants to load flux bias. DCSources NOT reloaded. You can retry loading the settings {ts}by either passing the DCSources or by reloading settings manually with the reload_settings method from init script")
            return

        for DCSource in DCSources:
            DCSource_params = gen.load_settings(DCSource, timestamp=timestamp,
                                                update=False)
            set_fluxline_dict = {'fluxline_' + qb.name[2:]:
                                     eval(DCSource_params['volt_fluxline_' + qb.name[2:]])
                                 for qb in qubits if qb in qbs}
            print(f"Setting flux line voltages to {set_fluxline_dict}")
            if 'Virtual' in DCSource.__class__.__name__:
                for k, v in set_fluxline_dict.items():
                    DCSource.set(f'volt_{k}', v)
            else:
                DCSource.set_smooth(set_fluxline_dict)<commit_msg>utilities.reload_settings: avoid hard-coded names of fluxlines<commit_after>import pycqed.utilities.general as gen
import logging

log = logging.getLogger(__name__)

def reload_settings(timestamp=None, timestamp_filters=None, load_flux_bias=True,
                    virtual_setup=False,
                    qubits=None, dev=None,
                    DCSources=None,
                    fluxlines_dict=None,
                    **kw):
    """
    Reload settings from the database.
    """
    if dev is None:
        raise ValueError('dev must be specified')
    else:
        qubits = dev.get_qubits()

    qbs = kw.get('qubits', kw.get('qbs', None))
    if qbs is None:
        qbs = qubits

    gen.load_settings(dev, timestamp=timestamp)
    for qb in qbs:
        gen.load_settings(qb, timestamp=timestamp)
        if timestamp_filters is not None:
            gen.load_settings(qb, timestamp=timestamp_filters,
                              params_to_set=[f'flux_distortion'])
        # set offsets and create filters in pulsar based on settings in the qubits
        try:
            qb.configure_pulsar()
        except Exception:
            if not virtual_setup:
                raise
    try:
        dev.configure_pulsar()
    except Exception:
        if not virtual_setup:
            raise

    if load_flux_bias:  # reload and set flux bias

        if DCSources is None or fluxlines_dict is None:
            ts = f"({timestamp}) " if timestamp is not None else ""
            log.warning(
                f"DCSources and fluxlines_dict must be specified if user "
                f"wants to load flux bias. DCSources NOT reloaded. You can "
                f"retry loading the settings {ts}by passing the DCSources and "
                f"fluxlines_dict.")
            return

        for DCSource in DCSources:
            DCSource_params = gen.load_settings(DCSource, timestamp=timestamp,
                                                update=False)
            set_fluxline_dict = {
                fluxlines_dict[qb.name].name[5:]:  # strip "volt_"
                    eval(DCSource_params[fluxlines_dict[qb.name].name])
                for qb in qubits if qb in qbs}
            print(f"Setting flux line voltages to {set_fluxline_dict}")
            if 'Virtual' in DCSource.__class__.__name__:
                for k, v in set_fluxline_dict.items():
                    DCSource.set(f'volt_{k}', v)
            else:
                DCSource.set_smooth(set_fluxline_dict)
{'fraction_non_alphanumeric': 0.0750979987621209, 'fraction_numerical': 0.0006189395502372602, 'mean_word_length': 1.838407494145199, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869803', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1313, 'n_words': 373}