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

Refactored code and created tensorflow backend #52

Merged
merged 6 commits into from May 18, 2019
Merged

Conversation

chaserileyroberts
Copy link
Contributor

@chaserileyroberts chaserileyroberts commented May 16, 2019

This is a big change, but I think it is for the better. (See #51 for details).

The next backend we will add will be a pure numpy implementation, then JAX, and then leave torch to the community.

@chaserileyroberts
Copy link
Contributor Author

This is a big design change so I would appreciate your inputs.

This was referenced May 16, 2019
Copy link
Contributor

@sleichen sleichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

network_components and ncon_interface need to be updated as well, right?

Also, I'm not sure how switching backends will be implemented, but it seems conceivable that someone could try to merge two networks created using two different backends. How do we deal with that?

tensornetwork/backends/base_backend.py Outdated Show resolved Hide resolved
tensornetwork/backends/base_backend.py Outdated Show resolved Hide resolved
tensornetwork/backends/base_backend.py Outdated Show resolved Hide resolved
def outer_product(self, tensor1: Tensor, tensor2: Tensor) -> Tensor:
"""Calculate the outer product of the two given tensors."""
raise NotImplementedError(
"Backend '{}' has not implemented trace.".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace --> outer_product

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell I copy and pasted? lol

@chaserileyroberts
Copy link
Contributor Author

Also, I'm not sure how switching backends will be implemented.

Two ways (I'm waiting on stavros building the numpy backend before trying it).

  1. Doing tensornetwork.TensorNetwork(backend='numpy')
  2. Defaulting to the global backend, and changing the global backend with tensornetwork.set_backend('numpy')

but it seems conceivable that someone could try to merge two networks created using two different backends. How do we deal with that?

Easiest thing to do is throw an error. We can check that the backends are the same before merging, which is pretty easy. We could have a converter by changing each node's tensor by doing torch.Tensor -> np.array -> tf.Tensor, but I expect that would get messy and I'm not sure people would use it often enought to justify the complexity.

All 4 backends we plan on supporting right now (JAX/PyTorch/TF/numpy) allow tensors to be created by converting a np.array to their own Tensor type. All higher level network creators we build would just have to build nodes using numpy and they would get converted internally.

@chaserileyroberts
Copy link
Contributor Author

chaserileyroberts commented May 17, 2019

network_components and ncon_interface need to be updated as well, right?

Yes they do.

Copy link
Contributor

@sleichen sleichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaserileyroberts chaserileyroberts merged commit 7977cc5 into master May 18, 2019
@chaserileyroberts chaserileyroberts deleted the backend branch May 18, 2019 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants