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

Unary iteration: nth_operation_callgraph for more subclasses #844

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import itertools
from functools import cached_property
from typing import Callable, Sequence, Tuple
from typing import Callable, Sequence, Set, Tuple

import attrs
import cirq
Expand All @@ -23,6 +23,8 @@
from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, QAny, QBit, Register, Signature
from qualtran._infra.gate_with_registers import total_bits
from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate
from qualtran.cirq_interop._cirq_to_bloq import _cirq_gate_to_bloq
from qualtran.resource_counting import BloqCountT


@attrs.frozen
Expand Down Expand Up @@ -104,6 +106,10 @@ def nth_operation( # type: ignore[override]
target_idx = int(np.ravel_multi_index(selection_idx, selection_shape))
return self.nth_gate(*selection_idx).on(target[target_idx]).controlled_by(control)

def nth_operation_callgraph(self, **selection_regs_name_to_val) -> Set['BloqCountT']:
selection_idx = tuple(selection_regs_name_to_val[reg.name] for reg in self.selection_regs)
return {(_cirq_gate_to_bloq(self.nth_gate(*selection_idx)), 1)}
Comment on lines +109 to +111
Copy link
Collaborator

Choose a reason for hiding this comment

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

The self.target_gate and self.nth_gate should be controlled gates here and below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would be a good opportunity to revisit these gates, use the new controlled infrastructure, create a bloq example and fix whatever is failing.



@bloq_example
def _apply_z_to_odd() -> ApplyGateToLthQubit:
Expand Down
7 changes: 6 additions & 1 deletion qualtran/bloqs/multiplexers/selected_majorana_fermion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from functools import cached_property
from typing import Sequence, Tuple, Union
from typing import Sequence, Set, Tuple, Union

import attrs
import cirq
Expand All @@ -23,7 +23,9 @@
from qualtran import QAny, QBit, Register
from qualtran._infra.data_types import BoundedQUInt
from qualtran._infra.gate_with_registers import total_bits
from qualtran.bloqs.basic_gates import CNOT, CZPowGate
from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate
from qualtran.cirq_interop._cirq_to_bloq import _cirq_gate_to_bloq


@attrs.frozen
Expand Down Expand Up @@ -120,3 +122,6 @@ def nth_operation( # type: ignore[override]
yield cirq.CNOT(control, *accumulator)
yield self.target_gate(target[target_idx]).controlled_by(control)
yield cirq.CZ(*accumulator, target[target_idx])

def nth_operation_callgraph(self, **selection_regs_name_to_val) -> Set['BloqCountT']:
return {(CNOT(), 1), (_cirq_gate_to_bloq(self.target_gate), 1), (CZPowGate(), 1)}
Loading