Utilities package¶
Parsers module¶
Parsers to read in config files and construct the corresponding objects.
-
c3.utils.parsers.
create_c1_opt
(optimizer_config, exp)[source]¶ Create an object for C1 optimal control.
- Parameters
optimizer_config (str) – File path to a hjson file containing the C1 configuration.
lindblad (boolean) – Include lindbladian dynamics.
- Returns
Open loop optimizer object
- Return type
-
c3.utils.parsers.
create_c1_opt_hk
(optimizer_config, lindblad, RB_number, RB_length, shots, noise)[source]¶
-
c3.utils.parsers.
create_c2_opt
(optimizer_config, eval_func_path)[source]¶ Create a C2 Calibration object. Can be used to simulate the calibration process, if the eval_func_path contains a ‘’real’’ experiment.
- Parameters
optimizer_config (str) – File path to a hjson configuration file.
eval_func_path (str) – File path to a python script, containing the functions used perform an experiment.
- Returns
The C2 optimizer and, in the case of simulated calibration, the ‘’real’’ experiment object.
- Return type
Qutip utilities 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.
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: str, 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 utilities module¶
Various utility functions to speed up tensorflow coding.
-
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.
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_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_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_log_level_info
()[source]¶ Display the information about different log levels in tensorflow.
-
c3.utils.tf_utils.
tf_matmul_n
(tensor_list)[source]¶ Multiply a list of tensors as binary tree.
EXPERIMENTAL
-
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_superoper_average_fidelity
(A, B, lvls=None)[source]¶ A very useful but badly named fidelity measure.
-
c3.utils.tf_utils.
tf_unitary_overlap
(A: tensorflow.python.framework.ops.Tensor, B: tensorflow.python.framework.ops.Tensor, lvls: tensorflow.python.framework.ops.Tensor = None) → tensorflow.python.framework.ops.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
Miscellaneous utilities module¶
Miscellaneous, general utilities.
-
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