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

DoubleFactorized block encoding fails when sf_error_threshold is zero #21

Open
max-radin opened this issue Aug 27, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@max-radin
Copy link

max-radin commented Aug 27, 2024

I'm seeing the error below when initializing DoubleFactorized objects with sf_error_threshold set to zero. (Context: I'm setting this to zero to make the truncation consistent with OpenFermion's logic for estimating truncation error.) It looks like the issue is just that num_ops does not get initialized if none of the eigenvalues are thrown out.

I think this is not a big blocker for our work though because it seems like we can work around it by just setting sf_error_threshold to some very small value.

Traceback (most recent call last):
  File "/Users/maxradin/Development/qb-gsee-benchmark/examples/get_qre.py", line 14, in <module>
    circuit, n_shots, allowable_error = get_df_qpe_circuit(
                                        ^^^^^^^^^^^^^^^^^^^
  File "/Users/maxradin/Development/qb-gsee-benchmark/src/qb_gsee_benchmark/qre.py", line 250, in get_df_qpe_circuit
    encoding = DoubleFactorized(
               ^^^^^^^^^^^^^^^^^
  File "/Users/maxradin/anaconda3/lib/python3.11/site-packages/pyLIQTR/BlockEncodings/DoubleFactorized.py", line 67, in __init__
    one_body_array, two_body_array, self.Xi_l_data, self.givens_angle_tensor = self.PI.yield_DF_Info(df_error_threshold=df_error_threshold,sf_error_threshold=sf_error_threshold)
                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxradin/anaconda3/lib/python3.11/site-packages/pyLIQTR/ProblemInstances/ChemicalHamiltonian.py", line 193, in yield_DF_Info
    DF_frags = self.DF_fragments(sf_error_threshold)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxradin/anaconda3/lib/python3.11/site-packages/pyLIQTR/ProblemInstances/ChemicalHamiltonian.py", line 130, in DF_fragments
    return DF_decomposition(h0, one_body_tensor, two_body_tensor,tol=sf_error_threshold)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxradin/anaconda3/lib/python3.11/site-packages/pyLIQTR/utils/df_utils.py", line 238, in DF_decomposition
    vals = all_vals[:num_ops]
                     ^^^^^^^
UnboundLocalError: cannot access local variable 'num_ops' where it is not associated with a value
@max-radin max-radin changed the title DoubleFactorized block encoding fails when sf_error_threshold is zero. DoubleFactorized block encoding fails when sf_error_threshold is zero Aug 27, 2024
@kjm538
Copy link
Collaborator

kjm538 commented Aug 27, 2024

It looks like the issue is just that num_ops does not get initialized if none of the eigenvalues are thrown out.

Looks like you're right. I'll push the fix with the next release, thanks for pointing it out.

@kjm538 kjm538 added the bug Something isn't working label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants