Skip to content

Commit

Permalink
!2296 Added qudit encoding & decoding, qutrit symmetric ansatz. Fixed…
Browse files Browse the repository at this point in the history
… and improved gate decomposition function

Merge pull request !2296 from GhostArtyom/r0.10
  • Loading branch information
donghufeng authored and gitee-org committed Apr 7, 2024
2 parents ea5da2b + f7cf69a commit de64d1b
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mindquantum.algorithm.compiler.qudit_symmetric_decoding
========================================================

.. py:function:: qudit_symmetric_decoding(qubit: np.ndarray, n_qubits: int = 1)
对称性解码,将qubit对称态或矩阵解码成qudit态或矩阵。

.. math::
\begin{align}
\ket{00\cdots00}&\to\ket{0} \\[.5ex]
\frac{\ket{0\cdots01}+\ket{0\cdots010}+\ket{10\cdots0}}{\sqrt{d-1}}&\to\ket{1} \\
\frac{\ket{0\cdots011}+\ket{0\cdots0101}+\ket{110\cdots0}}{\sqrt{d-1}}&\to\ket{2} \\
\vdots&\qquad\vdots \\[.5ex]
\ket{11\cdots11}&\to\ket{d-1}
\end{align}
参数:
- **qubit** (np.ndarray) - 需要解码的qubit对称态或矩阵,qubit态或矩阵需满足对称性。
- **n_qubits** (int) - qubit对称态或矩阵的量子比特数。默认值:``1``。

返回:
np.ndarray,对称性解码后的qudit态或矩阵。
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mindquantum.algorithm.compiler.qudit_symmetric_encoding
========================================================

.. py:function:: qudit_symmetric_encoding(qudit: np.ndarray, n_qudits: int = 1)
对称性编码,将qudit态或矩阵编码成qubit对称态或矩阵。

.. math::
\begin{align}
\ket{0}&\to\ket{00\cdots00} \\[.5ex]
\ket{1}&\to\frac{\ket{0\cdots01}+\ket{0\cdots010}+\ket{10\cdots0}}{\sqrt{d-1}} \\
\ket{2}&\to\frac{\ket{0\cdots011}+\ket{0\cdots0101}+\ket{110\cdots0}}{\sqrt{d-1}} \\
\vdots&\qquad\vdots \\[.5ex]
\ket{d-1}&\to\ket{11\cdots11}
\end{align}
参数:
- **qudit** (np.ndarray) - 需要编码的qudit态或矩阵。
- **n_qudits** (int) - qudit态或矩阵的量子位个数。默认值:``1``。

返回:
np.ndarray,对称性编码后的qubit对称态或矩阵。
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mindquantum.algorithm.compiler.qutrit_symmetric_ansatz
=======================================================

.. py:function:: qutrit_symmetric_ansatz(gate: UnivMathGate, basis: str = "zyz", with_phase: bool = False)
构造一个保持任意qutrit门编码对称性的qubit ansatz。

参考文献:
`Synthesis of multivalued quantum logic circuits by elementary gates <https://journals.aps.org/pra/abstract/10.1103/PhysRevA.87.012325>`_,
`Optimal synthesis of multivalued quantum circuits <https://journals.aps.org/pra/abstract/10.1103/PhysRevA.92.062317>`_。

参数:
- **gate** (:class:`~.core.gates.UnivMathGate`) - 由qutrit门编码而来的qubit门。
- **basis** (str) - 分解的基,可以是 ``"zyz"`` 或者 ``"u3"`` 中的一个。默认值: ``"zyz"``。
- **with_phase** (bool) - 是否将全局相位以 :class:`~.core.gates.GlobalPhase` 的形式作用在量子线路上。默认值: ``False``。

返回:
:class:`~.core.circuit.Circuit`,保持qutrit编码对称性的qubit ansatz。
3 changes: 3 additions & 0 deletions docs/api_python/algorithm/mindquantum.algorithm.library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ MindQuantum常用算法模块。
mindquantum.algorithm.library.general_ghz_state
mindquantum.algorithm.library.general_w_state
mindquantum.algorithm.library.qft
mindquantum.algorithm.library.qudit_symmetric_decoding
mindquantum.algorithm.library.qudit_symmetric_encoding
mindquantum.algorithm.library.qutrit_symmetric_ansatz
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def kak_decompose(gate: QuantumGate, return_u3: bool = True) -> Circuit:
(q_left, q_right), (dr, di) = utils.simult_svd(ur, ui)
d = dr + 1j * di

_, a0, a1 = kron_factor_4x4_to_2x2s(M @ q_left @ M_DAG)
_, b0, b1 = kron_factor_4x4_to_2x2s(M @ q_right.T @ M_DAG)
_, a1, a0 = kron_factor_4x4_to_2x2s(M @ q_left @ M_DAG)
_, b1, b0 = kron_factor_4x4_to_2x2s(M @ q_right.T @ M_DAG)

k = linalg.inv(A) @ np.angle(np.diag(d))
h1, h2, h3 = -k[1:]
Expand Down
1 change: 0 additions & 1 deletion mindquantum/algorithm/compiler/decompose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def params_zyz(mat: np.ndarray):
coe = linalg.det(mat) ** (-0.5)
alpha = -np.angle(coe)
v = coe * mat
v = v.round(10)
theta = 2 * atan2(abs(v[1, 0]), abs(v[0, 0]))
phi_lam_sum = 2 * np.angle(v[1, 1])
phi_lam_diff = 2 * np.angle(v[1, 0])
Expand Down
6 changes: 5 additions & 1 deletion mindquantum/algorithm/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from .general_ghz_state import general_ghz_state
from .general_w_state import general_w_state
from .quantum_fourier import qft
from .qudit_mapping import qudit_symmetric_decoding, qudit_symmetric_encoding, qutrit_symmetric_ansatz

__all__ = ['qft', 'amplitude_encoder', 'general_w_state', 'general_ghz_state', 'bitphaseflip_operator']
__all__ = [
'qft', 'amplitude_encoder', 'general_w_state', 'general_ghz_state', 'bitphaseflip_operator',
'qudit_symmetric_decoding', 'qudit_symmetric_encoding', 'qutrit_symmetric_ansatz'
]

__all__.sort()
Loading

0 comments on commit de64d1b

Please sign in to comment.