Project

General

Profile

Bug #15453

Ruby 2.5 on Darwin appears to return different result

Added by akanet (Vincent Woo) over 1 year ago. Updated over 1 year ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:90675]

Description

Hi everyone,

I'm not sure if this is the right place to report, but I hit a shocking result recently. I was developing on my OSX machine on ruby 2.5.1 and also on a linux x64 machine and noticed I was getting different results for a totally deterministic ruby script (attached).

On Darwin:

Vincents-MBP:~ vwoo$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
Vincents-MBP:~ vwoo$ ruby test.rb
.=.|=.|.|=.|=|=.
.|=|=|||..|.=...
.==|....||=..|==
=.|....|.==.|==.
=|..==...=.|==..
=||.=.=||=|=..|=
|.=.===|||..=..|
|..==||=.|==|===
.=..===..=|.|||.
.======|||=|=.|=
.===|=|===.===||
=|||...|==..|=.|
=.=|=.=..=.||==|
||=|=...|==.=|==
|=.=||===.|||===
||.|==.|.|.||=||
1445
[[10, 10, :torch], 49, 0]

On Linux:

vwoo@ubuntu:~$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
vwoo@ubuntu:~$ ruby test.rb
.=.|=.|.|=.|=|=.
.|=|=|||..|.=...
.==|....||=..|==
=.|....|.==.|==.
=|..==...=.|==..
=||.=.=||=|=..|=
|.=.===|||..=..|
|..==||=.|==|===
.=..===..=|.|||.
.======|||=|=.|=
.===|=|===.===||
=|||...|==..|=.|
=.=|=.=..=.||==|
||=|=...|==.=|==
|=.=||===.|||===
||.|==.|.|.||=||
1032
[[10, 10, :torch], 45, 0]

I believe the Linux result to be correct (and I have validated it against other Linux machines). This appears to happen on 2.5.3 as well. I built Darwin ruby with ruby-install and Apple clang 10. Any help debugging would be very appreciated!


Files

test.rb (1.97 KB) test.rb akanet (Vincent Woo), 12/23/2018 12:38 AM

Updated by mame (Yusuke Endoh) over 1 year ago

  • Status changed from Open to Rejected

Your program is actually not deterministic. The result of Array#sort_by! may differ depending upon the platform. See the rdoc:

  *  The result is not guaranteed to be stable.  When the comparison of two
  *  elements returns +0+, the order of the elements is unpredictable.

A* is of course robust against the tie breaking. The reason why your program does not work correctly, is just because your program is buggy. Read the textbook carefully.

You can reproduce the bug on Linux by replacing the line of sort_by! with:

queue.sort_by! { |p, cost, estimate| [cost + estimate, rand()] }

Good luck.

Updated by aycabta (aycabta .) over 1 year ago

Nice try to resolve your problem with Ruby. I think that this issue fits ruby-talk mailing list.
https://www.ruby-lang.org/en/community/mailing-lists/

Best of luck on your venture. Thank you.

Updated by akanet (Vincent Woo) over 1 year ago

Ah, thank you very much for the explanation Yusuke. I should have examined the documentation more closely.

Also available in: Atom PDF