Exemple #1
0
def is_gate_this_standard_unitary(gate_unitary, standard_gate_name):
    """
    Whether a unitary is, up to a phase, the standard gate specified by the name `standard_gate_name`.

    The correspondence between the standard names and unitaries is w.r.t the
    internally-used gatenames (see internal_gate_unitaries()).  For example, one use
    of this function is to check whether some gate specifed by a user with the name
    'Ghadamard' is the Hadamard gate, denoted internally by 'H'.

    Parameters
    ----------
    gate_unitary : complex np.array
        The unitary to test.

    standard_gate_name : str
        The standard gatename to check whether the unitary `gate_unitary` is (e.g., 'CNOT').

    Returns
    -------
    bool
        True if the `gate_unitary` is, up to phase, the unitary specified `standard_gate_name`.
        False otherwise.
    """
    std_unitaries = internal_gate_unitaries()
    if _np.shape(gate_unitary) != _np.shape(std_unitaries[standard_gate_name]):
        return False
    else:
        pm_input = _ot.unitary_to_pauligate(gate_unitary)
        pm_std = _ot.unitary_to_pauligate(std_unitaries[standard_gate_name])
        equal = _np.allclose(pm_input, pm_std)
        return equal
Exemple #2
0
    def test_unitary_to_pauligate(self):
        theta = np.pi
        sigmax = np.array([[0, 1], [1, 0]])
        ex = 1j * theta * sigmax / 2
        U = scipy.linalg.expm(ex)
        # U is 2x2 unitary matrix operating on single qubit in [0,1] basis (X(pi) rotation)

        op = ot.unitary_to_pauligate(U)
        op_ans = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.],
                           [0., 0., -1., 0.], [0., 0., 0., -1.]], 'd')
        self.assertArraysAlmostEqual(op, op_ans)

        U_2Q = np.identity(4, 'complex')
        U_2Q[2:, 2:] = U
        # U_2Q is 4x4 unitary matrix operating on isolated two-qubit space (CX(pi) rotation)

        op_2Q = ot.unitary_to_pauligate(U_2Q)
Exemple #3
0
    def setUpClass(cls):
        super(RBTheoryZrotModelTester, cls).setUpClass()
        cls.target_model = std1Q_XY.target_model()
        cls.mdl = cls.target_model.copy()

        Zrot_unitary = np.array([[1., 0.], [0., np.exp(-1j * 0.01)]])
        Zrot_channel = ot.unitary_to_pauligate(Zrot_unitary)

        for key in cls.target_model.operations.keys():
            cls.mdl.operations[key] = np.dot(Zrot_channel, cls.target_model.operations[key])
Exemple #4
0
    def test_densitymx_svterm_cterm(self):
        std_unitaries = itgs.standard_gatename_unitaries()

        for evotype in ['default']:  # 'densitymx', 'svterm', 'cterm'
            for name, U in std_unitaries.items():
                if callable(U):
                    continue  # skip unitary functions (create factories)
                dmop = op.StaticStandardOp(name,
                                           'pp',
                                           evotype,
                                           state_space=None)
                self.assertArraysAlmostEqual(
                    dmop._rep.to_dense('HilbertSchmidt'),
                    gt.unitary_to_pauligate(U))
Exemple #5
0
    def test_internalgate_definitions(self):
        # TODO is this test needed?
        self.skipTest(
            "RB analysis is known to be broken.  Skip tests until it gets fixed."
        )
        std_unitaries = internalgates.get_standard_gatename_unitaries()
        std_quil = internalgates.get_standard_gatenames_quil_conversions()
        std_quil = internalgates.get_standard_gatenames_openqasm_conversions()

        # Checks the standard Clifford gate unitaries agree with the Clifford group unitaries.
        group = rb.group.construct_1Q_Clifford_group()
        for key in group.labels:
            self.assertLess(
                np.sum(
                    abs(
                        np.array(group.get_matrix(key)) -
                        ot.unitary_to_pauligate(std_unitaries[key]))), 10**-10)
Exemple #6
0
def qasm_u3(theta, phi, lamb, output='unitary'):
    """
    The u3 1-qubit gate of QASM, returned as a unitary.

    if output = 'unitary' and as a processmatrix in the Pauli basis if out = 'superoperator.'

    Parameters
    ----------
    theta : float
        The theta parameter of the u3 gate.

    phi : float
        The phi parameter of the u3 gate.

    lamb : float
        The lambda parameter of the u3 gate.

    output : {'unitary', 'superoperator'}
        Whether the returned value is a unitary matrix or the Pauli-transfer-matrix
        superoperator representing that unitary action.

    Returns
    -------
    numpy.ndarray
    """
    u3_unitary = _np.array(
        [[_np.cos(theta / 2), -1 * _np.exp(1j * lamb) * _np.sin(theta / 2)],
         [
             _np.exp(1j * phi) * _np.sin(theta / 2),
             _np.exp(1j * (lamb + phi)) * _np.cos(theta / 2)
         ]])

    if output == 'unitary':
        return u3_unitary

    elif output == 'superoperator':
        u3_superoperator = _ot.unitary_to_pauligate(u3_unitary)
        return u3_superoperator

    else:
        raise ValueError("The `output` string is invalid!")