Пример #1
0
def test_rot_gates_eq():
    eq = cirq.testing.EqualsTester()
    gates = [
        cirq.RotXGate, cirq.RotYGate, cirq.RotZGate, cirq.CNotGate,
        cirq.Rot11Gate
    ]
    for gate in gates:
        eq.add_equality_group(gate(half_turns=3.5), gate(half_turns=-0.5),
                              gate(rads=-np.pi / 2), gate(degs=-90))
        eq.make_equality_group(lambda: gate(half_turns=0))
        eq.make_equality_group(lambda: gate(half_turns=0.5))

    eq.add_equality_group(cirq.RotXGate(), cirq.RotXGate(half_turns=1), cirq.X)
    eq.add_equality_group(cirq.RotYGate(), cirq.RotYGate(half_turns=1), cirq.Y)
    eq.add_equality_group(cirq.RotZGate(), cirq.RotZGate(half_turns=1), cirq.Z)
    eq.add_equality_group(
        cirq.RotZGate(half_turns=1, global_shift_in_half_turns=-0.5),
        cirq.RotZGate(half_turns=5, global_shift_in_half_turns=-0.5))
    eq.add_equality_group(
        cirq.RotZGate(half_turns=3, global_shift_in_half_turns=-0.5))
    eq.add_equality_group(
        cirq.RotZGate(half_turns=1, global_shift_in_half_turns=-0.1))
    eq.add_equality_group(
        cirq.RotZGate(half_turns=5, global_shift_in_half_turns=-0.1))
    eq.add_equality_group(cirq.CNotGate(), cirq.CNotGate(half_turns=1),
                          cirq.CNOT)
    eq.add_equality_group(cirq.Rot11Gate(), cirq.Rot11Gate(half_turns=1),
                          cirq.CZ)
Пример #2
0
 def operations(self, qubits: Sequence[cirq.QubitId]) -> cirq.OP_TREE:
     a, b = qubits
     yield cirq.RotXGate(half_turns=self.params['theta0']).on(a)
     yield cirq.RotXGate(half_turns=self.params['theta1']).on(b)
     yield cirq.CZ(a, b)
     yield cirq.RotXGate(half_turns=self.params['theta0']).on(a)
     yield cirq.RotXGate(half_turns=self.params['theta1']).on(b)
     yield cirq.MeasurementGate('all').on(a, b)
Пример #3
0
def test_x_matrix():
    assert np.allclose(cirq.RotXGate(half_turns=1).matrix(),
                       np.array([[0, 1], [1, 0]]))

    assert np.allclose(cirq.RotXGate(half_turns=0.5).matrix(),
                       np.array([[1 + 1j, 1 - 1j], [1 - 1j, 1 + 1j]]) / 2)

    assert np.allclose(cirq.RotXGate(half_turns=0).matrix(),
                       np.array([[1, 0], [0, 1]]))

    assert np.allclose(cirq.RotXGate(half_turns=-0.5).matrix(),
                       np.array([[1 - 1j, 1 + 1j], [1 + 1j, 1 - 1j]]) / 2)
Пример #4
0
def test_arbitrary_xyz_repr():
    cirq.testing.assert_equivalent_repr(
        cirq.RotXGate(half_turns=0.1, global_shift_in_half_turns=0.2))
    cirq.testing.assert_equivalent_repr(
        cirq.RotYGate(half_turns=0.1, global_shift_in_half_turns=0.2))
    cirq.testing.assert_equivalent_repr(
        cirq.RotZGate(half_turns=0.1, global_shift_in_half_turns=0.2))
Пример #5
0
def rot_x_layer(length, half_turns):
    """Yields X rotations by half_turns on a square grid of given length."""
    rot = cirq.RotXGate(half_turns=half_turns)
    for i in range(length):
        for j in range(length):
            yield rot(cirq.GridQubit(i, j))
            pass
        pass
    pass
Пример #6
0
def test_two_qubit_product_state_identity(half_turn=0.1,
                                          repetitions=1000,
                                          verbose=False):
    """Tests the VQSD algorithm for two qubit pure product states.
    State preperation is single qubit rotations.
    Diagonalizing unitary is the inverse of state prep.

    Tests to see if overlap is maximal.
    """
    # get a VQSD circuit
    circ = VQSD(2)

    # define the rotations
    rot = cirq.RotXGate(half_turns=half_turn)
    rotdag = cirq.RotXGate(half_turns=-half_turn)

    # add the state preperation
    circ.state_prep_circ.append([rot(circ.qubits[x]) for x in [0, 1, 4, 5]])

    # add the unitary
    circ.unitary_circ.append([rotdag(circ.qubits[x]) for x in [0, 1, 4, 5]])

    # add the dip test circuit
    circ.dip_test()

    # verbose output
    if verbose:
        print("The total circuit is", circ.algorithm(), sep="\n")

    # get the HS distance
    distance = circ.obj_dip(repetitions=repetitions)

    # make sure we're close
    tolerance = 1 / repetitions
    assert distance < tolerance

    # print success message
    print("test_two_qubit_product_state_identity()".ljust(DOT_LEN, DOT),
          "passed!",
          sep="")
Пример #7
0
    def _rot(self, qubit, params):
        """Helper function that returns an arbitrary rotation of the form
        R = Rz(params[2]) * Ry(params[1]) * Rx(params[0])
        on the qubit, e.g. R |qubit>.

        Note that order is reversed when put into the circuit. The circuit is:
        |qubit>---Rx(params[0])---Ry(params[1])---Rz(params[2])---
        """
        rx = cirq.RotXGate(half_turns=params[0])
        ry = cirq.RotYGate(half_turns=params[1])
        rz = cirq.RotZGate(half_turns=params[2])

        yield (rx(qubit), ry(qubit), rz(qubit))