qubiter.OneQubitGate module¶
-
class
qubiter.OneQubitGate.
OneQubitGate
[source]¶ Bases:
object
This class has no attributes or constructor. It is simply a collection of static methods, all of which return a complex 2 by 2 matrix (numpy array or array from some other tensor library). In cases where the entries of the matrix are all real, an is_quantum bool option is given to choose between a float or complex array.
All gates have a tensor library lib option. lib equals ‘np’ for numpy, ‘tf’ for tensorflow
-
static
P_0
(is_quantum=True, lib='np')[source]¶ Returns projection operator
P_0 = |0><0| = nbar
, where|0> = [ 1, 0]^T
and|1> = [0, 1]^T
, T = transposeParameters: - is_quantum (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
P_0_phase_fac
(ang_rads, lib='np')[source]¶ Returns
exp(1j*ang_rads*P_0) = [[x, 0],[0, 1]] with x = exp(1j*ang_rads)
Parameters: - ang_rads (float) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
P_1
(is_quantum=True, lib='np')[source]¶ Returns projection operator
P_1 = |1><1| = n
, where|0> = [1, 0]^T
and|1> = [0, 1]^T
, T = transposeParameters: - is_quantum (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
P_1_phase_fac
(ang_rads, lib='np')[source]¶ Returns
exp(1j*ang_rads*P_1) = [[1, 0],[0, x]] with x = exp(1j*ang_rads)
Parameters: - ang_rads (float) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
const_dict
(x)[source]¶ Returns dictionary with all values equal to x. Dict is destined to fill a future 2-dim matrix.
Parameters: x – Returns: Return type: dict
-
static
get_fun
(lib, fun_name, lib_to_fun_name=None)[source]¶ If lib is ‘np’, this method returns eval(lib + ‘.’ + fun_name). Else, if lib is not ‘np’ then: if lib_to_fun_name is None, it returns eval(lib + ‘.’ + fun_name), but if lib_to_fun_name is not None, it returns eval(lib + ‘.’ + lib_to_fun_name[lib]). It aborts if lib_to_fun_name[ lib] doesn’t exist.
Parameters: - lib (str) – tensor library, either ‘np’ for numpy or ‘tp’ for tensorflow
- fun_name (str) – function name
- lib_to_fun_name (dict[str, str]) – dictionary mapping lib to fun_name. For example {‘tf’: ‘cos’}
Returns: Return type: function
-
static
get_mat
(lib, mat_dict, dtype=None)[source]¶ Internal function that creates a tensor of type lib, based on a dict mat_dict.
Parameters: - lib (str) –
- mat_dict (dict) –
- dtype (dtype | None) –
Returns: Return type: np.ndarray
-
static
had2
(is_quantum=True, lib='np')[source]¶ Returns 2 dimensional Hadamard matrix (sigma_x + sigma_z)/sqrt(2).
Parameters: - is_quantum (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
mat_S
(herm=False, lib='np')[source]¶ Returns
[[1, 0],[0, x*sign]] where x=exp(j*pi/2)=j
where sign = 1 if herm=False and sign = -1 if herm=True.
Parameters: - herm (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
mat_Sdag
(lib='np')[source]¶ returns
S^\dag
.Parameters: lib (str) – Returns: Return type: np.ndarray
-
static
mat_T
(herm=False, lib='np')[source]¶ Returns
[[1, 0],[0, exp(j*pi/4*sign)]]
where sign = 1 if herm=False and sign = -1 if herm=True.
Parameters: - herm (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
mat_Tdag
(lib='np')[source]¶ returns
T^\dag
.Parameters: lib (str) – Returns: Return type: np.ndarray
-
static
phase_fac
(ang_rads, lib='np')[source]¶ Returns
exp(1j*ang_rads*I_2) = [[x, 0],[0, x]] with x = exp(1j*ang_rads)
Parameters: - ang_rads (float) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
rot
(rad_ang_x, rad_ang_y, rad_ang_z, lib='np')[source]¶ Returns
exp(1j*(rad_ang_x*sig_x + rad_ang_y*sig_y + rad_ang_z*sig_z))
where rad_ang_x is an angle in radians and sig_x is the x Pauli matrix, etc.
Parameters: - rad_ang_x (float) –
- rad_ang_y (float) –
- rad_ang_z (float) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
rot_ax
(rad_ang, axis, lib='np')[source]¶ Returns
exp(1j*rad_ang*sig_n)
where n = x if axis = 1, n = y if axis = 2 and n = z if axis = 3
Parameters: - rad_ang (float) –
- axis (int) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
sigx
(is_quantum=True, lib='np')[source]¶ Returns sigma_x Pauli matrix.
Parameters: - is_quantum (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
sigy
(lib='np')[source]¶ Returns sigma_y Pauli matrix.
Parameters: lib (str) – Returns: Return type: np.ndarray
-
static
sigz
(is_quantum=True, lib='np')[source]¶ Returns sigma_z Pauli matrix.
Parameters: - is_quantum (bool) –
- lib (str) –
Returns: Return type: np.ndarray
-
static
u2
(rads0, rads1, rads2, rads3, lib='np')[source]¶ Returns arbitrary 2-dim unitary matrix (U(2) group) parametrized as follows:
exp(1j*(rads0 + rads1*sig_x + rads2*sig_y + rads3*sig_z))
where rads1 is an angle in radians and sig_x is the x Pauli matrix, etc.
Parameters: - rads0 (float) –
- rads1 (float) –
- rads2 (float) –
- rads3 (float) –
- lib (str) –
Returns: Return type: np.ndarray
-
static