Skip to content

Commit

Permalink
Fix charmap encoding issue with Windows installations
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrvz committed Oct 25, 2023
1 parent e740465 commit 9b5d978
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion customhys/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion customhys/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions customhys/hyperheuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion customhys/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions customhys/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -34,5 +35,6 @@
"tensorflow-metal>=0.7.1; sys_platform == 'darwin'",
]
},
include_package_data=True
include_package_data=True,

)

0 comments on commit 9b5d978

Please sign in to comment.