tensorflow / quantum

Hybrid Quantum-Classical Machine Learning in TensorFlow
https://www.tensorflow.org/quantum
Apache License 2.0
1.79k stars 572 forks source link

Add cuQuantum-based TFQ native ops and layers. #770

Closed jaeyoo closed 1 year ago

jaeyoo commented 1 year ago

This has large changes and requires some deps error, rewrite documentations, and fixed internal bugs inside random ops, and so forth.

Please look at the PR descriptions in my repo to understand the procedures : https://github.com/jaeyoo/quantum/pulls?q=is%3Apr+is%3Aclosed

review-notebook-app[bot] commented 1 year ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sinestro38 commented 1 year ago

Breaking Changes

Major Features and Improvements

Source: https://github.com/Sinestro38/quantum/blob/master/tensorflow_quantum/release.md cc: @MichaelBroughton @QuantumJaeYoo

jccalvojackson commented 1 year ago

Hi I tried all the above and when ran the tests, these failed:

//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_test             FAILED in 8.9s
  /home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/testlogs/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test/test.log
//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_test            FAILED in 7.6s
  /home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/testlogs/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test/test.log
//tensorflow_quantum/python/layers/circuit_executors:sampled_expectation_test FAILED in 59.1s
  /home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/testlogs/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test/test.log
//tensorflow_quantum/python/optimizers:spsa_minimizer_test               FAILED in 24.6s
  /home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/testlogs/tensorflow_quantum/python/optimizers/spsa_minimizer_test/test.log

the output of the second test log being

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_test
-----------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/load_module.py", line 42, in load_module
    return load_library.load_op_library(path)
  File "/home/ubuntu/quantum_nvidia/quantum/quantum_env/lib/python3.8/site-packages/tensorflow/python/framework/load_library.py", line 54, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: libcublas.so.12: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py", line 23, in <module>
    from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py", line 19, in <module>
    SIM_OP_MODULE = load_module("_tfq_simulate_ops_cuquantum.so")
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/load_module.py", line 46, in load_module
    return load_library.load_op_library(path)
  File "/home/ubuntu/quantum_nvidia/quantum/quantum_env/lib/python3.8/site-packages/tensorflow/python/framework/load_library.py", line 54, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: /home/ubuntu/quantum_nvidia/quantum/quantum_env/lib/python3.8/site-packages/tensorflow_quantum/core/ops/_tfq_simulate_ops_cuquantum.so: cannot open shared object file: No such file or directory
Sinestro38 commented 1 year ago

@jccalvojackson

jccalvojackson commented 1 year ago

iI followed those, I didn't get any error during the build instructions.

when running configure I do get the message

cuQuantum library is detected here: CUQUANTUM_ROOT=<my path>

I tried again and see this error in one of the tests

Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/load_module.py", line 42, in load_module
    return load_library.load_op_library(path)
  File "/home/ubuntu/quantum_nvidia/quantum/quantum_env/lib/python3.8/site-packages/tensorflow/python/framework/load_library.py", line 54, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: libcublas.so.12: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py", line 23, in <module>
    from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py", line 19, in <module>
    SIM_OP_MODULE = load_module("_tfq_simulate_ops_cuquantum.so")
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/3a577e6722a9311ddc77692e6a730328/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.runfiles/__main__/tensorflow_quantum/core/ops/load_module.py", line 46, in load_module
    return load_library.load_op_library(path)
  File "/home/ubuntu/quantum_nvidia/quantum/quantum_env/lib/python3.8/site-packages/tensorflow/python/framework/load_library.py", line 54, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: libcublas.so.12: cannot open shared object file: No such file or directory

I see that I have /usr/local/cuda/lib64/libcublas.so.11 but not libcublas.so.12 how do I make it use 11 instead of 12?

when running configure it says

Please specify the CUDA SDK major version you want to use. [Leave empty to default to CUDA 11]:

which I do

jccalvojackson commented 1 year ago

managed to make it work (though is not using gpus significantly) but that's for later. Thank you!