Skip to content

Commit ca452a9

Browse files
authored
Merge branch 'main' into semiclassical_qft
2 parents e411885 + 7a4c037 commit ca452a9

23 files changed

Lines changed: 206 additions & 119 deletions

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ abstract: >-
7272
Qualtran (quantum algorithms translator) is a set of abstractions for
7373
representing quantum programs, and a library of quantum algorithms expressed
7474
in that language to support quantum algorithms research.
75-
version: 0.5.0
76-
date-released: 2024-09-10
75+
version: 0.6.0
76+
date-released: 2025-04-01
7777
url: https://github.com/quantumlib/Qualtran
7878
repository-code: https://github.com/quantumlib/Qualtran
7979
license: Apache-2.0

dev_tools/bibliography.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@
131131
"source": [
132132
"for url, clss in sorted(backrefs.items(), key=lambda x: -len(x[1])):\n",
133133
" text = f'### [{titles[url]}]({url})\\n'\n",
134-
" for cls in clss:\n",
135-
" text += f' - {cls.__name__}\\n'\n",
134+
" class_names = [f'{cls._class_name_in_pkg_()}' for cls in clss]\n",
135+
" for cn in sorted(class_names):\n",
136+
" text += f' - {cn}\\n'\n",
136137
"\n",
137138
" display(Markdown(text))"
138139
]

dev_tools/qualtran_dev_tools/parse_docstrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def parse_reference(ref_text: str) -> ReferenceT:
4949
# To match the title and accept as many printable ascii characters as possible
5050
# besides square brackets, I have modified the range approach from
5151
# https://stackoverflow.com/a/31740504.
52-
link_match = re.match(r'^\[([ -Z^-~]+)]\((https?://[\w\d./?=#\-]+)\)\.?\s?(.*)$', ref_text)
52+
link_match = re.match(r'^\[([ -Z^-~]+)]\((https?://[\w\d./?=#\-\(\)]+)\)\.?\s?(.*)$', ref_text)
5353
if link_match:
5454
title = link_match.group(1)
5555
url = link_match.group(2)

dev_tools/qualtran_dev_tools/parse_docstrings_test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from .parse_docstrings import get_markdown_docstring_lines
14+
import pytest
15+
16+
from .bloq_finder import get_bloq_classes
17+
from .parse_docstrings import get_markdown_docstring_lines, get_references, UnparsedReference
1518

1619

1720
class ClassWithDocstrings:
@@ -40,3 +43,16 @@ def test_get_markdown_docstring_lines():
4043
' - [Google](www.google.com). Brin et. al. 1999.',
4144
'',
4245
]
46+
47+
48+
@pytest.mark.slow
49+
def test_parse_all_references():
50+
bloq_classes = get_bloq_classes()
51+
references = {bloq_cls: get_references(bloq_cls) for bloq_cls in bloq_classes}
52+
for bloq_cls, refs in references.items():
53+
for ref in refs:
54+
if isinstance(ref, UnparsedReference):
55+
raise AssertionError(
56+
f"{bloq_cls.__module__}.{bloq_cls.__qualname__} has an incorrectly "
57+
f"formatted reference:\n{ref.text}"
58+
)

qualtran/_infra/bloq.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,14 @@ def wire_symbol(
573573

574574
def __str__(self):
575575
return self.__class__.__name__
576+
577+
@classmethod
578+
def _class_name_in_pkg_(cls) -> str:
579+
"""The bloq class's name with its package.
580+
581+
The Qualtran standard library contains a heirarchy of packages under
582+
`qualtran.bloqs.*`. Each bloq class is defined in a module (i.e. the
583+
"*.py" file) and re-exported one level up.
584+
"""
585+
pkg = '.'.join(cls.__module__.split('.')[:-1])
586+
return f'{pkg}.{cls.__name__}'

qualtran/_infra/gate_with_registers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
319319

320320
return _wire_symbol_from_gate(self, self.signature, reg, idx)
321321

322-
# Part-2: Cirq-FT style interface can be used to implemented algorithms by Bloq authors.
322+
# Part-2: Cirq-FT style interface can be used to implement algorithms by Bloq authors.
323323

324324
def _num_qubits_(self) -> int:
325325
return total_bits(self.signature)

qualtran/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.6.0.dev0"
15+
__version__ = "0.7.0.dev0"

qualtran/bloqs/arithmetic/comparison.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
},
469469
"source": [
470470
"## `BiQubitsMixer`\n",
471-
"Implements the COMPARE2 subroutine from the reference (Fig. 1)\n",
471+
"Implements the COMPARE2 subroutine from the reference.\n",
472472
"\n",
473473
"This gates mixes the values in a way that preserves the result of comparison.\n",
474474
"The signature being compared are 2-qubit signature where\n",
@@ -485,7 +485,7 @@
485485
"https://github.com/quantumlib/Qualtran/issues/389\n",
486486
"\n",
487487
"#### References\n",
488-
" - [Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf).\n"
488+
" - [Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460). Berry et al. 2017. Appendix B. Fig 3.\n"
489489
]
490490
},
491491
{
@@ -582,7 +582,7 @@
582582
"Applies U|a>|b>|0>|0> = |a> |a=b> |(a<b)> |(a>b)>\n",
583583
"\n",
584584
"#### References\n",
585-
" - Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians. Figure 3. https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf\n"
585+
" - [Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460). Berry et al. 2017. Appendix B. Fig 5.\n"
586586
]
587587
},
588588
{
@@ -702,7 +702,7 @@
702702
"\n",
703703
"#### References\n",
704704
" - [Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity](https://arxiv.org/abs/1805.03662). \n",
705-
" - [Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf).\n"
705+
" - [Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460). Berry et al. 2017. Appendix B.\n"
706706
]
707707
},
708708
{

qualtran/bloqs/arithmetic/comparison.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _lt_k_symb() -> LessThanConstant:
218218

219219
@frozen
220220
class BiQubitsMixer(GateWithRegisters):
221-
"""Implements the COMPARE2 subroutine from the reference (Fig. 1)
221+
"""Implements the COMPARE2 subroutine from the reference.
222222
223223
This gates mixes the values in a way that preserves the result of comparison.
224224
The signature being compared are 2-qubit signature where
@@ -235,7 +235,8 @@ class BiQubitsMixer(GateWithRegisters):
235235
https://github.com/quantumlib/Qualtran/issues/389
236236
237237
References:
238-
[Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf).
238+
[Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460).
239+
Berry et al. 2017. Appendix B. Fig 3.
239240
"""
240241

241242
is_adjoint: bool = False
@@ -323,9 +324,8 @@ class SingleQubitCompare(GateWithRegisters):
323324
"""Applies U|a>|b>|0>|0> = |a> |a=b> |(a<b)> |(a>b)>
324325
325326
References:
326-
Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians.
327-
Figure 3.
328-
https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf
327+
[Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460).
328+
Berry et al. 2017. Appendix B. Fig 5.
329329
"""
330330

331331
is_adjoint: bool = False
@@ -433,7 +433,8 @@ class LessThanEqual(GateWithRegisters, cirq.ArithmeticGate): # type: ignore[mis
433433
References:
434434
[Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity](https://arxiv.org/abs/1805.03662).
435435
436-
[Supplementary Materials: Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf).
436+
[Improved Techniques for Preparing Eigenstates of Fermionic Hamiltonians](https://arxiv.org/abs/1711.10460).
437+
Berry et al. 2017. Appendix B.
437438
"""
438439

439440
x_bitsize: 'SymbolicInt'

qualtran/bloqs/basic_gates/global_phase_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_unitary():
2929
for alpha in random_state.random(size=10):
3030
coefficient = np.exp(2j * np.pi * alpha)
3131
bloq = GlobalPhase(exponent=2 * alpha)
32-
np.testing.assert_allclose(cirq.unitary(bloq), coefficient)
32+
np.testing.assert_allclose(bloq.tensor_contract(), coefficient)
3333

3434

3535
@pytest.mark.parametrize("cv", [0, 1])

0 commit comments

Comments
 (0)