Interface

Simulation results

class qmatchatea.utils.simulation_results.SimulationResults(observables=None)[source]

Class to store and retrieve the result of a qmatchatea simulation

property computational_time

Obtain the computational time of the simulation

Returns

float

computational time of the simulation

property date_time

Obtain the starting date and time of the simulation, in the format Year-month-day-Hour:Minute:Second

Returns

datetime: string

The date-time when the simulation started

property entanglement

Obtain the bond entanglement entropy measured along each bond of the MPS at the end of the simulation

Returns

entanglement: np.array or None

Bond entanglement entropy

property fidelity

Return the lower bound for the fidelity of the simulation, using the method described in If you are interested in the evolution of the fidelity through the simulation compute it yourself using np.cumprod(1-self.singular_values_cut).

Returns

float

fidelity of the final state

property initial_state

Returns the initial state of the simulation, as an MPS in row-major format or as a string if starting from the Vacuum state

Returns

initial_state: list or str

list of np.array tensors or Vacuum

load_state(tensor_backend=<qtealeaves.tensors.tensor_backend.TensorBackend object>)[source]

Loads the state located in tn_state_path, saving it in tn_state

Parameters

tensor_backendTensorBackend, optional

Tensor backend of the state if it is saved in a formatted format. Default to TensorBackend().

property measure_probabilities

Return the probability of measuring a given state, which is computed using a binary tree by eliminating all the branches with probability under a certain threshold.

Returns

measure_probabilities: Dict[Dict | None]

probability of measuring a certain state if it is greater than a threshold

property measures

Obtain the measures of the simulation as a dictionary. The keys are the measured states, the values the number of occurrencies

Returns

measures: dict

Measures of the simulation

property observables
Returns the expectation values of the observables as a dict with the format

observable_name : observable_expectation_value

Returns

observables: dict or None

Expectation values of the observables

classmethod read_pickle(filename)[source]

Load the results of a previous simulation

Parameters

path: str

PATH to the file from which we want to load the results

Returns

readme: str

The text contained in the readme file inside the folder

save_pickle(filename)[source]

Save class via pickle-module.

Parameters

filenamestr

path where to save the file

Details

The following attributes have a special treatment and are not present in the copied object.

  • initial state tensor network

  • final state tensor network

  • statevector

set_results(result_dict, singvals_cut)[source]

Set the results of a simulation

Parameters

result_dict: dict

Dictionary of the attribute to be set

singvals_cut: array-like

Array of singular values cut through the simulation

property singular_values_cut

Obtain the singular values cutted through the simulation, depending on the mode chosen. If ‘M’ for maximum (default), ‘C’ for cumulated.

Returns

np.ndarray[float]

Singular values cut during the simulation

property statevector

Obtain the statevector as a complex numpy array

Returns

statevector: np.array or None

The statevector of the simulation

property tn_state

Returns the tensor network class, either TTN or MPS

Returns

_AbstractTN

The tensor network class

property tn_state_path

Returns the tensor list in row-major format. The indexing of the single tensor is as follows:

1-o-3
 2|

Returns

mps: list

list of np.array tensors

Setting the backend

class qmatchatea.utils.backend.QCBackend(precision='A', device='cpu', ansatz='MPS', mpi_settings=None, tensor_module='numpy')[source]

Backend for the simulation. Contains all the informations about which executable you want to run.

Parameters

precision: str, optional

Precision of the simulation. Select a real precision ONLY if you use ONLY real gates. Available: - “A”: automatic. For the heuristic see self.resolve_precision. - “Z”: double precision complex; - “C”: single precision complex; - “D”: double precision real; - “S”: single precision real. Default to “A”.

device: str, optional

Device of the simulation. Available: - “A” : automatic. For the heuristic see self.resolve_device - “cpu”: use the cpu - “gpu”: use the gpu if it is available - “cpu+gpu”: use the device-mixed mode (if gpu is available) Default to “A”.

ansatzstr, optional

Whether to run the circuit with MPS or TTN tensor network ansatz. Default to “MPS”.

mpi_settingsMPISettings | None, optional

Settings for running the simulation multi-node. Default to None, i.e. no MPI.

tensor_modulestr, optional

Module used to perform the computations. Available: - “numpy” (Default, uses cupy for the GPU) - “torch”, uses pytorch; - “tensorflow” - “jax”. Default to “numpy”

property ansatz

ansatz property

property device

Device property

classmethod from_json(path)[source]

Initialize the class from a json file called “backend.json” in the folder path

property identifier

Identifier combining all properties.

property mpi_approach

mpi_approach property (inherited from mpi_settings)

property mpi_command

mpi_command property

property num_procs

Number of processes property

property precision

Precision property

resolve_device(bond_dimension, previous_device, exp_gpu=7)[source]

Resolve the device if it set on automatic.

Parameters

bond_dimensionint

Maximum bond dimension of the system

previous_devicestr

Device where the system is currently. This is used to ensure we do not keep exchanging data back and forth.

exp_gpuint, optional

Exponent of the bond dimension after which you switch to the gpu, i.e: - if chi >= 2**exp_gpu -> use gpu - if chi <= 2**(exp_gpu-1) -> use cpu Default to 7. (switch at 128)

Returns

str

Device where to move (or keep) the system

resolve_precision(min_fidelity, tol=1e-07)[source]

Resolve the precision of the simulation. Heuristic if self._precision=”A”.

Parameters

min_fidelity: float

Lower bound of the fidelity of the simulation at the moment

tol: float, optional

Tolerance after which you switch to single precision. Default to 1e-7

Returns

str

The selected precision

to_dict()[source]

Map the backend to a dictionary.

to_json(path)[source]

Write the class as a json on file as backend.json in the folder path

property where_barriers

This parameter is important only if you want to use MPI parallelization, where a barrier is equivalent to a canonization in the MPS simulation. Default to -1.

Preprocessing

Tensor compiler