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

sparse state prep: allow user to pick target bitsize if needed #1430

Merged
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SparseStatePreparationViaRotations(Bloq):
nonzero_coeffs: Union[tuple[complex, ...], HasLength] = field(converter=_to_tuple_or_has_length)
N: SymbolicInt
phase_bitsize: SymbolicInt
target_bitsize: SymbolicInt = field()
anurudhp marked this conversation as resolved.
Show resolved Hide resolved

def __attrs_post_init__(self):
n_idx = slen(self.sparse_indices)
Expand All @@ -71,8 +72,8 @@ def signature(self) -> Signature:
target_state=QUInt(self.target_bitsize), phase_gradient=QAny(self.phase_bitsize)
)

@property
def target_bitsize(self) -> SymbolicInt:
@target_bitsize.default
def _default_target_bitsize(self) -> SymbolicInt:
return bit_length(self.N - 1)

@property
Expand Down Expand Up @@ -160,6 +161,7 @@ def _dense_stateprep_bloq(self) -> StatePreparationViaRotations:
dense_coeffs_padded = np.pad(
list(self.nonzero_coeffs), (0, 2**self.dense_bitsize - len(self.nonzero_coeffs))
)
dense_coeffs_padded = dense_coeffs_padded / np.linalg.norm(dense_coeffs_padded)
return StatePreparationViaRotations(tuple(dense_coeffs_padded.tolist()), self.phase_bitsize)

@property
Expand Down
Loading