-
Notifications
You must be signed in to change notification settings - Fork 584
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
Add tfq.math.mps_1d_expectation
for 1D MPS
#610
Merged
Merged
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
43b25b8
initial commit
jaeyoo d56c35d
Fix simulate_mps_test
jaeyoo ae41578
Add CheckQubitsIn1D
jaeyoo b3f6d97
Add Eigen & QSim MPS
jaeyoo 9f8963e
Add mps_1d op and its test
jaeyoo b85e932
Mike's feedback - add bond_dim as attr
jaeyoo 3974752
Add Attr and its tests
jaeyoo b0a013d
Rename to mps_1d_expectation
jaeyoo 3c21e16
Fix lint and format
jaeyoo 1dbd1c0
Add import_test
jaeyoo 27a30d3
Fix wheel test - add mps into release/BUILD
jaeyoo 539b58d
Mike's feedback
jaeyoo 4f630c2
WIP where Segmentation fault happens?
jaeyoo c5a51be
Merge branch 'master' into add_mps_1d
jaeyoo bb5fc0b
Add Mike's feedback - no gate with control_qubit is allowed
jaeyoo cd6f239
Revert control_qubit gate validation.
jaeyoo fc86135
Fix program_resolution_test
jaeyoo ea1d543
Fix CheckQubitsIn1D()
jaeyoo 8035fc6
Add print messages
jaeyoo ce16003
Merge branch 'master' into add_mps_1d
jaeyoo 617bc6b
Add debug print
jaeyoo 86b0149
Bump up to qsim==0.10.2
jaeyoo b0f2daf
Remove tfq::QsimFor and util_qsim.h::ComputeExpectationMPS
jaeyoo af5b413
Add ComputeExpectationMPSQsim in util_qsim.h
jaeyoo bf533d5
Add more detailed debug prints
jaeyoo 9257c90
Bump up bond_dim from 2 (default) to 4 to fix segfault error.
jaeyoo 643e46c
Fix how to use ApplyGate in ComputeExpectationMPSQsim
jaeyoo 7057ca8
Uncomment ComputeSmall() and Remove debug outputs
jaeyoo 2adca84
Fix format
jaeyoo fa51a17
Mike's feedback 1 : use fuses circuit and ApplyFusedGate()
jaeyoo 01ff1c5
Mike's feedback 2 : set default bond_dim to 4
jaeyoo 97c11e9
Fix format
jaeyoo 4aed1b1
Mike's feedback 3 : bump up to qsim==0.10.3
jaeyoo cd216d7
Merge branch 'master' into add_mps_1d
MichaelBroughton 3875c85
bring 1d mps expectation into working state.
MichaelBroughton 2b9f9de
empty test.
MichaelBroughton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,60 @@ | ||
# 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. | ||
# ============================================================================== | ||
"""Module to register MPS simulation ops.""" | ||
import os | ||
import tensorflow as tf | ||
from tensorflow_quantum.core.ops.load_module import load_module | ||
|
||
MATH_OP_MODULE = load_module(os.path.join("math_ops", "_tfq_math_ops.so")) | ||
|
||
|
||
def mps_1d_expectation(programs, | ||
symbol_names, | ||
symbol_values, | ||
pauli_sums, | ||
bond_dim=4): | ||
"""Calculate 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. | ||
bond_dim: `tf.Tensor` for an integer representing bond dimension | ||
in this 1D MPS. This will create the following MPS: | ||
[2, bond_dim], [bond_dim, 2, bond_dim] ... [bond_dim, 2] | ||
|
||
The `bond_dim` should be >= 4. | ||
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 MATH_OP_MODULE.tfq_simulate_mps1d_expectation(programs, | ||
symbol_names, | ||
tf.cast( | ||
symbol_values, | ||
tf.float32), | ||
pauli_sums, | ||
bond_dim=bond_dim) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this just be a constant and doesn't have to be a
tf.Tensor
?