Skip to content

Commit

Permalink
Merge branch 'main' into 2024-08/non-thru-ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan authored Feb 28, 2025
2 parents 877a87b + ba8c807 commit 9c9e75a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Summary: yamllint configuration.
# See https://yamllint.readthedocs.io/ for info about configuration options.

rules:
line-length:
# YAML files (especially GitHub Actions workflows) tend to end up with
# long lines. The default of 80 is pretty limiting, and besides, in Python
# code linting, we set line lengths to 100. May as well follow suit here.
max: 100
# Another common occurrence in YAML files is long URLs. The next two
# settings are not specific to URLs, but help. It saves developer time by
# not requiring comment directives to disable warnings at every occurrence.
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
8 changes: 4 additions & 4 deletions qualtran/bloqs/data_loading/qroam_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
if reg is None:
return Text('QROAM').adjoint()
name = reg.name
if name == 'selection':
if name.startswith('selection'):
return TextBox('In').adjoint()
elif 'target' in name:
trg_indx = int(name.replace('target', '').replace('_', ''))
Expand Down Expand Up @@ -284,9 +284,9 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
if reg is None:
return Text('QROAM').adjoint()
name = reg.name
if name == 'selection':
if name.startswith('selection'):
return TextBox('In')
elif 'target' in name:
elif 'target' in name and 'junk' not in name:
trg_indx = int(name.replace('target', '').replace('_', ''))
# match the sel index
subscript = chr(ord('a') + trg_indx)
Expand Down Expand Up @@ -528,7 +528,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
if reg is None:
return Text('QROAM')
name = reg.name
if name == 'selection':
if name.startswith('selection'):
return TextBox('In')
elif 'target' in name and 'junk' not in name:
trg_indx = int(name.replace('target', '').replace('_', ''))
Expand Down
38 changes: 38 additions & 0 deletions qualtran/bloqs/data_loading/qroam_clean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
import pytest
import sympy

from qualtran._infra.data_types import QAny
from qualtran._infra.registers import Register
from qualtran.bloqs.data_loading.qroam_clean import (
_qroam_clean_multi_data,
_qroam_clean_multi_dim,
get_optimal_log_block_size_clean_ancilla,
QROAMClean,
QROAMCleanAdjoint,
QROAMCleanAdjointWrapper,
)
from qualtran.drawing.musical_score import Circle, LarrowTextBox, RarrowTextBox, Text, TextBox
from qualtran.resource_counting import get_cost_value, QubitCount
from qualtran.symbolics import ceil, log2

Expand All @@ -31,6 +35,40 @@ def test_bloq_examples(bloq_autotester):
bloq_autotester(_qroam_clean_multi_dim)


@pytest.mark.parametrize(
"reg, reg_type",
[
(None, Text),
(Register("selection", QAny(5)), TextBox),
(Register("selection0", QAny(5)), TextBox),
(Register("target0_", QAny(5)), RarrowTextBox),
(Register("junk_target0_", QAny(5)), RarrowTextBox),
(Register("control", QAny(5)), Circle),
],
)
def test_wire_symbol(reg, reg_type):
bloq = _qroam_clean_multi_dim.make()
assert isinstance(bloq.wire_symbol(reg, ()), reg_type)
assert isinstance(bloq.adjoint().wire_symbol(reg, ()), reg_type)


@pytest.mark.parametrize(
"reg, reg_type",
[
(None, Text),
(Register("selection", QAny(5)), TextBox),
(Register("selection0", QAny(5)), TextBox),
(Register("target0_", QAny(5)), LarrowTextBox),
(Register("control", QAny(5)), Circle),
],
)
def test_adjoint_wire_symbol(reg, reg_type):
data1 = np.arange(25, dtype=int).reshape((5, 5))
data2 = (np.arange(25, dtype=int) + 1).reshape((5, 5))
adjoint_bloq = QROAMCleanAdjoint.build_from_data(data1, data2, log_block_sizes=(1, 1))
assert isinstance(adjoint_bloq.wire_symbol(reg, ()), reg_type)


def test_qroam_clean_qubit_counts():
bloq = _qroam_clean_multi_data.make()
assert get_cost_value(bloq, QubitCount()) == get_cost_value(bloq.decompose_bloq(), QubitCount())
Expand Down

0 comments on commit 9c9e75a

Please sign in to comment.