Пример #1
0
def test_sycamore_gate_tabulation_repr():
    simple_tabulation = GateTabulation(
        np.array([[(1 + 0j), 0j, 0j, 0j]], dtype=np.complex128),
        np.array([[(1 + 0j), 0j, 0j, 0j]], dtype=np.complex128),
        [[]],
        0.49,
        'Sample string',
        (),
    )
    assert_equivalent_repr(simple_tabulation)
Пример #2
0
def test_sycamore_gate_tabulation_repr():
    simple_tabulation = GateTabulation(
        np.array([[(1 + 0j), 0j, 0j, 0j]], dtype=np.complex128),
        np.array([[(1 + 0j), 0j, 0j, 0j]], dtype=np.complex128),
        [[]],
        0.49,
        'Sample string',
        (),
    )
    assert_equivalent_repr(
        simple_tabulation,
        setup_code="import cirq\nimport cirq_google\nimport numpy as np")
Пример #3
0
def test_linear_permutation_gate(n_elements, n_permuted):
    qubits = cirq.LineQubit.range(n_elements)
    elements = tuple(range(n_elements))
    elements_to_permute = random.sample(elements, n_permuted)
    permuted_elements = random.sample(elements_to_permute, n_permuted)
    permutation = {e: p for e, p in
                   zip(elements_to_permute, permuted_elements)}
    cca.PermutationGate.validate_permutation(permutation, n_elements)
    gate = cca.LinearPermutationGate(n_elements, permutation)
    ct.assert_equivalent_repr(gate)
    assert gate.permutation() == permutation
    mapping = dict(zip(qubits, elements))
    for swap in cirq.flatten_op_tree(cirq.decompose_once_with_qubits(
            gate, qubits)):
        assert isinstance(swap, cirq.GateOperation)
        swap.gate.update_mapping(mapping, swap.qubits)
    for i in range(n_elements):
        p = permutation.get(elements[i], i)
        assert mapping.get(qubits[p], elements[i]) == i
Пример #4
0
def test_swap_network_repr(part_lens, acquaintance_size):
    gate = cca.SwapNetworkGate(part_lens, acquaintance_size)
    ct.assert_equivalent_repr(gate)