Repository: quantumlib/Qualtran

Issue:
Can't get the musical score of `QROAMClean`
Hi,

Here is the script:

```python3
from qualtran.bloqs.data_loading.qroam_clean import QROAMClean
import numpy as np

from qualtran.drawing import show_bloq

data1 = np.arange(8, dtype=int).reshape(2, 4)
qroam = QROAMClean.build_from_data(data1, log_block_sizes=1)

show_bloq(qroam)

from qualtran.drawing import get_musical_score_data, draw_musical_score
msd = get_musical_score_data(qroam)
```

and the error is

```bash
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[52], line 28
     25 show_bloq(qroam)
     27 from qualtran.drawing import get_musical_score_data, draw_musical_score
---> 28 msd = get_musical_score_data(qroam)

File ~/Software/quantum_resource_estimates/Qualtran/qualtran/drawing/musical_score.py:607, in get_musical_score_data(bloq, manager)
    605 for pred in preds:
    606     me = pred.right
--> 607     symb = _soq_to_symb(me)
    608     rpos = soq_assign[me]
    609     ident = _make_ident(binst, me)

File ~/Software/quantum_resource_estimates/Qualtran/qualtran/drawing/musical_score.py:503, in _soq_to_symb(soq)
    500     return Text(soq.pretty() + f'/{soq.reg.dtype}', fontsize=8)
    502 # Otherwise, use `Bloq.wire_symbol`.
--> 503 return soq.binst.bloq.wire_symbol(soq.reg, soq.idx)

File ~/Software/quantum_resource_estimates/Qualtran/qualtran/bloqs/data_loading/qroam_clean.py:545, in QROAMClean.wire_symbol(self, reg, idx)
    543 elif name == 'control':
    544     return Circle()
--> 545 raise ValueError(f'Unknown register name {name}')

ValueError: Unknown register name selection0
```

Discussion:
@mpharrigan: @tanujkhattar can you take a look? It seems like the `wire_symbol` method doesn't match the signature of the bloq

Solution patch:
diff --git a/qualtran/bloqs/data_loading/qroam_clean.py b/qualtran/bloqs/data_loading/qroam_clean.py
index 4dedb5be..7aa83dab 100644
--- a/qualtran/bloqs/data_loading/qroam_clean.py
+++ b/qualtran/bloqs/data_loading/qroam_clean.py
@@ -196,7 +196,7 @@ class QROAMCleanAdjoint(QROMBase, GateWithRegisters):  # type: ignore[misc]
         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('_', ''))
@@ -284,9 +284,9 @@ class QROAMCleanAdjointWrapper(Bloq):
         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)
@@ -528,7 +528,7 @@ class QROAMClean(SelectSwapQROM):
         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('_', ''))


Test patch:
diff --git a/qualtran/bloqs/data_loading/qroam_clean_test.py b/qualtran/bloqs/data_loading/qroam_clean_test.py
index 1f8cd0f0..02d6fd78 100644
--- a/qualtran/bloqs/data_loading/qroam_clean_test.py
+++ b/qualtran/bloqs/data_loading/qroam_clean_test.py
@@ -15,13 +15,17 @@ import numpy as np
 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
 
@@ -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())