Utilities package

Display module

Parsers module

Qutip utilitiess module

Useful functions to get basis vectors and matrices of the right size.

c3.utils.qt_utils.T1_sequence(length, target)[source]

Generate a gate sequence to measure relaxation time in a two-qubit chip.

Parameters
  • length (int) – Number of Identity gates.

  • target (str) – Which qubit is measured. Options: “left” or “right”

Returns

Relaxation sequence.

Return type

list

c3.utils.qt_utils.basis(lvls: int, pop_lvl: int)[source]

Construct a basis state vector.

Parameters
  • lvls (int) – Dimension of the state.

  • pop_lvl (int) – The populated entry.

Returns

A normalized state vector with one populated entry.

Return type

np.array

c3.utils.qt_utils.hilbert_space_dekron(op, indx, dims)[source]

Partial trace of an operator to return equivalent subspace operator. Inverse of hilbert_space_kron.

NOT IMPLEMENTED

c3.utils.qt_utils.hilbert_space_kron(op, indx, dims)[source]

Extend an operator op to the full product hilbert space given by dimensions in dims.

Parameters
  • op (np.array) – Operator to be extended.

  • indx (int) – Position of which subspace to extend.

  • dims (list) – New dimensions of the subspace.

Returns

Extended operator.

Return type

np.array

c3.utils.qt_utils.inverseC(sequence)[source]

Find the clifford to end a sequence s.t. it returns identity.

c3.utils.qt_utils.np_kron_n(mat_list)[source]

Apply Kronecker product to a list of matrices.

c3.utils.qt_utils.pad_matrix(matrix, dim, padding)[source]

Fills matrix dimensions with zeros or identity.

c3.utils.qt_utils.pauli_basis(dims=[2])[source]

Qutip implementation of the Pauli basis.

Parameters

dims (list) – List of dimensions of each subspace.

Returns

A square matrix containing the Pauli basis of the product space

Return type

np.array

c3.utils.qt_utils.perfect_cliffords(lvls: int, proj: str = 'fulluni', num_gates: int = 1)[source]

Returns a list of ideal matrix representation of Clifford gates.

c3.utils.qt_utils.perfect_gate(gates_str: str, index=[0, 1], dims=[2, 2], proj: str = 'wzeros')[source]

Construct an ideal single or two-qubit gate.

Parameters
  • gates_str (str) – Identifier of the gate, i.e. “X90p”.

  • index (list) – Indeces of the subspace(s) the gate acts on

  • dims (list) – Dimension of the subspace(s)

  • proj (str) – Option for projection in the case of more than two-level qubits.

Returns

Ideal representation of the gate.

Return type

np.array

c3.utils.qt_utils.perfect_parametric_gate(paulis_str, ang, dims)[source]

Construct an ideal parametric gate.

Parameters
  • paulis_str (str) –

    Names for the Pauli matrices that identify the rotation axis. Example:
    • ”X” for a single-qubit rotation about the X axis

    • ”Z:X” for an entangling rotation about Z on the first and X on the second qubit

  • ang (float) – Angle of the rotation

  • dims (list) – Dimensions of the subspaces.

Returns

Ideal gate.

Return type

np.array

c3.utils.qt_utils.ramsey_echo_sequence(length, target)[source]

Generate a gate sequence to measure dephasing time in a two-qubit chip including a flip in the middle. This echo reduce effects detrimental to the dephasing measurement.

Parameters
  • length (int) – Number of Identity gates. Should be even.

  • target (str) – Which qubit is measured. Options: “left” or “right”

Returns

Dephasing sequence.

Return type

list

c3.utils.qt_utils.ramsey_sequence(length, target)[source]

Generate a gate sequence to measure dephasing time in a two-qubit chip.

Parameters
  • length (int) – Number of Identity gates.

  • target (str) – Which qubit is measured. Options: “left” or “right”

Returns

Dephasing sequence.

Return type

list

c3.utils.qt_utils.rotation(phase, xyz)[source]

General Rotation using Euler’s formula.

Parameters
  • phase (np.float) – Rotation angle.

  • xyz (np.array) – Normal vector of the rotation axis.

Returns

Unitary matrix

Return type

np.array

c3.utils.qt_utils.single_length_RB(RB_number, RB_length, padding='')[source]

Given a length and number of repetitions it compiles Randomized Benchmarking sequences.

Parameters
  • RB_number (int) – The number of sequences to construct.

  • RB_length (int) – The number of Cliffords in each individual sequence.

  • padding (str) – Option of “left” or “right” in a two-qubit chip.

Returns

List of RB sequences.

Return type

list

c3.utils.qt_utils.two_qubit_gate_tomography(gate)[source]

Sequences to generate tomography for evaluating a two qubit gate.

c3.utils.qt_utils.xy_basis(lvls: int, vect: str)[source]

Construct basis states on the X, Y and Z axis.

Parameters
  • lvls (int) – Dimensions of the Hilbert space.

  • vect (str) –

    Identifier of the state. Options:

    ’zp’, ‘zm’, ‘xp’, ‘xm’, ‘yp’, ‘ym’

Returns

A state on one of the axis of the Bloch sphere.

Return type

np.array

Tensorflow utilitiess module

Various utility functions to speed up tensorflow coding.

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

Identity of the same size as A.

c3.utils.tf_utils.evaluate_sequences(U_dict: dict, sequences: list)[source]

Compute the total propagator of a sequence of gates.

Parameters
  • U_dict (dict) – Dictionary of unitary representation of gates.

  • sequences (list) –

    List of keys from U_dict specifying a gate sequence. The sequence is multiplied from the left, i.e.

    sequence = [U0, U1, U2, …]

    is applied as

    … U2 * U1 * U0

Returns

Propagator of the sequence.

Return type

tf.tensor

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.super_to_choi(A)[source]

Convert a super operator to choi representation.

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

Rewritten so that is has a gradient.

c3.utils.tf_utils.tf_abs_squared(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_average_fidelity(A, B, lvls=None)[source]

A very useful but badly named fidelity measure.

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.tf_dU_of_t(h0, hks, cflds_t, dt)[source]

Compute H(t) = H_0 + sum_k c_k H_k and matrix exponential exp(i H(t) dt).

Parameters
  • h0 (tf.tensor) – Drift Hamiltonian.

  • hks (list of tf.tensor) – List of control Hamiltonians.

  • cflds_t (array of tf.float) – Vector of control field values at time t.

  • dt (float) – Length of one time slice.

Returns

dU = exp(-i H(t) dt)

Return type

tf.tensor

c3.utils.tf_utils.tf_dU_of_t_lind(h0, hks, col_ops, cflds_t, dt)[source]

Compute the Lindbladian and it’s matrix exponential exp(L(t) dt).

Parameters
  • h0 (tf.tensor) – Drift Hamiltonian.

  • hks (list of tf.tensor) – List of control Hamiltonians.

  • col_ops (list of tf.tensor) – List of collapse operators.

  • cflds_t (array of tf.float) – Vector of control field values at time t.

  • dt (float) – Length of one time slice.

Returns

dU = exp(L(t) dt)

Return type

tf.tensor

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.tf_dm_to_vec(dm)[source]

Convert a density matrix into a density vector.

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_expm(A, terms)[source]

Matrix exponential by the series method.

Parameters
  • A (tf.tensor) – Matrix to be exponentiated.

  • terms (int) – Number of terms in the series.

Returns

expm(A)

Return type

tf.tensor

c3.utils.tf_utils.tf_expm_dynamic(A, acc=0.0001)[source]

Matrix exponential by the series method with specified accuracy.

Parameters
  • A (tf.tensor) – Matrix to be exponentiated.

  • acc (float) – Accuracy. Stop when the maximum matrix entry reaches

Returns

expm(A)

Return type

tf.tensor

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

Overlap of two state vectors.

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

Kronecker product of 2 matrices.

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

Set a limit for the GPU memory.

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_log10(x)[source]

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

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

Display the information about different log levels in tensorflow.

c3.utils.tf_utils.tf_matmul_left(dUs)[source]

Multiplies a list of matrices from the left.

c3.utils.tf_utils.tf_matmul_n(tensor_list)[source]

Multiply a list of tensors as binary tree.

EXPERIMENTAL

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

Multiplies a list of matrices from the right.

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_project_to_comp(A, dims, to_super=False)[source]

Project an operator onto the computational subspace.

c3.utils.tf_utils.tf_propagation(h0, hks, cflds, dt)[source]

Calculate the unitary time evolution of a system controlled by time-dependent fields.

Parameters
  • h0 (tf.tensor) – Drift Hamiltonian.

  • hks (list of tf.tensor) – List of control Hamiltonians.

  • cflds (list) – List of control fields, one per control Hamiltonian.

  • dt (float) – Length of one time slice.

Returns

List of incremental propagators dU.

Return type

list

c3.utils.tf_utils.tf_propagation_lind(h0, hks, col_ops, cflds, dt, history=False)[source]

Calculate the time evolution of an open system controlled by time-dependent fields.

Parameters
  • h0 (tf.tensor) – Drift Hamiltonian.

  • hks (list of tf.tensor) – List of control Hamiltonians.

  • col_ops (list of tf.tensor) – List of collapse operators.

  • cflds (list) – List of control fields, one per control Hamiltonian.

  • dt (float) – Length of one time slice.

Returns

List of incremental propagators dU.

Return type

list

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

Superoperator on the right of matrix A.

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

Superoperator on the left 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_super(A)[source]

Superoperator from both sides of matrix A.

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

Return average fidelity of a process.

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_superoper_unitary_overlap(A, B, lvls=None)[source]
c3.utils.tf_utils.tf_unitary_overlap(A, B, lvls=None)[source]

Unitary overlap between two matrices.

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

Convert a density vector to a density matrix.

Miscelaneous utilities module

Miscellaneous, general utilities.

c3.utils.utils.ask_yn()[source]

Ask for y/n user decision in the command line.

c3.utils.utils.eng_num(val)[source]

Convert a number to engineering notation by returning number and prefix.

c3.utils.utils.log_setup(data_path, run_name=None)[source]
Make sure the file path to save data exists. Create an appropriately named folder with date and time.

Also creates a symlink “recent” to the folder.

Parameters
  • data_path (str) – File path of where to store any data.

  • run_name (str) – User specified name for the run.

Returns

The file path to store new data.

Return type

str

c3.utils.utils.num3str(val, use_prefix=True)[source]

Convert a number to a human readable string in engineering notation.

Module contents