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

updates not printed out #26

Open
DonGiulio opened this issue Jan 15, 2019 · 4 comments
Open

updates not printed out #26

DonGiulio opened this issue Jan 15, 2019 · 4 comments

Comments

@DonGiulio
Copy link

hello,
I'm trying out simanneal, and found something that I don't understand:

here's my code:

oa = OptimizerAnnealer(strategy, ranges, self.get_data())
configuration, points = oa.anneal()

where my annealer is:

def __init__(self, strategy, ranges, data):
    self.strategy = strategy
    self.ranges = ranges
    self.data = data

    # initial state with first value of each range
    self.state = {}
    for key, value in self.ranges.items():
        self.state[key] = value[0]

    super(OptimizerAnnealer, self).__init__(self.state)  # important!

def move(self):
    key = pick(list(self.state))
    new_value = following(list(self.ranges[key]), self.state[key])
    self.state[key] = new_value

def energy(self):
   # energy function calculates points related to current state, obtaining a `result` float
   # that depends on state. 
    return result

the output of simanneal is:

Temperature        Energy    Accept   Improve     Elapsed   Remaining
 25000.00000        616.99                         0:00:02

and that's it, it doesn't show any updates at all. even though there are new solutions that have lower energy level.

anything I'm doing wrong?

Thanks

@perrygeo
Copy link
Owner

perrygeo commented Jan 15, 2019

The frequency of printing is determined by the updates and steps properties. What does oa.steps and oa.updates give you?

@sanguinettib
Copy link

Somehow, the end="\r" in the print statement of the default update function seemed to prevent it from printing on my system (macOS mojave). Removing the end="\r' fixed the problem, at least for me.

@Iain-S
Copy link

Iain-S commented Jan 21, 2020

@Br1000
There is a known issue with PyCharm where it won't print properly with end='\r' but will print strings containing '\r' just fine.

@perrygeo
Commit 2e79630 added end='\r' but I don't think it is necessary since the string begins with '\r' anyway. Perhaps it could be changed to end='' to help out PyCharm users?

Also, the annealing process seems to be run twice (once by auto and then again, for real). This leads to output like:

Temperature Energy Accept Improve Elapsed Remaining
Temperature Energy Accept Improve Elapsed Remaining
7.30000 6801.84 5.60% 0.27% 0:00:11 0:00:00

If you were to change

    print(' Temperature        Energy    Accept   Improve     Elapsed   Remaining',
                      file=sys.stderr)

to

    print('\n Temperature        Energy    Accept   Improve     Elapsed   Remaining',
                  file=sys.stderr) 

then the output would be:

empty line
Temperature Energy Accept Improve Elapsed Remaining
4.90000 6801.84 4.60% 0.00% 0:00:03 -1:59:59
Temperature Energy Accept Improve Elapsed Remaining
4.90000 6845.62 6.81% 0.14% 0:00:09 0:00:00
which I think is a bit neater.

@perrygeo
Copy link
Owner

@Iain-S sounds like a good solution. Would you mind creating a PR for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants