iss_opt

errors

exception qmetro.iss_opt.errors.MaxIterExceededError(max_iter, qfi, qfis, *args)[source]

Bases: Exception

Exception raised when the maximal number of iterations is exceeded.

Parameters:
  • max_iter (int) – Maximal iterations allowed.

  • qfi (float) – Quantum Fisher Information value at the moment of raising the error.

  • qfis (list[float]) – List of Quantum Fisher Information values from all previous iterations.

  • args (object)

Return type:

None

exception qmetro.iss_opt.errors.NonHermitianError(name, nonhermiticity, *_)[source]

Bases: Exception

Exception raised when the optimized tensor is non-hermitian.

Parameters:
  • name (str) – Name of the tensor being optimized.

  • nonhermiticity (float) – Measure of non-hermiticity of the optimized tensor. See enhance_hermiticity.

Return type:

None

exception qmetro.iss_opt.errors.NormMatZeroEigenval(eigval, *_)[source]

Bases: Exception

Exception raised when a near-zero eigenvalue of the norm matrix is encountered during the MPS optimization [17].

Parameters:

eigval (float) – The near-zero eigenvalue.

Return type:

None

exception qmetro.iss_opt.errors.SingleIterError(cause, iteration, qfi, qfis, *_)[source]

Bases: Exception

Exception raised when an iteration of the ISS algorithm fails.

Parameters:
  • cause (Exception) – Cause of the error.

  • iteration (int) – Iteration number at which the error occurred.

  • qfi (float) – Quantum Fisher Information value at the moment of raising the error.

  • qfis (list[float]) – List of Quantum Fisher Information values from all previous iterations.

Return type:

None

exception qmetro.iss_opt.errors.SolverError(name, cause, m0, m1, *_)[source]

Bases: Exception

Exception raised when the solver for optimizing a tensor fails.

Parameters:
  • name (str) – Name of the tensor being optimized.

  • cause (Exception | str) – Exception or message indicating the cause of the error.

  • m0 (ConstTensor) – Term of the pre-QFI linear in pre-SLD.

  • m1 (ConstTensor) – Term of the pre-QFI quadratic in pre-SLD.

  • _ (object)

Return type:

None

iss_config

class qmetro.iss_opt.iss_config.IssConfig(name, max_error_iterations, max_iterations, min_iterations, eps, init_tn, print_messages, var_iterations, sld_iterations, art_noise_spaces, art_noise_params, contraction_order, adaptive_art_noise)[source]

Configuration parameters for the ISS optimization algorithm.

Parameters:
  • name (str | None, optional) – Name of the returned network. If None then the name will be tn.name + ‘ optimized’, by default None.

  • max_error_iterations (int, optional) – Maximal number of times the function will restart computation after an error occurence, by default 10.

  • max_iterations (int, optional) – Maximal number of algorithm iterations, by default 500.

  • min_iterations (int, optional) – Minimal number of algorithm iterations, by default 10.

  • eps (float, optional) – The algorithm stops when the QFI in 5 consecutive iterations changes by less than eps, by default 1e-4.

  • init_tn (QNetwork | None, optional) – Network from which initial values of variables will be taken. If None then initial values will be random, by default None

  • print_messages (bool | str, optional) – Wheter to print messages about progress it made. Possible options: - True: all messages will be printed, - False: no messages will be printed, - ‘partial’: print only iteration summary. By default False.

  • var_iterations (int, optional) – Number of iterations done solely over non measurement variables (CPTP, MPS and combs) before proceeding to the measurement (pre-SLD) variables, by default 1.

  • sld_iterations (int, optional) – Number of iterations done solely over measurement (pre-SLD) variables before proceeding to other variables, by default 1.

  • art_noise_spaces (list[list[Hashable]] | None, optional) – Spaces on which the artificial noise will act. For a list: [[s00, s01, …], [s10, s11, …], …] noise will be applied to the whole list of spaces [s00, s01, …] combined. If set to None then only spaces of ParamTensor elements will be noisy (separately), by default None.

  • art_noise_params (tuple[float, float], optional) –

    For a tupple (a, l) noise will take a form of:

    rho -> p * rho + (1 - p) * Id,

    where p = 1 - a * exp(-l * i), i is the iteration number and Id is theidentity matrix, by default (0.5, 0.1). See also the documentation.

  • contraction_order (list[str] | None, optional) – Names of tensors in the required order of contraction and therfore also the order of optimization. If None then the program will use BFS starting from the variable with smallest dimension and without input spaces, by default None.

  • adaptive_art_noise (bool, optional) – If True then the program will track the increase of QFI coming from variable optimization and from the artificial noise decay. If the latter is bigger the artificial noise decay parameter, l, will be doubled increasing the decay speed. By default True.

Attributes:
print_full
print_partial

Methods

check(tn)

Check correctness of the parameters of the ISS algorithm.

check_art_noise_params

check_contraction_order

check_cptp_vars

check(tn)[source]

Check correctness of the parameters of the ISS algorithm.

Parameters:

tn (TensorNetwork) – Tensor network to be optimized.

Raises:

ValueError – If the parameters are not correct.

iss_opt function

qmetro.iss_opt.main.iss_opt(tn, name=None, max_error_iterations=10, max_iterations=500, min_iterations=10, eps=0.0001, init_tn=None, print_messages=False, var_iterations=1, sld_iterations=1, art_noise_spaces=None, art_noise_params=(0.5, 0.1), contraction_order=None, adaptive_art_noise=True)[source]

Computes the quantum Fisher information (QFI) for a strategy provided in the form of a tensor network using the iterative see-saw (ISS) algorithm [17, 22, 27].

Function takes as an arguemnt an object of TensorNetwork class then maximizes its QFI optimizing over nodes which are variable tensors (members of VarTensor class).

To make the algorithm more stable it adds an artificial depolarizing noise [22] whose strength decays exponentially with each iteration.

Parameters:
  • tn (TensorNetwork) – Network that will be optimized.

  • name (str | None, optional) – Name of the returned network. If None then the name will be tn.name + ‘ optimized’, by default None.

  • max_error_iterations (int, optional) – Maximal number of times the function will restart computation after an error occurence, by default 10.

  • max_iterations (int, optional) – Maximal number of algorithm iterations, by default 500.

  • min_iterations (int, optional) – Minimal number of algorithm iterations, by default 10.

  • eps (float, optional) – The algorithm stops when the QFI in 5 consecutive iterations changes relatively by less than eps, by default 1e-4.

  • init_tn (QNetwork | None, optional) – Network from which initial values of variables will be taken. If None then initial values will be random, by default None

  • print_messages (bool | str, optional) – Wheter to print messages about progress it made. Possible options: - True: all messages will be printed, - False: no messages will be printed, - ‘partial’: print only iteration summary. By default False.

  • var_iterations (int, optional) – Number of iterations done solely over non measurement variables (CPTP, MPS and combs) before proceeding to the measurement (pre-SLD) variables, by default 1.

  • sld_iterations (int, optional) – Number of iterations done solely over measurement (pre-SLD) variables before proceeding to other variables, by default 1.

  • art_noise_spaces (list[list[Hashable]] | None, optional) – Spaces on which the artificial noise will act. For a list: [[s00, s01, …], [s10, s11, …], …] noise will be applied to the whole list of spaces [s00, s01, …] combined. If set to None then only spaces of ParamTensor elements will be noisy (separately), by default None.

  • art_noise_params (tuple[float, float], optional) –

    For a tupple (a, l) noise will take a form of:

    rho -> p * rho + (1 - p) * Id,

    where p = 1 - a * exp(-l * i), i is the iteration number and Id is theidentity matrix, by default (0.5, 0.1). See also the documentation.

  • contraction_order (list[str] | None, optional) – Names of tensors in the required order of contraction and therfore also the order of optimization. If None then the program will use BFS starting from the variable with smallest dimension and without input spaces, by default None.

  • adaptive_art_noise (bool, optional) – If True then the program will track the increase of QFI coming from variable optimization and from the artificial noise decay. If the latter is bigger the artificial noise decay parameter, l, will be doubled increasing the decay speed. By default True.

Returns:

  • qfi (float) – Quantum Fisher information.

  • qfiss (list[list[float]]) – QFI by connected component by iteration number.

  • tn_opt (TensorNetwork) – Copy of tn with variables substituted with computed optimal values.

  • status (bool) – True if the algorithm converged, False otherwise.

Return type:

tuple[float, list[list[float]], TensorNetwork, bool]