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

Fault tolerance notebook doc and test update #6158

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/and_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import cirq_ft
import numpy as np
import pytest
from cirq_ft.infra.jupyter_tools import execute_notebook

random.seed(12345)

Expand Down Expand Up @@ -199,10 +198,6 @@ def test_and_gate_adjoint(cv: Tuple[int, int]):
cirq_ft.testing.assert_circuit_inp_out_cirqsim(circuit, [c1, c2, t], inp, out)


def test_notebook():
execute_notebook('and_gate')


@pytest.mark.parametrize(
"cv", [*itertools.chain(*[itertools.product(range(2), repeat=n) for n in range(2, 7 + 1)])]
)
Expand Down
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/apply_gate_to_lth_target_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import cirq_ft
import pytest
from cirq_ft.infra.bit_tools import iter_bits
from cirq_ft.infra.jupyter_tools import execute_notebook


@pytest.mark.parametrize("selection_bitsize,target_bitsize", [[3, 5], [3, 7], [4, 5]])
Expand Down Expand Up @@ -101,7 +100,3 @@ def test_apply_gate_to_lth_qubit_make_on():
assert op.qubits == op2.qubits
assert op.gate.selection_regs == op2.gate.selection_regs
assert op.gate.control_regs == op2.gate.control_regs


def test_notebook():
execute_notebook('apply_gate_to_lth_target')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/generic_select_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import numpy as np
import pytest
from cirq_ft.infra.bit_tools import iter_bits
from cirq_ft.infra.jupyter_tools import execute_notebook


def get_1d_Ising_hamiltonian(
Expand Down Expand Up @@ -273,7 +272,3 @@ def test_generic_select_consistent_protocols_and_controlled():
)
with pytest.raises(NotImplementedError, match="Cannot create a controlled version"):
_ = gate.controlled(num_controls=2)


def test_notebook():
execute_notebook('generic_select')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/hubbard_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import cirq
import cirq_ft
import pytest
from cirq_ft.infra.jupyter_tools import execute_notebook


@pytest.mark.parametrize('dim', [*range(2, 10)])
Expand Down Expand Up @@ -69,7 +68,3 @@ def test_hubbard_model_consistent_protocols():
expected_symbols += ['target'] * 8
expected_symbols[0] = 'SelectHubbard'
assert cirq.circuit_diagram_info(select_gate).wire_symbols == tuple(expected_symbols)


def test_notebook():
execute_notebook('hubbard_model')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/qrom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np
import pytest
from cirq_ft.infra.bit_tools import iter_bits
from cirq_ft.infra.jupyter_tools import execute_notebook


@pytest.mark.parametrize(
Expand Down Expand Up @@ -101,10 +100,6 @@ def test_qrom_repr():
cirq.testing.assert_equivalent_repr(qrom, setup_code="import cirq_ft\nimport numpy as np")


def test_notebook():
execute_notebook('qrom')


@pytest.mark.parametrize(
"data", [[[1, 2, 3, 4, 5]], [[1, 2, 3], [4, 5, 10]], [[1], [2], [3], [4], [5], [6]]]
)
Expand Down
6 changes: 0 additions & 6 deletions cirq-ft/cirq_ft/algos/qubitization_walk_operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import pytest
from cirq_ft.algos.generic_select_test import get_1d_Ising_hamiltonian
from cirq_ft.algos.reflection_using_prepare_test import greedily_allocate_ancilla, keep
from cirq_ft.infra.jupyter_tools import execute_notebook


def walk_operator_for_pauli_hamiltonian(
Expand Down Expand Up @@ -234,8 +233,3 @@ def test_qubitization_walk_operator_consistent_protocols_and_controlled():
)
with pytest.raises(NotImplementedError, match="Cannot create a controlled version"):
_ = gate.controlled(num_controls=2)


def test_notebook():
execute_notebook('qubitization_walk_operator')
execute_notebook('phase_estimation_of_quantum_walk')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/state_preparation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
import pytest
from cirq_ft.algos.generic_select_test import get_1d_Ising_lcu_coeffs
from cirq_ft.infra.jupyter_tools import execute_notebook


@pytest.mark.parametrize("num_sites, epsilon", [[2, 3e-3], [3, 3.0e-3], [4, 5.0e-3], [7, 8.0e-3]])
Expand Down Expand Up @@ -83,7 +82,3 @@ def test_state_preparation_via_coherent_alias_sampling_diagram():
''',
qubit_order=qubit_order,
)


def test_notebook():
execute_notebook('state_preparation')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/swap_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import cirq_ft
import numpy as np
import pytest
from cirq_ft.infra.jupyter_tools import execute_notebook

random.seed(12345)

Expand Down Expand Up @@ -145,10 +144,6 @@ def test_multi_target_cswap_make_on():
assert cswap1 == cswap2


def test_notebook():
execute_notebook('swap_network')


@pytest.mark.parametrize("n", [*range(1, 6)])
def test_t_complexity(n):
g = cirq_ft.MultiTargetCSwap(n)
Expand Down
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/algos/unary_iteration_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pytest
from cirq._compat import cached_property
from cirq_ft.infra.bit_tools import iter_bits
from cirq_ft.infra.jupyter_tools import execute_notebook


class ApplyXToLthQubit(cirq_ft.UnaryIterationGate):
Expand Down Expand Up @@ -191,7 +190,3 @@ def test_unary_iteration_loop_empty_range():
qm = cirq.ops.SimpleQubitManager()
assert list(cirq_ft.unary_iteration(4, 4, [], [], [cirq.q('s')], qm)) == []
assert list(cirq_ft.unary_iteration(4, 3, [], [], [cirq.q('s')], qm)) == []


def test_notebook():
execute_notebook('unary_iteration')
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/infra/gate_with_registers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import cirq_ft
import numpy as np
import pytest
from cirq_ft.infra.jupyter_tools import execute_notebook


def test_register():
Expand Down Expand Up @@ -154,7 +153,3 @@ def test_gate_with_registers():
op1 = tg.on_registers(r1=qubits[:5], r2=qubits[6:], r3=qubits[5])
op2 = tg.on(*qubits[:5], *qubits[6:], qubits[5])
assert op1 == op2


def test_notebook():
execute_notebook('gate_with_registers')
20 changes: 0 additions & 20 deletions cirq-ft/cirq_ft/infra/jupyter_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
from typing import Optional

import cirq
import cirq.contrib.svg.svg as ccsvg
import cirq_ft.infra.testing as cq_testing
import IPython.display
import ipywidgets
import nbformat
from cirq_ft.infra import gate_with_registers, t_complexity_protocol
from nbconvert.preprocessors import ExecutePreprocessor


def display_gate_and_compilation(g: cq_testing.GateHelper, vertical=False, include_costs=True):
Expand Down Expand Up @@ -95,20 +92,3 @@ def svg_circuit(
if len(tdd.horizontal_lines) == 0:
raise ValueError("No non-empty moments.")
return IPython.display.SVG(ccsvg.tdd_to_svg(tdd))


def execute_notebook(name: str):
"""Execute a jupyter notebook in the caller's directory.

Args:
name: The name of the notebook without extension.
"""
import traceback

# Assumes that the notebook is in the same path from where the function was called,
# which may be different from `__file__`.
notebook_path = Path(traceback.extract_stack()[-2].filename).parent / f"{name}.ipynb"
with notebook_path.open() as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=600, kernel_name="python3")
ep.preprocess(nb)
5 changes: 0 additions & 5 deletions cirq-ft/cirq_ft/infra/t_complexity_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import cirq
import cirq_ft
import pytest
from cirq_ft.infra.jupyter_tools import execute_notebook


class SupportTComplexity:
Expand Down Expand Up @@ -204,7 +203,3 @@ def gate(self):
assert cirq_ft.t_complexity([op, op]) == cirq_ft.TComplexity()
assert op.num_calls == 1
cirq_ft.t_complexity.cache_clear()


def test_notebook():
execute_notebook('t_complexity')
2 changes: 0 additions & 2 deletions dev_tools/notebooks/isolated_notebook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
"**/google/*.ipynb",
"**/ionq/*.ipynb",
"**/pasqal/*.ipynb",
# skipp cirq-ft notebooks since they are included in individual tests
'cirq-ft/**',
# Rigetti uses local simulation with docker, so should work
# if you run into issues locally, run
# `docker compose -f cirq-rigetti/docker-compose.test.yaml up`
Expand Down
2 changes: 0 additions & 2 deletions dev_tools/notebooks/notebook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
'**/ionq/*.ipynb',
'**/pasqal/*.ipynb',
'**/rigetti/*.ipynb',
# skipp cirq-ft notebooks since they are included in individual tests
'cirq-ft/**',
# skipping fidelity estimation due to
# https://github.com/quantumlib/Cirq/issues/3502
'examples/*fidelity*',
Expand Down
23 changes: 23 additions & 0 deletions cirq-ft/cirq_ft/algos/and_gate.ipynb → docs/ft/and_gate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be102248",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" import cirq_ft\n",
"except ImportError:\n",
" print(\"installing cirq_ft...\")\n",
" !pip install --quiet cirq-ft\n",
" print(\"installed cirq ft.\")\n",
" import cirq_ft"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "93353f4e",
"metadata": {},
Expand All @@ -45,6 +62,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "37a44523",
"metadata": {},
Expand Down Expand Up @@ -74,6 +92,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "8d4e16dc",
"metadata": {},
Expand All @@ -95,6 +114,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "b91cc9d9",
"metadata": {},
Expand Down Expand Up @@ -137,6 +157,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "fa451755",
"metadata": {},
Expand All @@ -159,6 +180,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "3a2dcf07",
"metadata": {},
Expand All @@ -178,6 +200,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "a99e3bf5",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2776365",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" import cirq_ft\n",
"except ImportError:\n",
" print(\"installing cirq_ft...\")\n",
" !pip install --quiet cirq-ft\n",
" print(\"installed cirq ft.\")\n",
" import cirq_ft"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac3bfb05",
"metadata": {
Expand Down Expand Up @@ -50,6 +67,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "249829b0",
"metadata": {
Expand Down Expand Up @@ -123,4 +141,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d11f7154",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" import cirq_ft\n",
"except ImportError:\n",
" print(\"installing cirq_ft...\")\n",
" !pip install --quiet cirq-ft\n",
" print(\"installed cirq ft.\")\n",
" import cirq_ft"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ae4c107e",
"metadata": {
Expand Down Expand Up @@ -52,6 +69,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "f217ffaf",
"metadata": {
Expand Down
Loading
Loading