Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Implement Bucket-Elimination-based contractor #92

Merged
merged 3 commits into from
Jun 5, 2019
Merged

Conversation

viathor
Copy link
Contributor

@viathor viathor commented Jun 3, 2019

The core of the logic for BE contractor is already implemented by #64 and #89. This just wraps it up in a contractor interface.

Note that like many other contraction algorithms, this one is very sensitive to contraction order. For this reason, we let the caller decide it. There are some heuristics in the literature which we should implement. Once we have them one of the can be made default to simplify the API by not requiring the second argument.

Context: #50.

class BucketTest(tf.test.TestCase):

def test_cnot_gate(self):
net = network.TensorNetwork(backend="tensorflow")
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert this to just use pytest (Remove tf.test.TestCase) and pass in the backends. None of your tests require tensorflow directly, so this will make sure it's always compatible with the other backends.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

# contractor.
contraction_order = (copy_node,)
net = bucket(net, contraction_order)
net = naive(net)
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels weird. Naive shouldn't work if any of the nodes were contracted. Why doesn't this hit the ValueError in naive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TensorNetwork.contract_copy_node() removes edges it contracts from self.edge_order in order to enable other contractors like naive to be used to finish contracting tensors that BE doesn't take care of.

net = naive(net)
result = net.get_final_node()
# Verify that CNOT has turned |11> into |10>.
self.assertAllClose(result.get_tensor(), 1.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

np.testing.assert_allclose (same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@chaserileyroberts
Copy link
Contributor

Squash and merge if you are ready.

@viathor viathor merged commit ee62b79 into master Jun 5, 2019
@viathor viathor deleted the bucket_contractor branch June 5, 2019 22:26
@viathor
Copy link
Contributor Author

viathor commented Jun 5, 2019

Accidentally merged all commits to master. Sorry.

I disabled "Allow merge commits" in project settings to prevent this in future. You can now choose between squash or rebase (copying all commits is disabled).

@chaserileyroberts
Copy link
Contributor

That's ok, I did that before too. Thanks for flipping the disable switch!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants