ワンクリックで
taylor
Simulate the time evolution of a quantum system using Taylor series expansion.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Simulate the time evolution of a quantum system using Taylor series expansion.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Root entrypoint for the quantum-skills package. Use this skill to route requests to the correct simulator or algorithm sub-skill, enforce full skill-chain reading before coding, and avoid duplicating implementation details that are already defined in leaf skills.
A set of quantum algorithms for solving linear systems of equations and related Fourier/signal-processing subroutines. This skill includes UnitaryLab implementations and educational resources for AQC, HHL, LCU, QFT, the basic single-qubit QSP demo, QSVT-QLSA, and VQLS.
Solve user-provided linear systems Ax = b with the UnitaryLab Variational Quantum Linear Solver, using a hardware-efficient ansatz and selectable local Hadamard-test, local classical, or global cost functions.
A top-level index of quantum algorithms centered on the UnitaryLab implementation, covering quantum primitives, linear systems, state preparation, cryptography, Hamiltonian simulation, Schrodingerization, quantum machine learning, eigensolvers, gradients, and quantum error correction, with selected Qiskit, PennyLane, and Classiq examples included as reference extensions.
Use when users ask about solving the discrete logarithm problem g^x ≡ y (mod P) with Shor-style two-register Fourier sampling, building/explaining DLP circuits, running simulator demos, or debugging post-processing (continued fractions plus two-dimensional Fourier-sample congruence solving). Relevant trigger terms include discrete log, DLP, Shor discrete logarithm, g^x mod P, modular exponentiation, two-dimensional Fourier sampling, continued fractions, congruence solving, and quantum cryptography demos.
Use this skill when the user asks for Shor integer factorization, quantum order-finding, period estimation, or implementing/running/debugging ShorAlgorithm in this repository (especially matrix/operator methods, IQFT-based phase post-processing, and continued-fraction period recovery). Relevant keywords include shor, factor N, order finding, period finding, modular exponentiation, continued fraction, quantum factoring, and ShorAlgorithm.
| name | taylor |
| description | Simulate the time evolution of a quantum system using Taylor series expansion. |
Category: Hamiltonian Simulation — Algebraic Expansion Methods
Purpose: Approximate the time-evolution operator $e^{-iHt}$ by truncating its Taylor series and expressing the result as a Linear Combination of Unitaries (LCU). The Hamiltonian is first decomposed into a weighted sum of Pauli strings; the Taylor series is then built order-by-order via dynamic programming; finally the combined operator is implemented as a single LCU circuit.
Core Idea:
pauli_string_power.Taylor expansion of the evolution operator:
$$ e^{-iHt} = \sum_{k=0}^{K} \frac{(-iHt)^k}{k!} + \mathcal{O}!\left(\frac{(\alpha t)^{K+1}}{(K+1)!}\right) $$
where $\alpha = |H|_2$ is the spectral norm.
Time-slicing reduces the per-slice parameter $\lambda = \alpha t$ to $\lambda / r$, allowing a lower truncation order $K$:
$$ r = \left\lfloor \frac{\alpha t}{0.5} \right\rfloor + 1, \qquad \lambda_{\text{slice}} = \frac{\alpha t}{r} $$
Adaptive degree selection:
$$ K = \min!\Bigl(\max!\bigl(K_{\text{init}},; \lceil 1.5,\lambda + 1.5\ln(1/\varepsilon) \rceil\bigr),; 15\Bigr) $$
Pauli decomposition of the Hamiltonian:
$$ H = \sum_{j} c_j P_j, \qquad P_j \in {I, X, Y, Z}^{\otimes n} $$
LCU representation of the truncated slice operator:
$$ U_{\text{approx}}^{(1)} \approx \sum_{\ell} w_\ell V_\ell, \qquad w_\ell \in \mathbb{R}{\geq 0},; V\ell \text{ unitary} $$
$$ e^{-iHt} \approx \bigl(U_{\text{approx}}^{(1)}\bigr)^r $$
Error metric (Frobenius norm):
$$ \varepsilon = \bigl|U_{\text{approx}}^r - e^{-iHt}\bigr|_F $$
TaylorAlgorithmclass TaylorAlgorithm:
def __init__(self, text_mode: str = "plain", algo_dir: str = None) -> None:
...
| Parameter | Type | Default | Description |
|---|---|---|---|
text_mode | str | "plain" | Output formatting mode for saved text reports ("plain" or "legacy"). |
algo_dir | str | None | None | Directory for saving results. Auto-derived from CWD if None. |
run() Methoddef run(self, H: np.ndarray, t: float, error: float, degree: int = 15) -> dict:
...
| Parameter | Type | Default | Constraints | Description |
|---|---|---|---|---|
H | np.ndarray | required | Square, Hermitian; padded to next power-of-2 if needed | Hamiltonian matrix. |
t | float | required | Finite real number | Total evolution time. |
error | float | required | > 0 | Target approximation error; used to compute the adaptive expansion degree. |
degree | int | 15 | ≥ 1, capped at 15 | Initial guess for the Taylor truncation order. Adjusted internally. |
| Name | Type | Requirements |
|---|---|---|
H | np.ndarray (complex128) | Square, Hermitian (checked to atol=1e-12); non-power-of-2 dims are zero-padded. |
t | float | Any finite real number. |
error | float | Strictly positive. |
degree | int | Positive integer; the runtime value is clipped to [computed_min, 15]. |
run()run() returns a dictionary built by _build_return_dict(). The output fields from algo.output are merged directly into the same dict via result.update(self.output).
| Key | Type | Description |
|---|---|---|
status | str | 'ok' on success, 'failed' on error. |
circuit_path | str | Path to the saved SVG circuit diagram. |
plot | list[dict] | List of saved result files, each {"format": str, "filename": str}. |
circuit | Circuit | The constructed LCU circuit object. |
Approximate evolution matrix | np.ndarray | $U_{\text{approx}}^r$ — the LCU-based time-evolution approximation. |
Exact evolution matrix | np.ndarray | $e^{-iHt}$ computed via scipy.linalg.expm. |
Frobenius norm of error | float | $|U_{\text{approx}}^r - e^{-iHt}|_F$. |
The same output fields are also accessible via algo.output after run() completes.
Stage 1 — Input validation and formatting
H is square, Hermitian, and finite-t.H to the next power-of-2 dimension if necessary.alpha = np.linalg.norm(H, 2) and lam = alpha * t.r = int(lam / 0.5) + 1.degree adaptively.Stage 2 — Pauli decomposition
pauli_string_decomposition(H * t / r) to expand the per-slice Hamiltonian into a list of (pauli_string, coefficient) tuples.Stage 3 — Taylor series construction
degree + 1 order maps (ans_term_map[k]) via dynamic programming:
ans_term_list of (pauli_string, complex_coeff) pairs.Stage 4 — Power elevation
pauli_string_power(ans_term_list, r) to raise the single-slice operator to the $r$-th power symbolically.Stage 5 — LCU circuit construction
(pauli_string, coeff) term:
magnitude = |coeff| as the LCU weight.phase = arg(coeff) and wraps it into a global phase gate via _make_U_rotation.LCU(lcu_terms).Stage 6 — Matrix extraction and error estimation
lcu_matrix[i*m, j*m] where m = len(LCU_terms).s to recover the true normalization.scipy.linalg.expm(-1j * H * t).| Constraint | Detail |
|---|---|
| Maximum Taylor degree | Hard-capped at 15 by implementation. |
| Hamiltonian dimension | Must be power-of-2; zero-padding is applied automatically. |
| Hermiticity tolerance | atol = 1e-12. |
| LCU term count | Grows exponentially with degree and the number of Pauli terms; large Hamiltonians increase memory use. |
| Function | Source | Role |
|---|---|---|
pauli_string_decomposition(H) | unitarylab.library.pauli_operator | Decomposes H into weighted Pauli strings. |
pauli_string_multiply(s1, s2) | unitarylab.library.pauli_operator | Multiplies two Pauli strings; returns result string and phase. |
pauli_string_power(terms, r) | unitarylab.library.pauli_operator | Raises a Pauli-string operator to integer power r. |
pauli_string_circuit(s) | unitarylab.library.pauli_operator | Builds the quantum circuit for a Pauli string. |
LCU(terms) | unitarylab.library | Constructs the LCU quantum circuit from (circuit, weight) pairs. |
Circuit.get_matrix() | unitarylab | Extracts the full unitary matrix from a circuit. |
import numpy as np
from unitarylab_algorithms import TaylorAlgorithm
# 2×2 Hermitian Hamiltonian
H = np.array([[2, 1],
[1, 3]], dtype=complex)
algo = TaylorAlgorithm(text_mode="plain")
result = algo.run(
H=H,
t=1.0,
error=1e-8,
degree=15,
)
print("status :", result["status"])
print("circuit_path:", result["circuit_path"])
print("plot :", result["plot"])
print("Frobenius error:", result["Frobenius norm of error"])
degree vs. timport numpy as np
from unitarylab_algorithms import TaylorAlgorithm
H = np.array([[2, 1],
[1, 3]], dtype=complex)
for t in [1.0, 3.0, 5.0]:
for degree in [5, 10, 15]:
algo = TaylorAlgorithm(text_mode="plain")
result = algo.run(H=H, t=t, error=1e-8, degree=degree)
frob_err = algo.output["Frobenius norm of error"]
print(f"t={t:.1f}, degree={degree:>2d}, error={frob_err:.2e}, status={result['status']}")
Expected observations:
t increases lam, which raises r (more slices) and the required degree.degree reduces error until it saturates near machine precision.t is compensated by more time slices.