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

Consider adding Symbol.__str__() overload #133

Open
arcondello opened this issue Oct 7, 2024 · 1 comment
Open

Consider adding Symbol.__str__() overload #133

arcondello opened this issue Oct 7, 2024 · 1 comment
Labels
enhancement New feature or request question Further information is requested or further design needed

Comments

@arcondello
Copy link
Member

Currently we have Symbol.__repr__() implemented

In [1]: from dwave.optimization import Model

In [2]: model = Model()

In [3]: i = model.integer()

In [5]: repr(i)
Out[5]: '<dwave.optimization.symbols.IntegerVariable at 0x55ed9d929be0>'

However, we've had a few requests for something closer to dimod's CQM printing

In [6]: import dimod

In [7]: cqm = dimod.ConstrainedQuadraticModel()

In [8]: i = cqm.add_variable("INTEGER")

In [9]: j = cqm.add_variable("INTEGER")

In [17]: cqm.set_objective([(i, j, 1)])

In [18]: print(cqm)
Constrained quadratic model: 2 variables, 0 constraints, 3 biases

Objective
  Integer(1)*Integer(0)

Constraints

Bounds
  0.0 <= Integer(0) <= 9007199254740991.0
  0.0 <= Integer(1) <= 9007199254740991.0

Approaches Considered

I think don't want to print everything for every node, so maybe something like 1-nesting

Max(Sum(...), Constant(...))

or

Max(Sum, Constant)

or something like that.

We could also take inspiration from sympy which does print the whole thing

In [1]: from sympy import *

In [2]: x, y, z = symbols("x y z")

In [10]: out = x + y

In [11]: for _ in range(100):
    ...:     out = x*out + y
    ...: 

In [12]: out
Out[12]: x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x*(x + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) + y) 

Though how to handle say indexing gets a bit funny.

@arcondello
Copy link
Member Author

This obviously interacts with #17 as well.

@arcondello arcondello added enhancement New feature or request question Further information is requested or further design needed labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested or further design needed
Projects
None yet
Development

No branches or pull requests

1 participant