Project save/load

As we explore data, we often make rational changes to parameters by overriding the initial values of either input or function quibs. These overriding assignments can be saved to external files and re-loaded when the session is initiated. Importantly, overriding assignments can be saved in simple text human readable/writable files, providing a transparent record of user defined parameters and changes. The linkage between a quib and its overriding file is bidirectional - changes to the quib overriding assignments can be saved to the file, and changes to the file can be loaded to update the quib.

File names and locations

By default, quibs save their assignment file to the Project’s directory, which can be get/set using the functions get_project_directory() and set_project_directory().

Alternatively, each quib can set its own path, either relative to the Project directory, or as an absolute path (see save_directory).

The name of the file of each quib is defined by its assigned_name (only quibs with defined assigned_name can save to a file).

The ultimate file path for each quib is given by the file_path property.

Assignment file format

Assignments can be saved as a text file or binary file ('txt', or 'bin'). The file format can be set globally for all quibs using the Project’s save_format, or individually for each quib using the Quib’s save_format.

Simple example of assignment saving to file

As a simple example for saving quib assignment to file, conider the following code:

# Quibbler import:
import pyquibbler as qb
from pyquibbler import iquib
qb.initialize_quibbler()

# Other imports:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib tk
# set the project path to the current directory
import os
os.system('mkdir my_data')
qb.set_project_directory('my_data')
# By default, quibs are saved to text file:
qb.get_project().save_format
<SaveFormat.TXT: 'txt'>
# Define an iquib and an fquib:
xy = iquib([10.5, 17.0])
# Make an assignment
xy[1] = 18.
xy.get_value()
[10.5, 18.0]
# Save all assignments:
qb.save_quibs()
os.system('ls my_data');
xy.txt
os.system('cat my_data/xy.txt');
quib[1] = 18.0
xy[1] = 20.
xy.get_value()
[10.5, 20.0]
qb.load_quibs()
xy
Data has changed.
Overwrite assignment?
1 :  Overwrite
2 :  Skip
1
xy.get_value()
[10.5, 18.0]