@@ -1834,6 +1834,7 @@ void multiplyPauliGadget(Qureg qureg, PauliStr str, qreal angle);
1834
1834
qcomp factor = cexp(- theta / 2 * 1.i);
1835
1835
setQuregToSuperposition(factor, qureg, 0,qureg,0,qureg);
1836
1836
* ```
1837
+ * - Passing @p angle=0 is equivalent to effecting the identity, leaving the state unchanged.
1837
1838
*
1838
1839
* @myexample
1839
1840
* ```
@@ -1850,13 +1851,20 @@ void multiplyPauliGadget(Qureg qureg, PauliStr str, qreal angle);
1850
1851
// concisely
1851
1852
applyPauliGadget(qureg, getInlinePauliStr("XYZ",{0,1,7}), theta);
1852
1853
* ```
1853
- * - Passing @p angle=0 is equivalent to effecting the identity, leaving the state unchanged.
1854
+ *
1855
+ * @see
1856
+ * - applyNonUnitaryPauliGadget()
1854
1857
*/
1855
1858
void applyPauliGadget (Qureg qureg, PauliStr str, qreal angle);
1856
1859
1857
- // / @notyetdoced
1860
+
1861
+ /* * @notyetdoced
1862
+ *
1863
+ * This function generalises applyPauliGadget() to accept a complex angle.
1864
+ */
1858
1865
void applyNonUnitaryPauliGadget (Qureg qureg, PauliStr str, qcomp angle);
1859
1866
1867
+
1860
1868
// / @notyetdoced
1861
1869
void applyControlledPauliGadget (Qureg qureg, int control, PauliStr str, qreal angle);
1862
1870
@@ -2265,8 +2273,13 @@ extern "C" {
2265
2273
void multiplyPauliStrSum (Qureg qureg, PauliStrSum sum, Qureg workspace);
2266
2274
2267
2275
2268
- /* * @notyetdoced
2269
- * @notyettested
2276
+ /* * @notyettested
2277
+ *
2278
+ * Effects (an approximation to) the exponential of @p sum, weighted by @p angle, upon @p qureg,
2279
+ * via the symmetrized Trotter-Suzuki decomposition (<a href="https://arxiv.org/abs/math-ph/0506007">arXiv</a>).
2280
+ * Increasing @p reps (the number of Trotter repetitions) or @p order (an even, positive integer or one)
2281
+ * improves the accuracy of the approximation (reducing the "Trotter error" due to non-commuting
2282
+ * terms of @p sum), though increases the runtime linearly and exponentially respectively.
2270
2283
*
2271
2284
* @formulae
2272
2285
*
@@ -2275,14 +2288,18 @@ void multiplyPauliStrSum(Qureg qureg, PauliStrSum sum, Qureg workspace);
2275
2288
\exp \left(\iu \, \theta \, \hat{H} \right)
2276
2289
* @f]
2277
2290
* via a Trotter-Suzuki decomposition of the specified @p order and number of repetitions (@p reps).
2291
+ * Simulation is exact, regardless of @p order or @p reps, only when all terms in @p sum commute.
2278
2292
*
2293
+ * @important
2294
+ * Note that @f$ \theta @f$ lacks the @f$ -\frac{1}{2} @f$ prefactor present in other functions like
2295
+ * applyPauliGadget().
2279
2296
*
2280
2297
* To be precise, let @f$ r = @f$ @p reps and assume @p sum is composed of
2281
2298
* @f$ T @f$-many terms of the form
2282
2299
* @f[
2283
2300
\hat{H} = \sum\limits_j^T c_j \, \hat{\sigma}_j
2284
2301
* @f]
2285
- * where @f$ c_j @f$ is the (necessarily real) coefficient of the @f$ j @f$-th PauliStr @f$ \hat{\sigma}_j @f$.
2302
+ * where @f$ c_j @f$ is the coefficient of the @f$ j @f$-th PauliStr @f$ \hat{\sigma}_j @f$.
2286
2303
*
2287
2304
* - When @p order=1, this function performs first-order Trotterisation, whereby
2288
2305
* @f[
@@ -2315,10 +2332,161 @@ void multiplyPauliStrSum(Qureg qureg, PauliStrSum sum, Qureg workspace);
2315
2332
*
2316
2333
* > These formulations are taken from 'Finding Exponential Product Formulas
2317
2334
* > of Higher Orders', Naomichi Hatano and Masuo Suzuki (2005) (<a href="https://arxiv.org/abs/math-ph/0506007">arXiv</a>).
2335
+ *
2336
+ * @equivalences
2337
+ *
2338
+ * - Time evolution of duration @f$ t @f$ under a time-independent Hamiltonian @p sum = @f$ \hat{H} @f$, as
2339
+ * per the unitary time evolution operator
2340
+ * @f[
2341
+ \hat{U}(t) = \exp(- \iu \, t \,\hat{H} \, / \, \hbar)
2342
+ * @f]
2343
+ * is approximated via @f$ \theta = - t / \hbar @f$.
2344
+ * ```
2345
+ qreal time = 3.14;
2346
+ qreal angle = - time / hbar;
2347
+ applyTrotterizedPauliStrSumGadget(qureg, sum, angle, order, reps);
2348
+ * ```
2349
+ * - This function is equivalent to applyNonUnitaryTrotterizedPauliStrSumGadget() when passing
2350
+ * a @p qcomp instance with a zero imaginary component as the @p angle parameter. This latter
2351
+ * function is useful for generalising dynamical simulation to imaginary-time evolution.
2352
+ *
2353
+ * @constraints
2354
+ * - Unitarity of the prescribed exponential(s) requires that @p sum is Hermitian, ergo containing
2355
+ * only real coefficients. Validation will check that @p sum is approximately Hermitian, permitting
2356
+ * coefficients with imaginary components smaller (in magnitude) than epsilon.
2357
+ * @f[
2358
+ \max\limits_{i} \Big|c_i| \le \valeps
2359
+ * @f]
2360
+ * where the validation epsilon @f$ \valeps @f$ can be adjusted with setValidationEpsilon().
2361
+ * Otherwise, use applyNonUnitaryTrotterizedPauliStrSumGadget() to permit non-Hermitian @p sum
2362
+ * and ergo effect a non-unitary exponential(s).
2363
+ * - The @p angle parameter is necessarily real despite the validation epsilon, but can be relaxed
2364
+ * to an arbitrary complex scalar using applyNonUnitaryTrotterizedPauliStrSumGadget().
2365
+ * - This function only ever effects @f$ \exp \left(\iu \, \theta \, \hat{H} \right) @f$ exactly
2366
+ * when all PauliStr in @p sum = @f$ \hat{H} @f$ commute.
2367
+ *
2368
+ * @param[in,out] qureg the state to modify.
2369
+ * @param[in] sum a weighted sum of Pauli strings to approximately exponentiate.
2370
+ * @param[in] angle an effective prefactor of @p sum in the exponent.
2371
+ * @param[in] order the order of the Trotter-Suzuki decomposition (e.g. @p 1, @p 2, @p 4, ...)
2372
+ * @param[in] reps the number of Trotter repetitions
2373
+ *
2374
+ * @throws @validationerror
2375
+ * - if @p qureg or @p sum are uninitialised.
2376
+ * - if @p sum is not approximately Hermitian.
2377
+ * - if @p sum contains non-identities on qubits beyond the size of @p qureg.
2378
+ * - if @p order is not 1 nor a positive, @b even integer.
2379
+ * - if @p reps is not a positive integer.
2380
+ *
2381
+ * @see
2382
+ * - applyPauliGadget()
2383
+ * - applyNonUnitaryTrotterizedPauliStrSumGadget()
2384
+ *
2385
+ * @author Tyson Jones
2318
2386
*/
2319
2387
void applyTrotterizedPauliStrSumGadget (Qureg qureg, PauliStrSum sum, qreal angle, int order, int reps);
2320
2388
2321
2389
2390
+ /* * @notyettested
2391
+ *
2392
+ * A generalisation of applyTrotterizedPauliStrSumGadget() which accepts a complex angle and permits
2393
+ * @p sum to be non-Hermitian, thereby effecting a potentially non-unitary and non-CPTP operation.
2394
+ *
2395
+ * @formulae
2396
+ *
2397
+ * Let @f$ \hat{H} = @f$ @p sum and @f$ \theta = @f$ @p angle. This function approximates the action of
2398
+ * @f[
2399
+ \exp \left(\iu \, \theta \, \hat{H} \right)
2400
+ * @f]
2401
+ * via a Trotter-Suzuki decomposition of the specified @p order and number of repetitions (@p reps).
2402
+ *
2403
+ * See applyTrotterizedPauliStrSumGadget() for more information about the decomposition.
2404
+ *
2405
+ * @equivalences
2406
+ *
2407
+ * - When @p angle is set to @f$ \theta = \iu \, \tau @f$ and @p sum = @f$ \hat{H} @f$ is Hermitian,
2408
+ * this function (approximately) evolves @p qureg in imaginary-time. That is, letting
2409
+ * @f$ \hat{U}(t) = \exp(-\iu \, t \, \hat{H}) @f$ be the normalised unitary evolution operator, this
2410
+ * function effects the imaginary-time operator
2411
+ @f[
2412
+ \hat{V}(\tau) = \hat{U}(t=-\iu \tau) = \exp(- \tau \hat{H}).
2413
+ * @f]
2414
+ * This operation drives the system toward the (unnormalised) groundstate.
2415
+ * Let @f$ \{ \ket{\phi_i} \} @f$ and @f$ \{ \ket{\lambda_i} \} @f$ be the eigenstates and respective
2416
+ * eigenvalues of @f$ \hat{H} @f$, which are real due to Hermiticity.
2417
+ * @f[
2418
+ \hat{H} = \sum \limits_i \lambda_i \ket{\phi_i}\bra{\phi_i},
2419
+ \;\;\;\;\; \lambda_i \in \mathbb{R}.
2420
+ * @f]
2421
+ *
2422
+ * - When @p qureg is a statevector @f$ \svpsi @f$ and can ergo be expressed in the basis of
2423
+ * @f$ \{ \ket{\phi_i} \} @f$ as @f$ \svpsi = \sum_i \alpha_i \ket{\phi_i} @f$,
2424
+ * this function approximates
2425
+ * @f[
2426
+ \svpsi \, \rightarrow \, \hat{V}(\tau) \svpsi =
2427
+ \sum\limits_i \alpha_i \exp(- \tau \, \lambda_i) \ket{\phi_i}.
2428
+ * @f]
2429
+ * - When @p qureg is a density matrix and is ergo expressible as
2430
+ * @f$ \dmrho = \sum\limits_{ij} \alpha_{ij} \ket{\phi_i}\bra{\phi_j} @f$, this function effects
2431
+ * @f[
2432
+ \dmrho \, \rightarrow \, \hat{V}(\tau) \dmrho \hat{V}(\tau)^\dagger =
2433
+ \sum\limits_{ij} \alpha_{ij} \exp(-\tau (\lambda_i + \lambda_j)) \ket{\phi_i}\bra{\phi_j}.
2434
+ * @f]
2435
+ *
2436
+ * As @f$ \tau \rightarrow \infty @f$, the resulting unnormalised state approaches statevector
2437
+ * @f$ \svpsi \rightarrow \alpha_0 \exp(-\tau \lambda_0) \ket{\phi_0} @f$ or density matrix
2438
+ * @f$ \dmrho \rightarrow \alpha_{0,0} \exp(-2 \tau \lambda_0) \ket{\phi_0}\bra{\phi_0} @f$,
2439
+ * where @f$ \lambda_0 @f$ is the minimum eigenvalue and @f$ \ket{\phi_0} @f$ is the groundstate.
2440
+ * Assuming the initial overlap @f$ \alpha_0 @f$ is not zero (or exponentially tiny),
2441
+ * subsequent renormalisation via setQuregToRenormalized() produces the pure
2442
+ * ground-state @f$ \ket{\phi_0} @f$.
2443
+ *
2444
+ * ```
2445
+ // pray for a non-zero initial overlap
2446
+ initRandomPureState(qureg); // works even for density matrices
2447
+
2448
+ // minimize then renormalise
2449
+ qreal tau = 10; // impatient infinity
2450
+ int order = 4;
2451
+ int reps = 100;
2452
+ applyNonUnitaryTrotterizedPauliStrSumGadget(qureg, hamil, tau * 1i, order, reps);
2453
+ setQuregToRenormalized(qureg);
2454
+
2455
+ // ground-state (phi_0)
2456
+ reportQureg(qureg);
2457
+
2458
+ // lowest lying eigenvalue (lambda_0)
2459
+ qreal expec = calcExpecPauliStrSum(qureg, hamil);
2460
+ reportScalar("expec", expec);
2461
+ * ```
2462
+ *
2463
+ * Note degenerate eigenvalues will yield a pure superposition of the corresponding eigenstates, with
2464
+ * coefficients informed by the initial, relative populations.
2465
+ *
2466
+ * - When @p angle is real and @p sum is Hermitian (has approximately real coefficients), this
2467
+ * function is equivalent to applyTrotterizedPauliStrSumGadget()
2468
+ *
2469
+ * @constraints
2470
+ * - This function only ever effects @f$ \exp \left(\iu \, \theta \, \hat{H} \right) @f$ exactly
2471
+ * when all PauliStr in @p sum = @f$ \hat{H} @f$ commute.
2472
+ *
2473
+ * @param[in,out] qureg the state to modify.
2474
+ * @param[in] sum a weighted sum of Pauli strings to approximately exponentiate.
2475
+ * @param[in] angle an effective prefactor of @p sum in the exponent.
2476
+ * @param[in] order the order of the Trotter-Suzuki decomposition (e.g. @p 1, @p 2, @p 4, ...)
2477
+ * @param[in] reps the number of Trotter repetitions
2478
+ *
2479
+ * @throws @validationerror
2480
+ * - if @p qureg or @p sum are uninitialised.
2481
+ * - if @p sum contains non-identities on qubits beyond the size of @p qureg.
2482
+ * - if @p order is not 1 nor a positive, @b even integer.
2483
+ * - if @p reps is not a positive integer.
2484
+ *
2485
+ * @author Tyson Jones
2486
+ */
2487
+ void applyNonUnitaryTrotterizedPauliStrSumGadget (Qureg qureg, PauliStrSum sum, qcomp angle, int order, int reps);
2488
+
2489
+
2322
2490
// end de-mangler
2323
2491
#ifdef __cplusplus
2324
2492
}
0 commit comments