def test_pauli_string_dag_from_circuit(repetition): q0, q1, q2 = cirq.LineQubit.range(3) c_orig = cirq.testing.nonoptimal_toffoli_circuit(q0, q1, q2) c_left, _ = convert_and_separate_circuit(c_orig) c_left_dag = pauli_string_dag_from_circuit(c_left) c_left_reordered = c_left_dag.to_circuit() cirq.testing.assert_allclose_up_to_global_phase(c_left.unitary(), c_left_reordered.unitary(), atol=1e-7)
def test_pauli_string_dag_from_circuit(repetition): q0, q1, q2 = cirq.LineQubit.range(3) c_orig = cirq.testing.nonoptimal_toffoli_circuit(q0, q1, q2) c_left, _ = convert_and_separate_circuit(c_orig) c_left_dag = pauli_string_dag_from_circuit(c_left) c_left_reordered = c_left_dag.to_circuit() cirq.testing.assert_allclose_up_to_global_phase( c_left.to_unitary_matrix(), c_left_reordered.to_unitary_matrix(), atol=1e-7)
def test_move_non_clifford_into_clifford(): q0, q1, q2 = cirq.LineQubit.range(3) c_orig = cirq.testing.nonoptimal_toffoli_circuit(q0, q1, q2) c_left, c_right = convert_and_separate_circuit(c_orig) # Normally, c_left would be optimized here c_left_dag = pauli_string_dag_from_circuit(c_left) c_recombined1 = move_pauli_strings_into_circuit(c_left, c_right) c_recombined2 = move_pauli_strings_into_circuit(c_left_dag, c_right) _assert_no_multi_qubit_pauli_strings(c_recombined1) _assert_no_multi_qubit_pauli_strings(c_recombined2) baseline_len = len(cirq.google.optimized_for_xmon(c_orig)) opt_len1 = len(cirq.google.optimized_for_xmon(c_recombined1)) opt_len2 = len(cirq.google.optimized_for_xmon(c_recombined2)) assert opt_len1 <= baseline_len assert opt_len2 <= baseline_len
def test_move_non_clifford_into_clifford(): q0, q1, q2 = cirq.LineQubit.range(3) c_orig = cirq.testing.nonoptimal_toffoli_circuit(q0, q1, q2) c_left, c_right = convert_and_separate_circuit(c_orig) # Normally, c_left would be optimized here c_left_dag = pauli_string_dag_from_circuit(c_left) c_recombined1 = move_non_clifford_into_clifford(c_left, c_right) c_recombined2 = move_non_clifford_into_clifford(c_left_dag, c_right) _assert_no_multi_qubit_pauli_strings(c_recombined1) _assert_no_multi_qubit_pauli_strings(c_recombined2) baseline_len = len(cirq.google.optimized_for_xmon(c_orig)) opt_len1 = len(cirq.google.optimized_for_xmon(c_recombined1)) opt_len2 = len(cirq.google.optimized_for_xmon(c_recombined2)) assert opt_len1 <= baseline_len assert opt_len2 <= baseline_len
def test_move_non_clifford_into_clifford(): cg = pytest.importorskip("cirq_google") q0, q1, q2 = cirq.LineQubit.range(3) c_orig = cirq.testing.nonoptimal_toffoli_circuit(q0, q1, q2) c_left, c_right = convert_and_separate_circuit(c_orig) # Normally, c_left would be optimized here c_left_dag = pauli_string_dag_from_circuit(c_left) c_recombined1 = move_pauli_strings_into_circuit(c_left, c_right) c_recombined2 = move_pauli_strings_into_circuit(c_left_dag, c_right) _assert_no_multi_qubit_pauli_strings(c_recombined1) _assert_no_multi_qubit_pauli_strings(c_recombined2) with cirq.testing.assert_deprecated('Use cirq.optimize_for_target_gateset', deadline='v0.16', count=None): baseline_len = len(cg.optimized_for_xmon(c_orig)) opt_len1 = len(cg.optimized_for_xmon(c_recombined1)) opt_len2 = len(cg.optimized_for_xmon(c_recombined2)) assert opt_len1 <= baseline_len assert opt_len2 <= baseline_len