quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
132 stars 35 forks source link

BugFix in `SelectSwapQROM` when multiple datasets are specified #1049

Closed tanujkhattar closed 1 month ago

tanujkhattar commented 1 month ago

Two bugfixes:

  1. Use self.use_dirty_ancilla in _value_equality_values_ -- This is important to make sure bloq.t_complexity() returns different values when bloq is initialized with use_dirty_ancilla=True vs use_dirty_ancilla=False. Right now, they can return the same value because the t-complexity is cached
  2. qrom_batched_target[0] can return a numpy array because the target shapes can be multi-dimensional. This is especially true when input data is multi-dimensional (i.e. data[N][M] --> bached_qrom_data[N / k1][M / k2]). We need the target_0_0_..._0'th register and not the target_0th register; which can be multidimensional.

The added tests fail on main but pass with this PR.

fdmalone commented 1 month ago

We need the target_0_0_..._0'th register and not the target_0th register; which can be multidimensional.

I was a little confused by the underscores here given our weird target register convention, you just mean you want the actual zero'th target register not the zero'th row (in the 2D example)

tanujkhattar commented 1 month ago

I was a little confused by the underscores here given our weird target register convention, you just mean you want the actual zero'th target register not the zero'th row (in the 2D example)

Yup

mpharrigan commented 1 month ago

Why are we using value_equality_values at all?

tanujkhattar commented 1 month ago

Why are we using value_equality_values at all?

We store tuples of numpy arrays, which don't support value equality by default.

fdmalone commented 1 month ago

In several of the chemistry bloqs I ended up using tuples of tuples etc which is horrendous, but maybe this is solved in attrs now: https://www.attrs.org/en/stable/comparison.html#customization?

tanujkhattar commented 1 month ago

@fdmalone @mpharrigan Removed the use of _value_equality_values_ with the fancy attrs functionality Fionn mentioned above. This is ready to go now.