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

Move Cirq-FT infrastructure to Qualtran #393

Merged
merged 12 commits into from
Oct 13, 2023
Merged

Conversation

tanujkhattar
Copy link
Collaborator

@tanujkhattar tanujkhattar commented Oct 12, 2023

This PR is the first big PR that moves code from Cirq-FT to Qualtran as part of Qualtran & Cirq-FT Integration

Some key features:

  • GateWithRegisters now exists in Qualtran and is both a cirq.Gate and a Bloq.
  • As a proof of concept, And and MultiAnd bloq's in Qualtran now derive from the GateWithRegisters class. They pass all existing tests and are used in cirq-ft style tests as well.
  • CirqGateAsBloq and BloqAsCirqGate don't depend upon cirq_ft at the top-level anymore. There still exists some temporary glue code that needs to support both cirq_ft.GateWithRegisters and qualtran.GateWithRegisters as part of the transition period, but that'll be gone once the migration is completed.
  • Other cirq infra code, like TComplexity, decompose_protocol etc. also make their way into qualtran as part of the cirq_interop repository. In follow-up PRs, we can rearrange this code (for example: move all or parts of TComplexity to resource_counting/ instead of cirq_interop).

cc @fdmalone @mpharrigan

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

Can you comment on lingering compatibility issues? It looks like Signature is almost the same but not quite

@@ -19,7 +19,7 @@
from typing import Dict, Iterable, Iterator, List, overload, Tuple, TYPE_CHECKING

import numpy as np
from attr import frozen
from attr import field, frozen
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this has already snuck through, but try to change these to attrs when you see one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

qualtran/_infra/registers.py Show resolved Hide resolved
qualtran/bloqs/arithmetic_test.py Show resolved Hide resolved
@@ -74,7 +74,7 @@ def test_swap_with_zero_gate(selection_bitsize, target_bitsize, n_target_registe
def test_swap_with_zero_gate_diagram():
gate = SwapWithZeroGate(3, 2, 4)
q = cirq.LineQubit.range(cirq.num_qubits(gate))
circuit = cirq.Circuit(gate.on_registers(**cirq_ft.infra.split_qubits(gate.signature, q)))
circuit = cirq.Circuit(gate.on_registers(**split_qubits(gate.signature, q)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are your intentions with this module (as well as swap_network.py). These are sortof half-hearted attempts at providing a bloq user-api from cirq gates from some time ago.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both of these would be removed and replaced with swap_network.py from Cirq-FT which already derives from GateWithRegisters and thus would be a Bloq.

Copy link
Collaborator

Choose a reason for hiding this comment

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

are you going to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup

qualtran/cirq_interop/_bloq_to_cirq.py Outdated Show resolved Hide resolved
qualtran/cirq_interop/_bloq_to_cirq.py Show resolved Hide resolved
qualtran/cirq_interop/_cirq_to_bloq.py Show resolved Hide resolved
_FREDKIN_GATESET = cirq.Gateset(cirq.FREDKIN, unroll_circuit_op=False)


def _fredkin(qubits: Sequence[cirq.Qid], context: cirq.DecompositionContext) -> cirq.OP_TREE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

reminder that per our agreement if this code still exists like 1 month from now I will unceremoniously remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't want to keep this code either. The project that takes care of supporting different decompositions when counting resources should remove this code as a first proof of concept. Whoever removes this code should make sure the T-counts of higher level primitives remain the same, and then I'm happy.

@mpharrigan mpharrigan mentioned this pull request Oct 13, 2023
@tanujkhattar
Copy link
Collaborator Author

It looks like Signature is almost the same but not quite

Cirq-FT signature is lacking a few accessor methods (like signature.lefts() / signature.rights()) but it's a strict subset of Qualtran.Signature. Apart from that there should no difference. Is there a specific compatibility issue that you are concerned about?

@tanujkhattar
Copy link
Collaborator Author

@mpharrigan I've addressed all your comments. This is ready for another look.

@mpharrigan
Copy link
Collaborator

Apart from that there should no difference. Is there a specific compatibility issue that you are concerned about?

The Side enum thing is a difference I wouldn't have expected, a priori.

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

sweeeeeeeeet

@tanujkhattar tanujkhattar enabled auto-merge (squash) October 13, 2023 18:56
@tanujkhattar tanujkhattar merged commit cf25d4f into main Oct 13, 2023
8 checks passed
@mpharrigan mpharrigan deleted the gate_with_registers branch November 22, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants