c3.utils.tf_utils

Various utility functions to speed up tensorflow coding.

Module Contents

c3.utils.tf_utils.tf_log_level_info()[source]

Display the information about different log levels in tensorflow.

c3.utils.tf_utils.get_tf_log_level()[source]

Display the current tensorflow log level of the system.

c3.utils.tf_utils.set_tf_log_level(lvl)[source]

Set tensorflows system log level.

REMARK: it seems like the ‘TF_CPP_MIN_LOG_LEVEL’ variable expects a string.

the input of this function seems to work with both string and/or integer, as casting string to string does nothing. feels hacked? but I guess it’s just python…

c3.utils.tf_utils.tf_list_avail_devices()[source]

List available devices.

Function for displaying all available devices for tf_setuptensorflow operations on the local machine.

TODO: Refine output of this function. But without further knowledge

about what information is needed, best practise is to output all information available.

c3.utils.tf_utils.tf_limit_gpu_memory(memory_limit)[source]

Set a limit for the GPU memory.

c3.utils.tf_utils.tf_measure_operator(M, rho)[source]

Expectation value of a quantum operator by tracing with a density matrix.

Parameters
  • M (tf.tensor) – A quantum operator.

  • rho (tf.tensor) – A density matrix.

Returns

Expectation value.

Return type

tf.tensor

c3.utils.tf_utils.tf_matmul_left(dUs: tensorflow.Tensor)[source]
Parameters

dUs – tf.Tensor Tensorlist of shape (N, n,m) with number N matrices of size nxm

Multiplies a list of matrices from the left.

c3.utils.tf_utils.tf_matmul_right(dUs)[source]
Parameters

dUs – tf.Tensor Tensorlist of shape (N, n,m) with number N matrices of size nxm

Multiplies a list of matrices from the right.

c3.utils.tf_utils.tf_matmul_n(tensor_list: tensorflow.Tensor, folding_stack: List[Callable]) tensorflow.Tensor[source]

Multipy a list of tensors using a precompiled stack of function to apply to each layer of a binary tree.

Parameters
  • tensor_list (List[tf.Tensor]) – Matrices to be multiplied.

  • folding_stack (List[Callable]) – List of functions to multiply each layer.

Returns

Reduced product of matrices.

Return type

tf.Tensor

c3.utils.tf_utils.tf_log10(x)[source]

Tensorflow had no logarithm with base 10. This is ours.

c3.utils.tf_utils.tf_abs_squared(x)[source]

Rewritten so that is has a gradient.

c3.utils.tf_utils.tf_abs(x)[source]

Rewritten so that is has a gradient.

c3.utils.tf_utils.tf_ave(x: list)[source]

Take average of a list of values in tensorflow.

c3.utils.tf_utils.tf_diff(l)[source]

Running difference of the input list l. Equivalent to np.diff, except it returns the same shape by adding a 0 in the last entry.

c3.utils.tf_utils.Id_like(A)[source]

Identity of the same size as A.

c3.utils.tf_utils.tf_kron(A, B)[source]

Kronecker product of 2 matrices. Can be applied with batch dimmensions.

c3.utils.tf_utils.tf_spre(A)[source]

Superoperator on the left of matrix A.

c3.utils.tf_utils.tf_spost(A)[source]

Superoperator on the right of matrix A.

c3.utils.tf_utils.tf_super(A)[source]

Superoperator from both sides of matrix A.

c3.utils.tf_utils.tf_state_to_dm(psi_ket)[source]

Make a state vector into a density matrix.

c3.utils.tf_utils.tf_dm_to_vec(dm)[source]

Convert a density matrix into a density vector.

c3.utils.tf_utils.tf_vec_to_dm(vec)[source]

Convert a density vector to a density matrix.

c3.utils.tf_utils.tf_dmdm_fid(rho, sigma)[source]

Trace fidelity between two density matrices.

c3.utils.tf_utils.tf_dmket_fid(rho, psi)[source]

Fidelity between a state vector and a density matrix.

c3.utils.tf_utils.tf_ketket_fid(psi1, psi2)[source]

Overlap of two state vectors.

c3.utils.tf_utils.tf_unitary_overlap(A: tensorflow.Tensor, B: tensorflow.Tensor, lvls: tensorflow.Tensor = None) tensorflow.Tensor[source]

Unitary overlap between two matrices.

Parameters
  • A (tf.Tensor) – Unitary A

  • B (tf.Tensor) – Unitary B

  • lvls (tf.Tensor, optional) – Levels, by default None

Returns

Overlap between the two unitaries

Return type

tf.Tensor

Raises
  • TypeError – For errors during cast

  • ValueError – For errors during matrix multiplicaton

c3.utils.tf_utils.tf_average_fidelity(A, B, lvls=None)[source]

A very useful but badly named fidelity measure.

c3.utils.tf_utils.tf_superoper_average_fidelity(A, B, lvls=None)[source]

A very useful but badly named fidelity measure.

c3.utils.tf_utils.tf_super_to_fid(err, lvls)[source]

Return average fidelity of a process.

c3.utils.tf_utils.tf_choi_to_chi(U, dims=None)[source]

Convert the choi representation of a process to chi representation.

c3.utils.tf_utils.super_to_choi(A)[source]

Convert a super operator to choi representation.

c3.utils.tf_utils.tf_project_to_comp(A, dims, index=None, to_super=False)[source]

Project an operator onto the computational subspace.

c3.utils.tf_utils.tf_convolve(sig: tensorflow.Tensor, resp: tensorflow.Tensor)[source]

Compute the convolution with a time response.

Parameters
  • sig (tf.Tensor) – Signal which will be convoluted, shape: [N]

  • resp (tf.Tensor) – Response function to be convoluted with signal, shape: [M]

Returns

convoluted signal of shape [N]

Return type

tf.Tensor

c3.utils.tf_utils.tf_convolve_legacy(sig: tensorflow.Tensor, resp: tensorflow.Tensor)[source]

Compute the convolution with a time response. LEGACY version. Ensures compatibility with the previous response implementation.

Parameters
  • sig (tf.Tensor) – Signal which will be convoluted, shape: [N]

  • resp (tf.Tensor) – Response function to be convoluted with signal, shape: [M]

Returns

convoluted signal of shape [N]

Return type

tf.Tensor