Skip to content
Draft
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
14 changes: 10 additions & 4 deletions scripts/ci_validate_tutorials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ pip install \
"ipykernel>=6.29.0"

# Gymnasium pip package needed for the quantum reinforcement learning tutorial
pip install gymnasium[classic-control]==1.2.3
pip install "gymnasium[classic-control]==1.2.3"
# seaborn has also numpy dependency, it requires version >= 0.12.0.
pip install seaborn==0.12.0
# tf_docs pip package needed for noise tutorial.
pip install -q git+https://github.com/tensorflow/docs
# Leave the quantum directory, otherwise errors may occur
cd ..

examples_output=$(python3 quantum/scripts/test_tutorials.py)
# Leave the repository directory, otherwise errors may occur
thisdir=$(CDPATH="" cd -- "$(dirname -- "${0}")" && pwd -P)
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel 2>/dev/null)
parent_dir=$(dirname "${repo_dir}")
repo_name=$(basename "${repo_dir}")

cd "${parent_dir}"

examples_output=$(python3 "${repo_name}/scripts/test_tutorials.py")
exit_code=$?

if [ "$exit_code" == "0" ]; then
Expand Down
22 changes: 16 additions & 6 deletions scripts/run_example.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#!/bin/bash
# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
cd ..
cp quantum/scripts/import_test.py import_test.py
python import_test.py

set -e

thisdir=$(CDPATH="" cd -- "$(dirname -- "${0}")" && pwd -P)
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel 2>/dev/null)
parent_dir=$(dirname "${repo_dir}")
repo_name=$(basename "${repo_dir}")

# Leave the repository directory; otherwise, errors may occur.
cd "${parent_dir}"

cp "${repo_name}/scripts/import_test.py" import_test.py
python import_test.py
8 changes: 6 additions & 2 deletions scripts/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import glob
import re
import subprocess

from absl.testing import parameterized
import nbformat
Expand All @@ -29,8 +30,11 @@
# Pylint doesn't like code before imports, but we need the env var set first.
import tensorflow as tf # pylint: disable=wrong-import-position

# Must be run from the directory containing `quantum` repo.
NOTEBOOKS = glob.glob("quantum/docs/tutorials/*.ipynb")
# Must be run from the directory containing the repository.
this_dir = os.path.dirname(os.path.abspath(__file__))
repo_name = os.path.basename(os.path.abspath(os.path.join(this_dir, "..")))

NOTEBOOKS = glob.glob(os.path.join(repo_name, "docs", "tutorials", "*.ipynb"))


class ExamplesTest(tf.test.TestCase, parameterized.TestCase):
Expand Down
Loading