@@ -2094,286 +2094,6 @@ void applyMultiQubitPhaseShift(Qureg qureg, std::vector<int> targets, qreal angl
20942094
20952095
20962096
2097- /* *
2098- * @defgroup op_paulistrsum PauliStrSum gadgets
2099- * @brief Functions for apply Trotterised exponentials of weighted sums of Pauli tensors.
2100- * @{
2101- */
2102-
2103-
2104- #ifdef __cplusplus
2105- extern " C" {
2106- #endif
2107-
2108-
2109- /* * @notyettested
2110- *
2111- * Effects (an approximation to) the exponential of @p sum, weighted by @p angle, upon @p qureg,
2112- * via the symmetrized Trotter-Suzuki decomposition (<a href="https://arxiv.org/abs/math-ph/0506007">arXiv</a>).
2113- * Increasing @p reps (the number of Trotter repetitions) or @p order (an even, positive integer or one)
2114- * improves the accuracy of the approximation (reducing the "Trotter error" due to non-commuting
2115- * terms of @p sum), though increases the runtime linearly and exponentially respectively.
2116- *
2117- * @formulae
2118- *
2119- * Let @f$ \hat{H} = @f$ @p sum and @f$ \theta = @f$ @p angle. This function approximates the action of
2120- * @f[
2121- \exp \left(\iu \, \theta \, \hat{H} \right)
2122- * @f]
2123- * via a Trotter-Suzuki decomposition of the specified @p order and number of repetitions (@p reps).
2124- * Simulation is exact, regardless of @p order or @p reps, only when all terms in @p sum commute.
2125- *
2126- * @important
2127- * Note that @f$ \theta @f$ lacks the @f$ -\frac{1}{2} @f$ prefactor present in other functions like
2128- * applyPauliGadget().
2129- *
2130- * To be precise, let @f$ r = @f$ @p reps and assume @p sum is composed of
2131- * @f$ T @f$-many terms of the form
2132- * @f[
2133- \hat{H} = \sum\limits_j^T c_j \, \hat{\sigma}_j
2134- * @f]
2135- * where @f$ c_j @f$ is the coefficient of the @f$ j @f$-th PauliStr @f$ \hat{\sigma}_j @f$.
2136- *
2137- * - When @p order=1, this function performs first-order Trotterisation, whereby
2138- * @f[
2139- \exp(\iu \, \theta \, \hat{H} )
2140- \approx
2141- \prod\limits^{r}
2142- \prod\limits_{j=1}^{T}
2143- \exp \left( \iu \, \frac{\theta \, c_j}{r} \, \hat\sigma_j \right).
2144- * @f]
2145- * - When @p order=2, this function performs the lowest order "symmetrized" Suzuki decomposition, whereby
2146- * @f[
2147- \exp(\iu \, \theta \, \hat{H} )
2148- \approx
2149- \prod\limits^{r} \left[
2150- \prod\limits_{j=1}^{T} \exp \left( \iu \frac{\theta \, c_j}{2 \, r} \hat\sigma_j \right)
2151- \prod\limits_{j=T}^{1} \exp \left( \iu \frac{\theta \, c_j}{2 \, r} \hat\sigma_j \right)
2152- \right].
2153- * @f]
2154- * - Greater, even values of @p order (denoted by symbol @f$ n @f$) invoke higher-order symmetrized decompositions
2155- * @f$ S[\theta,n,r] @f$. Letting @f$ p = \left( 4 - 4^{1/(n-1)} \right)^{-1} @f$, these satisfy
2156- * @f{align*}
2157- S[\theta, n, 1] &=
2158- \left( \prod\limits^2 S[p \, \theta, n-2, 1] \right)
2159- S[ (1-4p)\,\theta, n-2, 1]
2160- \left( \prod\limits^2 S[p \, \theta, n-2, 1] \right),
2161- \\
2162- S[\theta, n, r] &=
2163- \prod\limits^{r} S\left[\frac{\theta}{r}, n, 1\right].
2164- * @f}
2165- *
2166- * > These formulations are taken from 'Finding Exponential Product Formulas
2167- * > of Higher Orders', Naomichi Hatano and Masuo Suzuki (2005) (<a href="https://arxiv.org/abs/math-ph/0506007">arXiv</a>).
2168- *
2169- * @equivalences
2170- *
2171- * - Time evolution of duration @f$ t @f$ under a time-independent Hamiltonian @p sum = @f$ \hat{H} @f$, as
2172- * per the unitary time evolution operator
2173- * @f[
2174- \hat{U}(t) = \exp(- \iu \, t \,\hat{H} \, / \, \hbar)
2175- * @f]
2176- * is approximated via @f$ \theta = - t / \hbar @f$.
2177- * ```
2178- qreal time = 3.14;
2179- qreal angle = - time / hbar;
2180- applyTrotterizedPauliStrSumGadget(qureg, sum, angle, order, reps);
2181- * ```
2182- * - This function is equivalent to applyNonUnitaryTrotterizedPauliStrSumGadget() when passing
2183- * a @p qcomp instance with a zero imaginary component as the @p angle parameter. This latter
2184- * function is useful for generalising dynamical simulation to imaginary-time evolution.
2185- *
2186- * @constraints
2187- * - Unitarity of the prescribed exponential(s) requires that @p sum is Hermitian, ergo containing
2188- * only real coefficients. Validation will check that @p sum is approximately Hermitian, permitting
2189- * coefficients with imaginary components smaller (in magnitude) than epsilon.
2190- * @f[
2191- \max\limits_{i} \Big|c_i| \le \valeps
2192- * @f]
2193- * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon().
2194- * Otherwise, use applyNonUnitaryTrotterizedPauliStrSumGadget() to permit non-Hermitian @p sum
2195- * and ergo effect a non-unitary exponential(s).
2196- * - The @p angle parameter is necessarily real despite the validation epsilon, but can be relaxed
2197- * to an arbitrary complex scalar using applyNonUnitaryTrotterizedPauliStrSumGadget().
2198- * - This function only ever effects @f$ \exp \left(\iu \, \theta \, \hat{H} \right) @f$ exactly
2199- * when all PauliStr in @p sum = @f$ \hat{H} @f$ commute.
2200- *
2201- * @param[in,out] qureg the state to modify.
2202- * @param[in] sum a weighted sum of Pauli strings to approximately exponentiate.
2203- * @param[in] angle an effective prefactor of @p sum in the exponent.
2204- * @param[in] order the order of the Trotter-Suzuki decomposition (e.g. @p 1, @p 2, @p 4, ...)
2205- * @param[in] reps the number of Trotter repetitions
2206- *
2207- * @throws @validationerror
2208- * - if @p qureg or @p sum are uninitialised.
2209- * - if @p sum is not approximately Hermitian.
2210- * - if @p sum contains non-identities on qubits beyond the size of @p qureg.
2211- * - if @p order is not 1 nor a positive, @b even integer.
2212- * - if @p reps is not a positive integer.
2213- *
2214- * @see
2215- * - applyPauliGadget()
2216- * - applyNonUnitaryTrotterizedPauliStrSumGadget()
2217- *
2218- * @author Tyson Jones
2219- */
2220- void applyTrotterizedPauliStrSumGadget (Qureg qureg, PauliStrSum sum, qreal angle, int order, int reps);
2221-
2222-
2223- // / @notyetdoced
2224- // / @notyettested
2225- // / @see
2226- // / - applyTrotterizedPauliStrSumGadget()
2227- // / - applyControlledCompMatr1()
2228- void applyControlledTrotterizedPauliStrSumGadget (Qureg qureg, int control, PauliStrSum sum, qreal angle, int order, int reps);
2229-
2230-
2231- // / @notyetdoced
2232- // / @notyettested
2233- // / @see
2234- // / - applyTrotterizedPauliStrSumGadget()
2235- // / - applyMultiControlledCompMatr1()
2236- void applyMultiControlledTrotterizedPauliStrSumGadget (Qureg qureg, int * controls, int numControls, PauliStrSum sum, qreal angle, int order, int reps);
2237-
2238-
2239- // / @notyetdoced
2240- // / @notyettested
2241- // / @see
2242- // / - applyTrotterizedPauliStrSumGadget()
2243- // / - applyMultiStateControlledCompMatr1()
2244- void applyMultiStateControlledTrotterizedPauliStrSumGadget (Qureg qureg, int * controls, int * states, int numControls, PauliStrSum sum, qreal angle, int order, int reps);
2245-
2246-
2247- /* * @notyettested
2248- *
2249- * A generalisation of applyTrotterizedPauliStrSumGadget() which accepts a complex angle and permits
2250- * @p sum to be non-Hermitian, thereby effecting a potentially non-unitary and non-CPTP operation.
2251- *
2252- * @formulae
2253- *
2254- * Let @f$ \hat{H} = @f$ @p sum and @f$ \theta = @f$ @p angle. This function approximates the action of
2255- * @f[
2256- \exp \left(\iu \, \theta \, \hat{H} \right)
2257- * @f]
2258- * via a Trotter-Suzuki decomposition of the specified @p order and number of repetitions (@p reps).
2259- *
2260- * See applyTrotterizedPauliStrSumGadget() for more information about the decomposition.
2261- *
2262- * @equivalences
2263- *
2264- * - When @p angle is set to @f$ \theta = \iu \, \tau @f$ and @p sum = @f$ \hat{H} @f$ is Hermitian,
2265- * this function (approximately) evolves @p qureg in imaginary-time. That is, letting
2266- * @f$ \hat{U}(t) = \exp(-\iu \, t \, \hat{H}) @f$ be the normalised unitary evolution operator, this
2267- * function effects the imaginary-time operator
2268- @f[
2269- \hat{V}(\tau) = \hat{U}(t=-\iu \tau) = \exp(- \tau \hat{H}).
2270- * @f]
2271- * This operation drives the system toward the (unnormalised) groundstate.
2272- * Let @f$ \{ \ket{\phi_i} \} @f$ and @f$ \{ \ket{\lambda_i} \} @f$ be the eigenstates and respective
2273- * eigenvalues of @f$ \hat{H} @f$, which are real due to Hermiticity.
2274- * @f[
2275- \hat{H} = \sum \limits_i \lambda_i \ket{\phi_i}\bra{\phi_i},
2276- \;\;\;\;\; \lambda_i \in \mathbb{R}.
2277- * @f]
2278- *
2279- * - When @p qureg is a statevector @f$ \svpsi @f$ and can ergo be expressed in the basis of
2280- * @f$ \{ \ket{\phi_i} \} @f$ as @f$ \svpsi = \sum_i \alpha_i \ket{\phi_i} @f$,
2281- * this function approximates
2282- * @f[
2283- \svpsi \, \rightarrow \, \hat{V}(\tau) \svpsi =
2284- \sum\limits_i \alpha_i \exp(- \tau \, \lambda_i) \ket{\phi_i}.
2285- * @f]
2286- * - When @p qureg is a density matrix and is ergo expressible as
2287- * @f$ \dmrho = \sum\limits_{ij} \alpha_{ij} \ket{\phi_i}\bra{\phi_j} @f$, this function effects
2288- * @f[
2289- \dmrho \, \rightarrow \, \hat{V}(\tau) \dmrho \hat{V}(\tau)^\dagger =
2290- \sum\limits_{ij} \alpha_{ij} \exp(-\tau (\lambda_i + \lambda_j)) \ket{\phi_i}\bra{\phi_j}.
2291- * @f]
2292- *
2293- * As @f$ \tau \rightarrow \infty @f$, the resulting unnormalised state approaches statevector
2294- * @f$ \svpsi \rightarrow \alpha_0 \exp(-\tau \lambda_0) \ket{\phi_0} @f$ or density matrix
2295- * @f$ \dmrho \rightarrow \alpha_{0,0} \exp(-2 \tau \lambda_0) \ket{\phi_0}\bra{\phi_0} @f$,
2296- * where @f$ \lambda_0 @f$ is the minimum eigenvalue and @f$ \ket{\phi_0} @f$ is the groundstate.
2297- * Assuming the initial overlap @f$ \alpha_0 @f$ is not zero (or exponentially tiny),
2298- * subsequent renormalisation via setQuregToRenormalized() produces the pure
2299- * ground-state @f$ \ket{\phi_0} @f$.
2300- *
2301- * ```
2302- // pray for a non-zero initial overlap
2303- initRandomPureState(qureg); // works even for density matrices
2304-
2305- // minimize then renormalise
2306- qreal tau = 10; // impatient infinity
2307- int order = 4;
2308- int reps = 100;
2309- applyNonUnitaryTrotterizedPauliStrSumGadget(qureg, hamil, tau * 1i, order, reps);
2310- setQuregToRenormalized(qureg);
2311-
2312- // ground-state (phi_0)
2313- reportQureg(qureg);
2314-
2315- // lowest lying eigenvalue (lambda_0)
2316- qreal expec = calcExpecPauliStrSum(qureg, hamil);
2317- reportScalar("expec", expec);
2318- * ```
2319- *
2320- * Note degenerate eigenvalues will yield a pure superposition of the corresponding eigenstates, with
2321- * coefficients informed by the initial, relative populations.
2322- *
2323- * - When @p angle is real and @p sum is Hermitian (has approximately real coefficients), this
2324- * function is equivalent to applyTrotterizedPauliStrSumGadget()
2325- *
2326- * @constraints
2327- * - This function only ever effects @f$ \exp \left(\iu \, \theta \, \hat{H} \right) @f$ exactly
2328- * when all PauliStr in @p sum = @f$ \hat{H} @f$ commute.
2329- *
2330- * @param[in,out] qureg the state to modify.
2331- * @param[in] sum a weighted sum of Pauli strings to approximately exponentiate.
2332- * @param[in] angle an effective prefactor of @p sum in the exponent.
2333- * @param[in] order the order of the Trotter-Suzuki decomposition (e.g. @p 1, @p 2, @p 4, ...)
2334- * @param[in] reps the number of Trotter repetitions
2335- *
2336- * @throws @validationerror
2337- * - if @p qureg or @p sum are uninitialised.
2338- * - if @p sum contains non-identities on qubits beyond the size of @p qureg.
2339- * - if @p order is not 1 nor a positive, @b even integer.
2340- * - if @p reps is not a positive integer.
2341- *
2342- * @author Tyson Jones
2343- */
2344- void applyNonUnitaryTrotterizedPauliStrSumGadget (Qureg qureg, PauliStrSum sum, qcomp angle, int order, int reps);
2345-
2346-
2347- // end de-mangler
2348- #ifdef __cplusplus
2349- }
2350- #endif
2351-
2352- #ifdef __cplusplus
2353-
2354-
2355- // / @notyettested
2356- // / @notyetvalidated
2357- // / @notyetdoced
2358- // / @cppvectoroverload
2359- // / @see applyMultiControlledTrotterizedPauliStrSumGadget()
2360- void applyMultiControlledTrotterizedPauliStrSumGadget (Qureg qureg, std::vector<int > controls, PauliStrSum sum, qreal angle, int order, int reps);
2361-
2362-
2363- // / @notyettested
2364- // / @notyetvalidated
2365- // / @notyetdoced
2366- // / @cppvectoroverload
2367- // / @see applyMultiStateControlledTrotterizedPauliStrSumGadget()
2368- void applyMultiStateControlledTrotterizedPauliStrSumGadget (Qureg qureg, std::vector<int > controls, std::vector<int > states, PauliStrSum sum, qreal angle, int order, int reps);
2369-
2370-
2371- #endif // __cplusplus
2372-
2373- /* * @} */
2374-
2375-
2376-
23772097/* *
23782098 * @defgroup op_nots Many-not gates
23792099 * @brief Functions for effecting many-qubit NOT gates
0 commit comments