qcodes/dataset/database_fix_functions.py
def fix_version_4a_run_description_bug(conn: ConnectionPlus) -> Dict[str, int]:
    """
    Fix function to fix a bug where the RunDescriber accidentally wrote itself
    to string using the (new) InterDependencies_ object instead of the (old)
    InterDependencies object. After the first call, this function should be
    idempotent.


    Args:
        conn: the connection to the database

    Returns:
        A dict with the fix results ('runs_inspected', 'runs_fixed')
    """

    user_version = get_user_version(conn)

    if not user_version == 4:
        raise RuntimeError('Database of wrong version. Will not apply fix. '
                           'Expected version 4, found version {user_version}')

    no_of_runs_query = "SELECT max(run_id) FROM runs"
    no_of_runs = one(atomic_transaction(conn, no_of_runs_query), 'max(run_id)')
    no_of_runs = no_of_runs or 0

    with atomic(conn) as conn:

        pbar = tqdm(range(1, no_of_runs+1))
        pbar.set_description("Fixing database")

        # collect some metrics
        runs_inspected = 0
        runs_fixed = 0

        old_style_keys = ['paramspecs']
        new_style_keys = ['parameters', 'dependencies', 'inferences',
                          'standalones']

        for run_id in pbar:

            desc_str = get_run_description(conn, run_id)
            desc_ser = json.loads(desc_str)
            idps_ser = desc_ser['interdependencies']

            if list(idps_ser.keys()) == old_style_keys:
                pass
            elif list(idps_ser.keys()) == new_style_keys:
                old_desc_ser = \
                    _convert_run_describer_v1_like_dict_to_v0_like_dict(
                        desc_ser)
                json_str = json.dumps(old_desc_ser)
                _update_run_description(conn, run_id, json_str)
                runs_fixed += 1
            else:
                raise RuntimeError(f'Invalid runs_description for run_id: '
                                   f'{run_id}')

            runs_inspected += 1

    return {'runs_inspected': runs_inspected, 'runs_fixed': runs_fixed}

    Fix function to fix a bug where the RunDescriber accidentally wrote itself
    to string using the (new) InterDependencies_ object instead of the (old)
    InterDependencies object. After the first call, this function should be
    idempotent.


    Args:
        conn: the connection to the database

    Returns:
        A dict with the fix results ('runs_inspected', 'runs_fixed')
    
Fix function to fix a bug where the RunDescriber accidentally wrote itself
to string using the (new) InterDependencies_ object instead of the (old)
InterDependencies object. After the first call, this function should be
idempotent.
Fix function to fix a bug where the RunDescriber accidentally wrote itself to string using the ( new ) InterDependencies_ object instead of the ( old ) InterDependencies object . After the first call this function should be idempotent .
def fix_version_4a_run_description_bug(conn: ConnectionPlus) -> Dict[str, int]:
    user_version = get_user_version(conn)
    if not user_version == 4:
        raise RuntimeError('Database of wrong version. Will not apply fix. '
                           'Expected version 4, found version {user_version}')
    no_of_runs_query = "SELECT max(run_id) FROM runs"
    no_of_runs = one(atomic_transaction(conn, no_of_runs_query), 'max(run_id)')
    no_of_runs = no_of_runs or 0
    with atomic(conn) as conn:
        pbar = tqdm(range(1, no_of_runs+1))
        pbar.set_description("Fixing database")
        runs_inspected = 0
        runs_fixed = 0
        old_style_keys = ['paramspecs']
        new_style_keys = ['parameters', 'dependencies', 'inferences',
                          'standalones']
        for run_id in pbar:
            desc_str = get_run_description(conn, run_id)
            desc_ser = json.loads(desc_str)
            idps_ser = desc_ser['interdependencies']
            if list(idps_ser.keys()) == old_style_keys:
                pass
            elif list(idps_ser.keys()) == new_style_keys:
                old_desc_ser = \
                    _convert_run_describer_v1_like_dict_to_v0_like_dict(
                        desc_ser)
                json_str = json.dumps(old_desc_ser)
                _update_run_description(conn, run_id, json_str)
                runs_fixed += 1
            else:
                raise RuntimeError(f'Invalid runs_description for run_id: '
                                   f'{run_id}')
            runs_inspected += 1
    return {'runs_inspected': runs_inspected, 'runs_fixed': runs_fixed}
def fix_version_4a_run_description_bug ( conn : ConnectionPlus ) -> Dict [ str , int ] : user_version = get_user_version ( conn ) if not user_version == 4 : raise RuntimeError ( 'Database of wrong version. Will not apply fix. ' 'Expected version 4, found version {user_version}' ) no_of_runs_query = "SELECT max(run_id) FROM runs" no_of_runs = one ( atomic_transaction ( conn , no_of_runs_query ) , 'max(run_id)' ) no_of_runs = no_of_runs or 0 with atomic ( conn ) as conn : pbar = tqdm ( range ( 1 , no_of_runs + 1 ) ) pbar . set_description ( "Fixing database" ) runs_inspected = 0 runs_fixed = 0 old_style_keys = [ 'paramspecs' ] new_style_keys = [ 'parameters' , 'dependencies' , 'inferences' , 'standalones' ] for run_id in pbar : desc_str = get_run_description ( conn , run_id ) desc_ser = json . loads ( desc_str ) idps_ser = desc_ser [ 'interdependencies' ] if list ( idps_ser . keys ( ) ) == old_style_keys : pass elif list ( idps_ser . keys ( ) ) == new_style_keys : old_desc_ser = _convert_run_describer_v1_like_dict_to_v0_like_dict ( desc_ser ) json_str = json . dumps ( old_desc_ser ) _update_run_description ( conn , run_id , json_str ) runs_fixed += 1 else : raise RuntimeError ( f'Invalid runs_description for run_id: ' f'{run_id}' ) runs_inspected += 1 return { 'runs_inspected' : runs_inspected , 'runs_fixed' : runs_fixed }
Fix function to fix a bug where the RunDescriber accidentally wrote itself
to string using the (new) InterDependencies_ object instead of the (old)
InterDependencies object.
Fix function to fix a bug where the RunDescriber accidentally wrote itself to string using the ( new ) InterDependencies_ object instead of the ( old ) InterDependencies object .
"""
    Fix function to fix a bug where the RunDescriber accidentally wrote itself
    to string using the (new) InterDependencies_ object instead of the (old)
    InterDependencies object. After the first call, this function should be
    idempotent.


    Args:
        conn: the connection to the database

    Returns:
        A dict with the fix results ('runs_inspected', 'runs_fixed')
    """ # collect some metrics
A dict with the fix results ('runs_inspected', 'runs_fixed')
A dict with the fix results ( ' runs_inspected ' ' runs_fixed ' )
conn
ConnectionPlus
the connection to the database
the connection to the database