Rotation and State Preparation¶
Rotation and state preparation operators provide arbitrary-dimensional unitary rotations and the ability to prepare a target quantum state from |0⟩.
Overview¶
Operator |
Operation |
Unitarity class |
|---|---|---|
|
Apply an arbitrary-dimensional unitary matrix |
BaseOperator |
|
Prepare a target quantum state from |
BaseOperator |
—
Rot_GeneralUnitary (general unitary rotation)¶
Operation: Applies an arbitrary \(2^n \times 2^n\) unitary matrix to a register.
Parameters:
reg— target register (name or ID)matrix— unitary matrix (DenseMatrix_complexor a NumPy array)
Dagger: Applies the conjugate transpose of the matrix.
Purpose: When the standard gate library cannot directly express the desired transformation, you can specify it directly in matrix form.
Note
The matrix dimension must match the Hilbert-space dimension \(2^n\) of the register, where \(n\) is the number of bits in the register.
import numpy as np
import pysparq as ps
ps.System.clear()
ps.System.add_register("q", ps.UnsignedInteger, 2)
state = ps.SparseState()
# Define a 4x4 unitary matrix
matrix = np.eye(4, dtype=complex)
matrix[0, 0] = 0
matrix[0, 3] = 1
matrix[3, 3] = 0
matrix[3, 0] = 1
op = ps.Rot_GeneralUnitary("q", matrix)
op(state)
# Undo
op.dag(state)
—
Rot_GeneralStatePrep (quantum state preparation)¶
Operation: Prepares a register from the |0⟩ state into a target quantum state.
Parameters:
reg— target register (name or ID)state_vector— the target state vector (list of complex numbers or a NumPy array)
Dagger: Maps the target state back to |0⟩.
Mathematical representation: Given a target state \(|\psi\rangle = \sum_i \alpha_i |i\rangle\), construct a unitary \(U\) such that \(U|0\rangle = |\psi\rangle\).
Warning
This operator requires the register to currently be in the |0⟩ state. If the register already holds a nonzero value, the behavior is undefined.
import numpy as np
import pysparq as ps
ps.System.clear()
ps.System.add_register("q", ps.UnsignedInteger, 2)
state = ps.SparseState()
# Prepare a simplified Bell state: a uniform superposition
target = np.array([0.5, 0.5, 0.5, 0.5], dtype=complex)
op = ps.Rot_GeneralStatePrep("q", target)
op(state)
ps.pprint(state)
# |q=0⟩ : (0.5+0j)
# |q=1⟩ : (0.5+0j)
# |q=2⟩ : (0.5+0j)
# |q=3⟩ : (0.5+0j)
Helper Functions¶
stateprep_unitary_build_schmidt¶
Operation: Constructs the unitary matrix needed for state preparation using a Schmidt decomposition.
Purpose: Use it when you need to manually build or inspect the internal matrix of Rot_GeneralStatePrep.
中文版 ===
旋转与态制备¶
旋转与态制备算子提供任意维幺正旋转和从 |0⟩ 制备目标量子态的能力。
概述¶
算子 |
操作 |
幺正类 |
|---|---|---|
|
作用任意维幺正矩阵 |
BaseOperator |
|
从 |
BaseOperator |
—
Rot_GeneralUnitary(通用幺正旋转)¶
操作: 对寄存器作用一个任意 \(2^n \times 2^n\) 幺正矩阵。
参数:
reg— 目标寄存器(名称或 ID)matrix— 幺正矩阵(DenseMatrix_complex或 NumPy 数组)
Dagger: 作用矩阵的共轭转置。
用途: 当标准门库无法直接表达所需的变换时,可以通过矩阵形式直接指定。
Note
矩阵维度必须与寄存器的希尔伯特空间维度 \(2^n\) 匹配,其中 \(n\) 为寄存器比特数。
import numpy as np
import pysparq as ps
ps.System.clear()
ps.System.add_register("q", ps.UnsignedInteger, 2)
state = ps.SparseState()
# 定义 4x4 幺正矩阵
matrix = np.eye(4, dtype=complex)
matrix[0, 0] = 0
matrix[0, 3] = 1
matrix[3, 3] = 0
matrix[3, 0] = 1
op = ps.Rot_GeneralUnitary("q", matrix)
op(state)
# 撤销
op.dag(state)
—
Rot_GeneralStatePrep(量子态制备)¶
操作: 将寄存器从 |0⟩ 态制备为目标量子态。
参数:
reg— 目标寄存器(名称或 ID)state_vector— 目标态矢量(复数列表或 NumPy 数组)
Dagger: 将目标态映射回 |0⟩。
数学表示: 给定目标态 \(|\psi\rangle = \sum_i \alpha_i |i\rangle\),构造幺正 \(U\) 使得 \(U|0\rangle = |\psi\rangle\)。
Warning
该算子要求寄存器当前处于 |0⟩ 态。如果寄存器已有非零值,行为未定义。
import numpy as np
import pysparq as ps
ps.System.clear()
ps.System.add_register("q", ps.UnsignedInteger, 2)
state = ps.SparseState()
# 制备 Bell 态的简化版:均匀叠加
target = np.array([0.5, 0.5, 0.5, 0.5], dtype=complex)
op = ps.Rot_GeneralStatePrep("q", target)
op(state)
ps.pprint(state)
# |q=0⟩ : (0.5+0j)
# |q=1⟩ : (0.5+0j)
# |q=2⟩ : (0.5+0j)
# |q=3⟩ : (0.5+0j)
辅助函数¶
stateprep_unitary_build_schmidt¶
操作: 使用 Schmidt 分解构造态制备所需的幺正矩阵。
用途: 当需要手动构建或检查 Rot_GeneralStatePrep 的内部矩阵时使用。