[go: nahoru, domu]

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

Python support for GPU ops [WIP] #759

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
python support for adj grad cuqantum op (needs to be merged WIP)
  • Loading branch information
Sinestro38 committed Apr 1, 2023
commit ae9cac57e3fd3456a706b9fe2d191fd1822d9b5e
14 changes: 9 additions & 5 deletions tensorflow_quantum/python/differentiators/adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Compute gradients by combining function values linearly."""
import tensorflow as tf

from tensorflow_quantum.core.ops import tfq_adj_grad_op
from tensorflow_quantum.core.ops import tfq_adj_grad_op, tfq_adj_grad_op_cuquantum
from tensorflow_quantum.python.differentiators import differentiator


Expand Down Expand Up @@ -98,13 +98,17 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values):
@differentiator.catch_empty_inputs
@tf.function
def differentiate_analytic(self, programs, symbol_names, symbol_values,
pauli_sums, forward_pass_vals, grad):
return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names,
symbol_values, pauli_sums, grad)
pauli_sums, forward_pass_vals, grad, use_gpu=False):
if use_gpu:
return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names,
symbol_values, pauli_sums, grad)
else:
return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names,
symbol_values, pauli_sums, grad)

def differentiate_sampled(self, programs, symbol_names, symbol_values,
pauli_sums, num_samples, forward_pass_vals, grad):
raise NotImplementedError(
"Adjoint state methods are not supported in sample based settings."
" Please use analytic expectation calculation or a different "
"tfq.differentiator.")
"tfq.differentiator.")