utils
The quotonic.utils module includes miscellaneous helper functions for a variety of other modules within quotonic.
genHaarUnitary(m)
¶
Generate an \(m\times m\) unitary sampled randomly from the Haar measure.
This function follows the procedure outlined in F. Mezzadri, “How to generate random matrices from classical compact groups”, arXiv:math-ph/0609050v2 (2007).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
int
|
dimension of the square \(m \times m\) unitary |
required |
Returns:
| Type | Description |
|---|---|
np_ndarray
|
A 2D array storing the Haar random \(m\times m\) unitary |
Source code in src/quotonic/utils.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
comp_to_secq(comp_state)
¶
Convert a computational basis state to its corresponding second-quantized Fock basis state in dual-rail encoding.
In dual-rail encoding, a qubit is defined by the location of a single photon in two consecutive optical modes. Mathematically, this can be written as \(\left|0\right\rangle_\mathrm{log} \equiv \left|10\right\rangle\) and \(\left|1\right\rangle_\mathrm{log} \equiv \left|01\right\rangle\). This function takes a computational basis state, iterates through each qubit, and inserts the corresponding representation in the second-quantized Fock basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_state
|
np_ndarray
|
\(n\)-length array, where \(n\) is the number of qubits, where each element specifies whether a qubit is 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
np_ndarray
|
Fock basis state that corresponds to the given computational basis state by dual-rail encoding, a \(2n\)-length |
np_ndarray
|
array |
Examples:
>>> comp_to_secq(np.array([0]))
array([1, 0])
>>> comp_to_secq(np.array([0, 1]))
array([1, 0, 0, 1])
Source code in src/quotonic/utils.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
secq_to_comp(fock_state)
¶
Convert a Fock basis state, that is dual-rail encoded, to its corresponding computational basis state.
In dual-rail encoding, a qubit is defined by the location of a single photon in two consecutive optical modes. Mathematically, this can be written as \(\left|0\right\rangle_\mathrm{log} \equiv \left|10\right\rangle\) and \(\left|1\right\rangle_\mathrm{log} \equiv \left|01\right\rangle\). This function takes a second-quantized Fock basis state, iterates through each qubit, and inserts the corresponding 0 or 1 from the computational basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fock_state
|
np_ndarray
|
\(2n\)-length array, where \(n\) is the number of qubits, where each consecutive pair of elements signifies whether a qubit is 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
np_ndarray
|
Computational basis state that corresponds to the given Fock basis state by dual-rail encoding, an \(n\)-length array |
Examples:
>>> secq_to_comp(np.array([1, 0]))
array([0])
>>> secq_to_comp(np.array([1, 0, 0, 1]))
array([0, 1])
Source code in src/quotonic/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
comp_indices_from_secq(fock_basis, ancillary_modes=None)
¶
Extract the indices of Fock basis states that correspond to computational basis states by dual-rail encoding.
This function iterates through each second-quantized Fock basis states, ignores the specified ancillary modes if provided (these are not involved with logical encoding), checks if the state corresponds to the dual-rail encoding, and stores the index of this state within the Fock basis if it is deemed logical. The list of indices is returned as an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fock_basis
|
np_ndarray
|
\(N\times 2n\) array, where \(n\) is the number of qubits, that catalogs all states in the \(N\)-dimensional second quantization Fock basis |
required |
ancillary_modes
|
np_ndarray | None
|
array that specifies which optical modes are ancillary and thus should not contribute to logical encoding |
None
|
Returns:
| Type | Description |
|---|---|
np_ndarray
|
\(2^n\)-length array whose elements are the indices of the second quantization Fock basis where dual-rail encoded computational basis states lie |
Examples:
>>> from quotonic.fock import build_secq_basis
>>> n = 2
>>> m = 4
>>> fock_basis = build_secq_basis(n, m)
>>> fock_basis
array([[2, 0, 0, 0],
[1, 1, 0, 0],
[1, 0, 1, 0],
[1, 0, 0, 1],
[0, 2, 0, 0],
[0, 1, 1, 0],
[0, 1, 0, 1],
[0, 0, 2, 0],
[0, 0, 1, 1],
[0, 0, 0, 2]])
>>> comp_indices_from_secq(fock_basis)
array([2, 3, 5, 6])
Source code in src/quotonic/utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
vectorial_factorial(x)
¶
Compute the factorial on the input vectorially.
Simply put, this function wraps jax.scipy.special.factorial with the jax.vmap decorator. It doesn't really
need its own documented function, but I thought the name vectorial_factorial sounded cool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | float
|
integer to compute the factorial of |
required |
Returns:
| Type | Description |
|---|---|
int | float
|
Factorial of the input |
Source code in src/quotonic/utils.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |