Skip to content

fix: block_zxz phase bug - #76

Open
CXMghost wants to merge 5 commits into
cq-lib:release/2.0from
CXMghost:release/2.0
Open

CXMghost wants to merge 5 commits into
cq-lib:release/2.0from
CXMghost:release/2.0

Conversation

@CXMghost

Copy link
Copy Markdown

No description provided.

@jianjian01

Copy link
Copy Markdown
Collaborator
import numpy as np

from cqlib.compile.transform.decompose.block_zxz import decompose_block_zxz


def test_block_zxz_preserves_global_phase():
    rng = np.random.default_rng(13)
    shape = (32, 32)
    matrix = rng.normal(size=shape) + 1j * rng.normal(size=shape)
    unitary = np.linalg.qr(matrix)[0] * np.exp(0.321j)

    rebuilt = decompose_block_zxz(unitary).to_matrix()

    phase = np.angle(np.vdot(unitary, rebuilt))
    np.testing.assert_allclose(
        rebuilt, unitary, atol=1e-10, rtol=0,
        err_msg=f"Global phase error: {phase} rad",
    )

还是有相位问题。

原因是 A.2 无法把对角余项吸收到下一个两比特子电路时,会调用 diagonal_gate_circuit() 单独合成余项。该函数生成的 CX 和 Rz 保留了对角元素之间的相对相位,但返回前没有把缺少的整体相位写入电路。建议在这里补齐相位,并保留上面的完整矩阵断言作为回归测试。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants