Samila version added for reproducibility (#184)

* change : micro version is no longer saved.

* add : `__version__` attribute for Samila version. (#171)

* fix : minor mistake in CHANGELOG.md.

* update : `VERSION_WARNING` updated.
master
Sadra Sabouri 2023-03-31 17:37:17 +03:30 zatwierdzone przez GitHub
rodzic a994902006
commit 2a98624138
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 36 dodań i 21 usunięć

Wyświetl plik

@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `__version__` attribute
- `python_version` attribute
- `get_python_version` function
- `RANDOM_EQUATION_MIN_COMPLEXITY` parameter
- `RANDOM_EQUATION_FOF_MAX_DEPTH` parameter
- `RANDOM_EQUATION_FOF_MIN_DEPTH` parameter

Wyświetl plik

@ -12,6 +12,7 @@ import matplotlib
from matplotlib import cm
from matplotlib.colors import ListedColormap
from PIL import Image
from .params import SAMILA_VERSION
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
@ -472,6 +473,7 @@ def _GI_initializer(g, function1, function2):
:type function2: python or lambda function
:return: None
"""
g.__version__ = SAMILA_VERSION
g.matplotlib_version = matplotlib.__version__
g.python_version = get_python_version()
g.function1 = function1
@ -559,12 +561,11 @@ def get_python_version():
"""
Get Python's version.
:return: python's version as 'major.minor.micro'
:return: python's version as 'major.minor'
"""
return "{}.{}.{}".format(
return "{}.{}".format(
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro
sys.version_info.minor
)
@ -576,8 +577,6 @@ def get_data(g):
:type g: GenerativeImage
:return: data as a dict
"""
matplotlib_version = matplotlib.__version__
python_version = get_python_version()
data = {}
if g.data1 is None or g.data2 is None:
raise samilaDataError(SAVE_NO_DATA_ERROR)
@ -595,8 +594,9 @@ def get_data(g):
"depth": g.depth,
"rotation": g.rotation,
}
data['matplotlib_version'] = matplotlib_version
data['python_version'] = python_version
data['matplotlib_version'] = g.matplotlib_version
data['python_version'] = g.python_version
data['__version__'] = g.__version__
return data
@ -608,8 +608,6 @@ def get_config(g):
:type g: GenerativeImage
:return: config as a dict
"""
matplotlib_version = matplotlib.__version__
python_version = get_python_version()
config = {}
if g.function1_str is None or g.function2_str is None:
raise samilaConfigError(CONFIG_NO_STR_FUNCTION_ERROR)
@ -633,8 +631,9 @@ def get_config(g):
"depth": g.depth,
"rotation": g.rotation,
}
config['matplotlib_version'] = matplotlib_version
config['python_version'] = python_version
config['matplotlib_version'] = g.matplotlib_version
config['python_version'] = g.python_version
config['__version__'] = g.__version__
return config
@ -808,6 +807,8 @@ def load_data(g, data):
g.matplotlib_version = data['matplotlib_version']
if 'python_version' in data:
g.python_version = data['python_version']
if '__version__' in data:
g.__version__ = data['__version__']
plot_config = data.get("plot")
if plot_config is not None:
g.color = plot_config.get("color", DEFAULT_COLOR)
@ -844,6 +845,8 @@ def load_config(g, config):
g.matplotlib_version = config['matplotlib_version']
if 'python_version' in config:
g.python_version = config['python_version']
if '__version__' in config:
g.__version__ = config['__version__']
generate_config = config.get("generate")
if generate_config is not None:
g.seed = generate_config.get("seed")

Wyświetl plik

@ -45,11 +45,13 @@ class GenerativeImage:
elif data is not None:
load_data(self, data)
if self.matplotlib_version != matplotlib.__version__ or \
self.python_version != get_python_version():
self.python_version != get_python_version() or \
self.__version__ != SAMILA_VERSION:
warn(
VERSION_WARNING.format(
self.matplotlib_version,
self.python_version),
self.python_version,
self.__version__),
RuntimeWarning)
if self.function1 is None:
if self.function1_str is None:

Wyświetl plik

@ -48,7 +48,7 @@ PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use
COLOR_SIZE_ERROR = "Color list size is not equal to the data size."
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
INVALID_COLOR_TYPE_ERROR = "Given color/bgcolor type is not supported."
VERSION_WARNING = "Source matplotlib version({0}) or Python version({1}) is different from yours, plots may be different."
VERSION_WARNING = "Your plots may differ as the version of matplotlib ({0}), Python ({1}), or Samila ({2}) that you are using is not the same as the source."
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"

Wyświetl plik

@ -91,7 +91,7 @@ False
1
>>> distance_calc("test12","test234")
3
>>> get_python_version() == sys.version.split()[0]
>>> get_python_version() == '.'.join(sys.version.split()[0].split('.')[:2])
True
>>> samila_help()
<BLANKLINE>

Wyświetl plik

@ -24,7 +24,7 @@
True
>>> g.function2 == f2
True
>>> g.python_version == sys.version.split()[0]
>>> g.python_version == '.'.join(sys.version.split()[0].split('.')[:2])
True
>>> g.fig
>>> g.generate()

Wyświetl plik

@ -13,20 +13,28 @@ True
>>> g_.data2 == g.data2
True
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], '__version__': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', '__version__': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], 'python_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', 'python_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], 'matplotlib_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', 'matplotlib_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):