Data#

Data Objects#

Data objects are instances of the qclab.data.Data class and are used to store and manage the results of a simulation. They provide methods for collecting, processing, and saving data, as well as logging errors or warnings during a simulation.

In general, a data object has the following attributes:

  • data_dict: a dictionary that stores the results of the simulation. Each key in the dictionary corresponds to a specific quantity that was collected during the simulation, and the value is an array containing the values of that quantity averaged over the trajectories.

  • log: a string that stores the log of errors or warnings that occurred during the simulation.

Data objects provide several methods for managing and processing the data they contain. Some of the most important methods include:

  • add_data: adds data from an existing data object to the current one.

  • save: saves the data object to a file.

  • load: loads a data object from a file (this adds to any existing data).

These methods are documented here:

qclab.data.Data.add_data(self, new_data)#

Add data from new_data to the output dictionary self.data_dict.

Args

new_data: Data

A Data instance containing the new data to merge.

qclab.data.Data.save(self, filename, disable_h5py=False)#

Save the data to disk with file name filename.

If h5py is available the data is stored as an HDF5 archive; otherwise each variable is saved using numpy.savez.

Args

filenamestr

The file name to save the data to.

disable_h5pybool, default: qclab.utils.DISABLE_H5PY

If True, h5py is not used even if available.

qclab.data.Data.load(self, filename, disable_h5py=False)#

Load a Data object from filename.

Args

filenamestr

The file name to load the data from.

disable_h5pybool, default: qclab.utils.DISABLE_H5PY

If True, h5py is not used even if available.

Returns

DataData

The loaded Data object.

Example#

Here is a simple example of running a simulation and plotting from the data object returned by the driver:

import numpy as np
import matplotlib.pyplot as plt
from qclab import Simulation
from qclab.models import SpinBoson
from qclab.algorithms import MeanField
from qclab.dynamics import serial_driver

sim = Simulation()
sim.model = SpinBoson()
sim.algorithm = MeanField()
sim.initial_state.wf_db= np.array([1,0], dtype=complex)
data = serial_driver(sim)

t = data.data_dict['t']
plt.plot(t, np.real(np.einsum('tii->ti',data.data_dict['dm_db'])))
plt.title('Diabatic populations')
plt.show()