-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Labels
contributors welcomeHelp with this would be appreciatedHelp with this would be appreciateddrawingunitaryhackCandidates for unitaryHACK 2025Candidates for unitaryHACK 2025
Milestone
Description
When plotting musical score diagrams for QvrZPow with a symbolic rotation angle sympy.Symbol('Y'), I want the output to have nicely formatted rotation angles instead of very small floating point values. For example:
When running the code
qvr_zpow = QvrZPow(Register('x', QFxp(12, 6, False)), gamma = sympy.Symbol('Y'))
show_bloq(qvr_zpow, 'dtype')
show_bloq(qvr_zpow.decompose_bloq(), 'musical_score')I want the output to be like
instead of (current main)
or what you get if you update the pretty name of ZPowGate bloq to return f'Z^{self.exponent}'
To generate the original diagram, I implemented a very hacky format function locally as follows:
def format(x: SymbolicFloat) -> str:
if isinstance(x, float) or x.is_constant():
if x.is_integer:
return f'{int(x)}'
for i in range(1, 20):
if x * (2**i) == 1:
return f'/2^{i}'
return f'{x:.2g}'
if isinstance(x, sympy.Symbol):
return str(x)
if isinstance(x, sympy.Expr):
return '*'.join(format(x) for x in x.args[::-1])
return str(x)The goal of this issue would be to add a similar production quality format function that can be used to get nice string representations of exponents represented as a SymbolicFloat
cc #791
Metadata
Metadata
Assignees
Labels
contributors welcomeHelp with this would be appreciatedHelp with this would be appreciateddrawingunitaryhackCandidates for unitaryHACK 2025Candidates for unitaryHACK 2025