Skip to content

Commit

Permalink
Fix reprs to avoid data arrays being printed in the output.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmalone committed Oct 9, 2023
1 parent a4558cb commit f09aada
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qualtran/bloqs/chemistry/thc.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ def signature(self) -> Signature:
]
)

def __repr__(self) -> str:
return (
f"PrepareTHC(num_mu={self.num_mu}, num_spin_orb={self.num_spin_orb},"
"keep_bitsize={self.keep_bitsize})"
)

@classmethod
def build(cls, t_l, zeta, probability_epsilon=1e-8) -> 'PrepareTHC':
"""Factory method to build PrepareTHC from Hamiltonian coefficients."""
Expand Down
15 changes: 15 additions & 0 deletions qualtran/bloqs/chemistry/thc_notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
mcp_cv0 = ssa.new_symbol('cv3')


def custom_qroam_repr(self) -> str:
target_repr = repr(self._target_bitsizes)
return f"cirq_ft.SelectSwapQROM(target_bitsizes={target_repr}, block_size={self.block_size})"


def custom_qrom_repr(self) -> str:
target_repr = repr(self.target_bitsizes)
selection_repr = repr(self.selection_bitsizes)
return f"cirq_ft.QROM(selection_bitsizes={selection_repr}, target_bitsizes={target_repr})"


def generalize(bloq):
"""Genereralizer for THC prepare bloqs."""
if isinstance(bloq, (Allocate, Free, Split, Join)):
Expand All @@ -75,6 +86,10 @@ def generalize(bloq):
(bloq.gate**-1).target_bitsize,
(bloq.gate**-1).n_target_registers,
)
if isinstance(bloq.gate, cirq_ft.algos.SelectSwapQROM):
bloq.gate.__class__.__repr__ = custom_qroam_repr
if isinstance(bloq.gate, cirq_ft.algos.QROM):
bloq.gate.__class__.__repr__ = custom_qrom_repr
if isinstance(bloq.gate, single_qubit_clifford):
return ArbitraryClifford(n=1)
if isinstance(bloq.gate, two_qubit_clifford):
Expand Down

0 comments on commit f09aada

Please sign in to comment.