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

Fix BulkSetAmpl bug, Add more diff cuquantum unit tests #17

Merged
merged 9 commits into from
May 5, 2023
Merged
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
2 changes: 1 addition & 1 deletion benchmarks/scripts/benchmark_clifford_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Benchmark simulators against classically simulatable circuits."""
import os
import time
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/benchmark_op_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Benchmark differentiator methods."""
import os
import time
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/benchmark_random_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Benchmark simulators against classically intractable 'supremacy' circuits."""
import os
import time
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/benchmark_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Utility functions for benchmark tools."""
import tensorflow as tf
import test_log_pb2
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/benchmark_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Tests for utilities related to reading/running benchmarks."""
import os
import tempfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Command line flags shared between benchmarks."""
from collections import namedtuple
from absl import flags as absl_flags
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/flags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Tests for benchmark command line flags."""

import tensorflow as tf
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# 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.
# ==============================================================================
# =============================================================================
2 changes: 1 addition & 1 deletion benchmarks/scripts/models/random_clifford_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================

from typing import Iterable

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/models/random_clifford_circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================

from absl.testing import parameterized
import cirq
Expand Down
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"

function write_to_bazelrc() {
Expand Down
2 changes: 1 addition & 1 deletion release/build_pip_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
set -e
set -x

Expand Down
2 changes: 1 addition & 1 deletion release/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""TensorFlow Quantum adds qauntum computing primitives to TensorFlow.

TensorFlow Quantum is an open source library for high performance batch
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Testing benchmarks.";
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...))
exit_code=$?
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Tool to generate external api_docs for tfq."""

from __future__ import absolute_import
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_pip_package_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================

pip install -r requirements.txt

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
sudo dpkg -i bazel_5.3.0-linux-x86_64.deb
pip install --upgrade pip setuptools wheel
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci_validate_tutorials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================

# Run the tutorials using the installed pip package
pip install jupyter nbclient==0.6.5 jupyter-client==6.1.12 ipython==7.22.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/format_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Doing python language formatting..."
python3 -m yapf --style=google --in-place --recursive ./benchmarks
python3 -m yapf --style=google --in-place --recursive ./tensorflow_quantum
Expand Down
2 changes: 1 addition & 1 deletion scripts/format_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Checking python formatting...";

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion scripts/format_ipynb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Format notebook code cells using yapf google style."""
import glob
import nbformat
Expand Down
2 changes: 1 addition & 1 deletion scripts/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Tests to check if importing `tfq` APIs is successful or not."""
import tensorflow_quantum as tfq

Expand Down
2 changes: 1 addition & 1 deletion scripts/lint_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Checking for lint in python code...";
linting_outputs=$(pylint --rcfile .pylintrc ./tensorflow_quantum ./examples);
exit_code=$?
Expand Down
2 changes: 1 addition & 1 deletion scripts/msan_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Testing All Bazel cc_tests with msan.";
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
--cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" \
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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
2 changes: 1 addition & 1 deletion scripts/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Testing All Bazel py_test and cc_tests.";
ENABLE_CUDA=${1}

Expand Down
2 changes: 1 addition & 1 deletion scripts/test_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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.
# ==============================================================================
# =============================================================================
echo "Testing all Benchmarks.";
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)
# test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all))
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Module to ensure all notebooks execute without error by pytesting them."""
import glob
import re
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Module functions for tensorflow_quantum.*"""

# Import basic ops and op getters.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Imports to tensorflow_quantum.core.* level."""
# Import getters for constructing ops.
from tensorflow_quantum.core.ops import (get_expectation_op,
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Module for tfq.core.ops.*"""

# Import getters for constructing ops.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/batch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""A module to for running Cirq objects."""
import collections

Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/batch_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Test parallel Cirq simulations."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
Expand Down
30 changes: 14 additions & 16 deletions tensorflow_quantum/core/ops/circuit_execution_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""A module for user-facing generators of tfq ops."""
import enum

Expand All @@ -23,15 +23,16 @@

try:
from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum
_enable_use_cuquantum = True
_ENABLE_USE_CUQUANTUM = True
except:
# `_enable_use_cuquantum = False` makes `use_cuquantum` silent.
_enable_use_cuquantum = False
# `_ENABLE_USE_CUQUANTUM = False` makes `use_cuquantum` silent.
_ENABLE_USE_CUQUANTUM = False
tfq_simulate_ops_cuquantum = tfq_simulate_ops


def is_cuda_configured() -> bool:
return _enable_use_cuquantum
def is_gpu_configured() -> bool:
"""Returns True if gpu ops are available or not."""
return _ENABLE_USE_CUQUANTUM


class TFQStateVectorSimulator(enum.Enum):
Expand All @@ -45,12 +46,9 @@ class TFQStateVectorSimulator(enum.Enum):
state = tfq_simulate_ops.tfq_simulate_state
state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state

sampled_expectation = (
tfq_simulate_ops.tfq_simulate_sampled_expectation
)
sampled_expectation = tfq_simulate_ops.tfq_simulate_sampled_expectation
sampled_expectation_cuquantum = (
tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation
)
tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation)


def _check_quantum_concurrent(quantum_concurrent, use_cuquantum):
Expand Down Expand Up @@ -150,7 +148,7 @@ def get_expectation_op(
"""
# TODO (mbbrough): investigate how the above docstring renders.
_check_quantum_concurrent(quantum_concurrent, use_cuquantum)
use_cuquantum = _enable_use_cuquantum and use_cuquantum
use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum

op = None
if backend is None:
Expand Down Expand Up @@ -256,7 +254,7 @@ def get_sampling_op(

# TODO (mbbrough): investigate how the above docstring renders.
_check_quantum_concurrent(quantum_concurrent, use_cuquantum)
use_cuquantum = _enable_use_cuquantum and use_cuquantum
use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum

op = None
if backend is None:
Expand Down Expand Up @@ -352,7 +350,7 @@ def get_state_op(

# TODO (mbbrough): investigate how the above docstring renders.
_check_quantum_concurrent(quantum_concurrent, use_cuquantum)
use_cuquantum = _enable_use_cuquantum and use_cuquantum
use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum

op = None
if backend is None:
Expand Down Expand Up @@ -470,7 +468,7 @@ def get_sampled_expectation_op(
"""
# TODO (mbbrough): investigate how the above docstring renders.
_check_quantum_concurrent(quantum_concurrent, use_cuquantum)
use_cuquantum = _enable_use_cuquantum and use_cuquantum
use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum

op = None
if backend is None:
Expand Down Expand Up @@ -503,4 +501,4 @@ def get_sampled_expectation_op(

raise TypeError(
"Backend {} is invalid. Expected a Cirq.Sampler or None.".format(
backend))
backend))
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/circuit_execution_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
# ==============================================================================
# =============================================================================
"""Module to test consistency between Cirq and TFQ circuit execution ops."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
Expand Down
Loading