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

Some issues with printing a TComplexity that has symbolic parameters #1453

Open
wjhuggins opened this issue Oct 8, 2024 · 2 comments
Open
Labels
bug Something isn't working resource_counting
Milestone

Comments

@wjhuggins
Copy link
Collaborator

I get an error I don't understand when trying to print a TComplexity with symbolic parameters. Here is a minimal example:

from sympy import Symbol

import cirq

from qualtran.bloqs.mcmt import MultiControlPauli
from qualtran.symbolics import HasLength
from qualtran.cirq_interop.t_complexity_protocol import t_complexity

ccpauli_symb = MultiControlPauli(cvs=HasLength(Symbol("k", integer=True, positive=True)), target_gate=cirq.X)

print(t_complexity(ccpauli_symb))

Running this code produces the following error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-8e9cf3d259d8> in <cell line: 11>()
      9 ccpauli_symb = MultiControlPauli(cvs=HasLength(Symbol("k", integer=True, positive=True)), target_gate=cirq.X)
     10 
---> 11 print(t_complexity(ccpauli_symb))

1 frames
/usr/local/lib/python3.10/dist-packages/qualtran/cirq_interop/t_complexity_protocol.py in __str__(self)
     67     def __str__(self) -> str:
     68         return (
---> 69             f'T-count:   {self.t:g}\n'
     70             f'Rotations: {self.rotations:g}\n'
     71             f'Cliffords: {self.clifford:g}\n'

/usr/local/lib/python3.10/dist-packages/sympy/core/expr.py in __format__(self, format_spec)
    381                 if rounded.is_Float:
    382                     return format(rounded, format_spec)
--> 383         return super().__format__(format_spec)
    384 
    385     @staticmethod

TypeError: unsupported format string passed to Add.__format__
@tanujkhattar
Copy link
Collaborator

Yeah, that's because of the ":g" in the __str__ implementation, which assumes the fields to be floats / ints. Printing individual fields as sympy expressions should work fine -- print(t_complexity(ccpauli_symb).t)

This issue should be fixed though. I've also run into this in the past. Thanks for opening an issue!

@wjhuggins
Copy link
Collaborator Author

Sure. I've been using
.asdict() to make it print but I figured it was worth flagging.

@mpharrigan mpharrigan added bug Something isn't working resource_counting labels Oct 8, 2024
@mpharrigan mpharrigan added this to the v1.0 milestone Oct 10, 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 resource_counting
Projects
None yet
Development

No branches or pull requests

3 participants