Comments (6)
Well, that is irritating. Python 3 looks worse and worse...
Adam and I confirmed that numpy is reproducible across python 2.7 and 3.5, e.g.
Python 2.7.12 |Anaconda 2.0.1 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> np.random.seed(2)
>>> np.random.randint(100, size=20)
array([40, 15, 72, 22, 43, 82, 75, 7, 34, 49, 95, 75, 85, 47, 63, 31, 90,
20, 37, 39])
(py3) ~ $ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.random.seed(2)
>>> np.random.randint(100, size=20)
array([40, 15, 72, 22, 43, 82, 75, 7, 34, 49, 95, 75, 85, 47, 63, 31, 90,
20, 37, 39])
Another bizarre thing with the python system library random: on my laptop, the sequence I get from ipython is one element offset from the sequence I get from vanilla python:
~ $ python
Python 2.7.12 |Anaconda 2.0.1 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import random; random.seed(2); random.sample(range(100), 20)
[95, 94, 5, 8, 83, 73, 66, 30, 60, 58, 15, 43, 39, 72, 99, 54, 44, 26, 3, 2]
~ $ ipython
Python 2.7.12 |Anaconda 2.0.1 (x86_64)| (default, Jul 2 2016, 17:43:17)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import random
In [2]: random.seed(2)
In [3]: random.sample(range(100),20)
Out[3]: [94, 5, 8, 83, 73, 66, 30, 60, 58, 15, 43, 39, 72, 99, 54, 44, 26, 3, 2, 46]
and to continue the bizarreness, I get the python sequence from ipython if I chain the commands together in a single line:
~ $ ipython
Python 2.7.12 |Anaconda 2.0.1 (x86_64)| (default, Jul 2 2016, 17:43:17)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import random; random.seed(2); random.sample(range(100), 20)
...:
Out[1]: [95, 94, 5, 8, 83, 73, 66, 30, 60, 58, 15, 43, 39, 72, 99, 54, 44, 26, 3, 2]
Guidelines:
- don't use the python system library random
- use numpy.random instead
- this is crazy
from desimodel.
wrong button; reopening until we've confirmed that we are using numpy.random throughout.
from desimodel.
Further weirdness. The fundamental function of the random
module is random.random()
; almost all the other functions depend on it. In Python 2 & 3, it does appear to be consistent.
Python 2:
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import random
>>> random.seed(2)
>>> random.random()
0.9560342718892494
>>> random.random()
0.9478274870593494
>>> random.random()
0.05655136772680869
>>> random.random()
0.08487199515892163
Python 3:
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.seed(2)
>>> random.random()
0.9560342718892494
>>> random.random()
0.9478274870593494
>>> random.random()
0.05655136772680869
>>> random.random()
0.08487199515892163
So maybe for random.sample()
the way the list members are hashed is what matters? Or maybe changes in how range()
works? I still agree with your guidelines though!
from desimodel.
The random.sample()
algorithm requires a random integer in the range [0,n). Python 2 & 3 have different mechanisms for obtaining that random integer, and it looks like the different mechanisms call random.random()
a different number of times.
from desimodel.
Does anyone care about this issue? We're weeks away from dropping Python 2 entirely, so it doesn't seem relevant anymore.
from desimodel.
Agreed. Closing this ticket, while reiterating the guidelines:
- don't use the python system library random
- use numpy.random instead
- this is crazy
from desimodel.
Related Issues (20)
- update xy2radec and radec2xy to support airmass field compression terms
- Add focalplane model support for stuck / broken position
- Add support for CANbus failures in focalplane model HOT 1
- Use instrument database for generating focalplane model HOT 2
- update/deprecate fiberpos.fits HOT 6
- DESIMODEL SVN data? HOT 2
- Update platescale to as-built design from DESI-4037 HOT 2
- Mechanism for getting current "nominal" focalplane HOT 1
- Convert focalplane model times to UTC
- Update throughput model to include dip between 4300 and 4500A HOT 3
- Add information about fibers with low transmission
- Outdated desimodel test branches. HOT 1
- astropy 5 not compatible with focalplane calibration ecsv HOT 13
- desiInstall desimodel branches/main fails
- Remove fix-tiles branch? HOT 1
- update psf-quicksim HOT 3
- Update api.rst
- Problem with new version of numpy HOT 5
- io.load_tiles defaults to old tile list $DESIMODEL/data/footprint/desi-tiles.fits HOT 6
- Error with get_tile_radius_deg when loading platescale HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from desimodel.