Skip to content

sb_poly defined in QuantumFloat class is used in SBP_arithmetic.py #522

@purva-thakre

Description

@purva-thakre

def sb_poly(self, m=0):
"""
Returns the semi-boolean polynomial of this `QuantumFloat` where `m` specifies
the image extension parameter.
For the technical details we refer to:
https://ieeexplore.ieee.org/document/9815035
Parameters
----------
m : int, optional
Image extension parameter. The default is 0.
Returns
-------
Sympy expression
The semi-boolean polynomial of this QuantumFloat.
Examples
--------
>>> from qrisp import QuantumFloat
>>> x = QuantumFloat(3, -1, signed = True, name = "x")
>>> print(x.sb_poly(5))
0.5*x_0 + 1.0*x_1 + 2.0*x_2 + 28.0*x_3
"""
if m == 0:
m = self.size
symbols = [sp.symbols(str(hash(self)) + "_" + str(i)) for i in range(self.size)]
poly = sum([2.0 ** (i) * symbols[i] for i in range(self.size)])
if self.signed:
poly += (2.0 ** (m + 1) - 2.0 ** (self.size)) * symbols[-1]
return 2**self.exponent * poly

sb_poly is a method of the QuantumFloat class. This gets used by the following functions in SBP_arithmetic.py:

  • sbp_mult
  • sbp_add
  • sbp_sub
  • polynomial_encoder
  • U_g_inpl_adder
  • app_phase_polynomial

We want to remove sb_poly from QuantumFloat. Initially, I thought this method is not used anywhere i.e. it could easily be moved. I tried removing it which led to many related unit test failures. https://github.com/eclipse-qrisp/Qrisp/actions/runs/24179539565/job/70568755443#step:5:15508

FAILED tests/algorithms_tests/test_QMCI.py::test_QMCI - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/algorithms_tests/test_grovers_algorithm.py::test_grovers_algorithm - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_arithmetic_validation.py::TestArithmeticExecution::test_array_plus_array - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_arithmetic_validation.py::TestArithmeticExecution::test_array_minus_array - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_arithmetic_validation.py::TestArithmeticExecution::test_array_multiply_array - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[add] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[sub] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[mul] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[gt] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[ge] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[lt] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_element_wise_ops[le] - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/quantum_array/test_quantum_array.py::test_quantum_array_inject_add - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/test_injection.py::test_injection_uncomputation - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/test_injection.py::test_injection_superposition_uncompute - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/test_iteration_environment.py::test_iteration_env - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/test_uncomputation_example.py::test_uncomputation_example - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/core_tests/test_unitary_calculation.py::test_unitary_calculation - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/interface_tests/test_batched_backend.py::test_batched_backend - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/interface_tests/test_cirq_converter.py::test_grover_example - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/interface_tests/test_converter_qrisp_to_qml.py::test_grover - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/jax_tests/test_HHL_demo.py::test_HHL_demo - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/jax_tests/test_arithmetic_tools.py::test_min_max - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/jax_tests/test_arithmetic_tools.py::test_q_fractional - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/operators_tests/test_measurement_method.py::test_measurement_method - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/arithmetic_tests/test_comparisons.py::test_quantum_float_comparison - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/arithmetic_tests/test_comparisons.py::test_quantum_modulus_comparison - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/arithmetic_tests/test_inpl_matrix_multiplication_example.py::test_inpl_matrix_multiplication_example - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/arithmetic_tests/test_matrix_multiplication_example.py::test_matrix_multiplication_example - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/arithmetic_tests/test_quantum_arithmetic.py::test_quantum_arithmetic - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'
FAILED tests/primitives_tests/test_diagonal_hamiltonian_application.py::test_phase_polynomial_application - AttributeError: 'QuantumFloat' object has no attribute 'sb_poly'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions