Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RZ gate #1

Merged
merged 4 commits into from
Feb 11, 2021
Merged

RZ gate #1

merged 4 commits into from
Feb 11, 2021

Conversation

jessding
Copy link
Contributor

No description provided.

@Hanrui-Wang
Copy link
Collaborator

I think in pennylane and qiskit they use this implementation: https://www.quantum-inspire.com/kbase/rz-gate/
https://qiskit.org/documentation/stubs/qiskit.circuit.library.RZGate.html

They differ in a global phase. We'd better implement the one as them.

Below is the code from pennylane for your reference

class RZ(DiagonalOperation):
    r"""RZ(phi, wires)
    The single qubit Z rotation

    .. math:: R_z(\phi) = e^{-i\phi\sigma_z/2} = \begin{bmatrix}
                e^{-i\phi/2} & 0 \\
                0 & e^{i\phi/2}
            \end{bmatrix}.

    **Details:**

    * Number of wires: 1
    * Number of parameters: 1
    * Gradient recipe: :math:`\frac{d}{d\phi}f(R_z(\phi)) = \frac{1}{2}\left[f(R_z(\phi+\pi/2)) - f(R_z(\phi-\pi/2))\right]`
      where :math:`f` is an expectation value depending on :math:`R_z(\phi)`.

    Args:
        phi (float): rotation angle :math:`\phi`
        wires (Sequence[int] or int): the wire the operation acts on
    """
    num_params = 1
    num_wires = 1
    par_domain = "R"
    grad_method = "A"
    generator = [PauliZ, -1 / 2]

    @classmethod
    def _matrix(cls, *params):
        theta = params[0]
        p = cmath.exp(-0.5j * theta)

        return np.array([[p, 0], [0, p.conjugate()]])

    @classmethod
    def _eigvals(cls, *params):
        theta = params[0]
        p = cmath.exp(-0.5j * theta)

        return np.array([p, p.conjugate()])

@jessding
Copy link
Contributor Author

updated

@Hanrui-Wang Hanrui-Wang merged commit c2c5516 into master Feb 11, 2021
@Hanrui-Wang Hanrui-Wang deleted the jessding branch February 1, 2023 15:49
Hanrui-Wang pushed a commit that referenced this pull request Oct 15, 2023
Separate Hadamard from Code Main File
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.

None yet

2 participants