forked from tensorflow/quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cuQuantum test (but failed at numeric diff test)
- Loading branch information
Showing
5 changed files
with
215 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2023 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. | ||
# ============================================================================== | ||
"""Module to register cuQuantum simulation python op.""" | ||
import os | ||
import tensorflow as tf | ||
from tensorflow_quantum.core.ops.load_module import load_module | ||
|
||
SIM_OP_MODULE = load_module("_tfq_simulate_ops_cuquantum.so") | ||
|
||
|
||
def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): | ||
"""Calculates the expectation value of circuits wrt some operator(s). | ||
Args: | ||
programs: `tf.Tensor` of strings with shape [batch_size] containing | ||
the string representations of the circuits to be executed. | ||
symbol_names: `tf.Tensor` of strings with shape [n_params], which | ||
is used to specify the order in which the values in | ||
`symbol_values` should be placed inside of the circuits in | ||
`programs`. | ||
symbol_values: `tf.Tensor` of real numbers with shape | ||
[batch_size, n_params] specifying parameter values to resolve | ||
into the circuits specificed by programs, following the ordering | ||
dictated by `symbol_names`. | ||
pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] | ||
containing the string representation of the operators that will | ||
be used on all of the circuits in the expectation calculations. | ||
Returns: | ||
`tf.Tensor` with shape [batch_size, n_ops] that holds the | ||
expectation value for each circuit with each op applied to it | ||
(after resolving the corresponding parameters in). | ||
""" | ||
return SIM_OP_MODULE.tfq_simulate_expectation_cuquantum( | ||
programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters