quantum icon indicating copy to clipboard operation
quantum copied to clipboard

Adds support for CCZ and CCX/TOF gates.

Open MichaelBroughton opened this issue 4 years ago • 6 comments

This PR adds serialization and C++ implementation support for three qubit eigen gates. A lot of this code is copy pasted from the two qubit cases with tweaks to work for the three qubit cases. Currently tests will fail on our unitary op since the latest qsim (https://github.com/quantumlib/qsim/blob/278b217f94bca179ac5fafd85498ee28bbd3e236/lib/unitary_calculator_basic.h#L52) unitary calculator doesn't support three qubit gates. This is being worked on by @sergeisakov so we should be able to merge very soon once we can upgrade our qsim dependency. Fixes #480

MichaelBroughton avatar Feb 22 '21 19:02 MichaelBroughton

@jaeyoo Would you be able to take a look at this issue ? It seems like the ParameterShift differentiator is breaking with adding the new gates. I did some investigation and I think it may have actually been broken by one of the recent PRs we did (since it still breaks even without the new gates sometimes if I increase the depth of the circuits). Do you think you would be able to take a look and see if you can spot the fix ?

MichaelBroughton avatar Mar 05 '21 18:03 MichaelBroughton

@jaeyoo Would you be able to take a look at this issue ? It seems like the ParameterShift differentiator is breaking with adding the new gates. I did some investigation and I think it may have actually been broken by one of the recent PRs we did (since it still breaks even without the new gates sometimes if I increase the depth of the circuits). Do you think you would be able to take a look and see if you can spot the fix ?

Let me look at it during weekend, and let's talk about it at our next sync.

jaeyoo avatar Mar 05 '21 23:03 jaeyoo

Oops, right, thank you for the catch. I am working on it, and found out the broken case in ParameterShift.

jaeyoo avatar Mar 10 '21 23:03 jaeyoo

Hi Mike, I want to ask you some questions.

I am trying to figure out the culprit circuit, but it seems not yet supported for multiple controlled qubit ops. For example, at the test test_gradients_vs_cirq_finite_difference in gradients_test.py, I used

        # will this be too tight? time will tell.
        self.assertAllClose(cirq_grads, tfq_grads, rtol=2e-2, atol=2e-2,
                            msg=f"{util.from_tensor(circuit_batch)}")

and got this error:

Traceback (most recent call last):
  File "/usr/local/google/home/jaeyoo/tfq-venv/lib/python3.8/site-packages/absl/testing/parameterized.py", line 282, in bound_param_test
    return test_method(self, **testcase_params)
  File "/usr/local/google/home/jaeyoo/.cache/bazel/_bazel_jaeyoo/7da1e95e8bb125cc5976e7c817e098d4/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/python/differentiators/gradie
nt_test.runfiles/__main__/tensorflow_quantum/python/differentiators/gradient_test.py", line 225, in test_gradients_vs_cirq_finite_difference
    msg=f"{util.from_tensor(circuit_batch)}")
  File "/usr/local/google/home/jaeyoo/.cache/bazel/_bazel_jaeyoo/7da1e95e8bb125cc5976e7c817e098d4/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/python/differentiators/gradie
nt_test.runfiles/__main__/tensorflow_quantum/python/util.py", line 380, in from_tensor
    found_item = _parse_single(item)
  File "/usr/local/google/home/jaeyoo/.cache/bazel/_bazel_jaeyoo/7da1e95e8bb125cc5976e7c817e098d4/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/python/differentiators/gradie
nt_test.runfiles/__main__/tensorflow_quantum/python/util.py", line 330, in _parse_single
    raise TypeError('Error decoding item: ' + str(item))
TypeError: Error decoding item: C1C1C0CZ**0.648900484520275*a((0, 2), (0, 4), (0, 1), (0, 3), (0, 0))

Any help please?

jaeyoo avatar Mar 15 '21 14:03 jaeyoo

Hmmm is circuit_batch something has had tfq.convert_to_tensor called on it ?

MichaelBroughton avatar Mar 16 '21 19:03 MichaelBroughton

Is there any update on this?

yudeep-rajbhandari avatar Aug 07 '22 05:08 yudeep-rajbhandari