From 9b5d978b926e9dad2d32750db31873c5dad3ce2d Mon Sep 17 00:00:00 2001 From: jcrvz Date: Wed, 25 Oct 2023 10:24:55 -0600 Subject: [PATCH] Fix charmap encoding issue with Windows installations --- customhys/__init__.py | 2 +- customhys/experiment.py | 2 +- customhys/hyperheuristic.py | 7 ++++--- customhys/operators.py | 2 +- customhys/tools.py | 4 ++-- requirements.txt | 1 + setup.py | 8 +++++--- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/customhys/__init__.py b/customhys/__init__.py index 9d78f4c..5fecda3 100644 --- a/customhys/__init__.py +++ b/customhys/__init__.py @@ -1,4 +1,4 @@ __all__ = ['benchmark_func', 'experiment', 'hyperheuristic', 'metaheuristic', 'operators', 'population', 'tools', 'visualisation'] # Under revision: 'characterisation', 'visualisation' -__version__ = "1.1.4" +__version__ = "1.1.5" diff --git a/customhys/experiment.py b/customhys/experiment.py index 603a342..86fdcb1 100644 --- a/customhys/experiment.py +++ b/customhys/experiment.py @@ -346,7 +346,7 @@ def create_task_list(function_list, dimension_list): os.makedirs(OUTPUT_FOLDER) if args.batch: - with open(args.exp_config) as configs: + with open(args.exp_config, encoding='utf-8') as configs: exp_filenames = configs.read() exp_filenames = [filename.strip() for filename in exp_filenames.splitlines()] else: diff --git a/customhys/hyperheuristic.py b/customhys/hyperheuristic.py index dd037dd..76d58d5 100644 --- a/customhys/hyperheuristic.py +++ b/customhys/hyperheuristic.py @@ -86,7 +86,7 @@ def __init__(self, heuristic_space='default.txt', problem=None, parameters=None, self.heuristic_space = heuristic_space elif isinstance(heuristic_space, str): self.heuristic_space_label = heuristic_space[:heuristic_space.rfind('.')].split('_')[0] - with open('collections/' + heuristic_space, 'r') as operators_file: + with open('collections/' + heuristic_space, 'r', encoding='utf-8') as operators_file: self.heuristic_space = [eval(line.rstrip('\n')) for line in operators_file] else: raise HyperheuristicError('Invalid heuristic_space') @@ -1167,7 +1167,8 @@ def _save_step(step_number, variable_to_save, prefix=''): _create_path(folder_name) # Create a new file for this step - with open(folder_name + f'/{str(step_number)}-' + now.strftime('%m_%d_%Y_%H_%M_%S') + '.json', 'w') as json_file: + with open(folder_name + f'/{str(step_number)}-' + now.strftime('%m_%d_%Y_%H_%M_%S') + '.json', 'w', + encoding='utf-8') as json_file: json.dump(variable_to_save, json_file, cls=jt.NumpyEncoder) @@ -1238,7 +1239,7 @@ def _save_sequences(file_name, sequences_to_save): _create_path(folder_name) # Overwrite or create file to store the sequences along its respective fitness - with open(folder_name + f'{file_name}.json', 'w') as json_file: + with open(folder_name + f'{file_name}.json', 'w', encoding='utf-8') as json_file: json.dump(sequences_to_save, json_file, cls=jt.NumpyEncoder) diff --git a/customhys/operators.py b/customhys/operators.py index 716a4ec..62a51b3 100644 --- a/customhys/operators.py +++ b/customhys/operators.py @@ -986,7 +986,7 @@ def build_operators(heuristics=obtain_operators(), file_name='operators_collecti # Initialise the collection of simple heuristics if file_name[-4:] == '.txt': file_name = file_name[:-4] - file = open('collections/' + file_name + '.txt', 'w') + file = open('collections/' + file_name + '.txt', 'w', encoding='utf-8') # For each simple heuristic, read their parameters and values for operator, parameters, selectors in heuristics: diff --git a/customhys/tools.py b/customhys/tools.py index 1b6d1dc..98590e9 100644 --- a/customhys/tools.py +++ b/customhys/tools.py @@ -396,7 +396,7 @@ def save_json(variable_to_save, file_name=None, suffix=None): suffix = '_' + suffix if suffix else '' # Create the new file - with open('./{}{}.json'.format(file_name, suffix), 'w') as json_file: + with open('./{}{}.json'.format(file_name, suffix), 'w', encoding='utf-8') as json_file: json.dump(variable_to_save, json_file, cls=NumpyEncoder) @@ -407,7 +407,7 @@ def read_json(data_file): Filename of the json file. :return: dict or list. """ - with open(data_file, 'r') as json_file: + with open(data_file, 'r', encoding='utf-8') as json_file: data = json.load(json_file) # Return only the data variable diff --git a/requirements.txt b/requirements.txt index f33f25d..33689dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ matplotlib>=3.2.2 tqdm>=4.47.0 scikit-learn>=1.2.2 pandas>=1.5.3 +latex>=0.7.0 tensorflow>=2.8.0; sys_platform != 'darwin' tensorflow-macos>=2.11.0; sys_platform == 'darwin' tensorflow-metal>=0.7.1; sys_platform == 'darwin' diff --git a/setup.py b/setup.py index 7fa1696..d488393 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,13 @@ +# -*- coding: utf-8 -*- import setuptools import pathlib # The text of the README file -README = (pathlib.Path(__file__).parent / 'README.md').read_text() +README = (pathlib.Path(__file__).parent / 'README.md').read_text(encoding='utf-8') setuptools.setup( name='customhys', - version='1.1.4', + version='1.1.5', packages=setuptools.find_packages(), url='https://github.com/jcrvz/customhys', license='MIT License', @@ -34,5 +35,6 @@ "tensorflow-metal>=0.7.1; sys_platform == 'darwin'", ] }, - include_package_data=True + include_package_data=True, + )