-
Notifications
You must be signed in to change notification settings - Fork 357
Implement Bucket-Elimination-based contractor #92
Conversation
class BucketTest(tf.test.TestCase): | ||
|
||
def test_cnot_gate(self): | ||
net = network.TensorNetwork(backend="tensorflow") |
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.
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.
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.
Done.
# contractor. | ||
contraction_order = (copy_node,) | ||
net = bucket(net, contraction_order) | ||
net = naive(net) |
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.
This feels weird. Naive shouldn't work if any of the nodes were contracted. Why doesn't this hit the ValueError in naive?
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.
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) |
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.
np.testing.assert_allclose (same below)
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.
Done.
Squash and merge if you are ready. |
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). |
That's ok, I did that before too. Thanks for flipping the disable switch! |
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.