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

Tf function support. #30

Open
AGaliciaMartinez opened this issue Aug 16, 2021 · 0 comments
Open

Tf function support. #30

AGaliciaMartinez opened this issue Aug 16, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@AGaliciaMartinez
Copy link
Member

AGaliciaMartinez commented Aug 16, 2021

I have been able to make the following code work:

@tf.function
def fastfunction(tensor):
    print('hi')
    qobj = qutip.Qobj(tensor)
    qobj += qobj
    return qobj.data._tf

fastfunction(tf.constant([10]))  # prints hi
fastfunction(tf.constant([10]))  # Does not print hi since it only executes the graph.

It does not work with the current version of TfTensor as the instantiation process does as first step:

data = tf.constant(data)

Not sure what the error message I get means, but removing this line of code makes the above compiled function to work. tf.constant is meant to create "constant" nodes in the graph, so it makes sense it complains as you are making a constant value from a variable input. The fix is quite easy, just check if it is a tensor an do not do the tf.constant in that case. However, having fastfunction accept Qobj as input is a little bit more involved and will most likely require us to create our own qtf.function. I believe it is doable though.

@AGaliciaMartinez AGaliciaMartinez added the enhancement New feature or request label Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant