public release 4.2.0 - see README.md and CHANGES.md for details

This commit is contained in:
2026-01-08 19:10:45 +01:00
parent ef781e2db4
commit b64beb694c
181 changed files with 39388 additions and 6527 deletions

View File

@@ -21,18 +21,14 @@ Licensed under the Apache License, Version 2.0 (the "License"); @n
http://www.apache.org/licenses/LICENSE-2.0
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import datetime
import logging
import math
import numpy as np
from pathlib import Path
import os
import time
from pmsco.compat import open
import pmsco.handlers as handlers
import pmsco.graphics.rfactor as grfactor
from pmsco.helpers import BraceMessage as BMsg
@@ -761,7 +757,9 @@ class Population(object):
self.pos_import = np.delete(self.pos_import, range(first, last))
self.size_act = last - first
self.update_particle_info()
return last - first
else:
self.size_act = 0
return self.size_act
def update_particle_info(self, index=None, inc_model=True):
"""
@@ -1083,9 +1081,9 @@ class Population(object):
the file name extensions are .pos, .vel, and .best
"""
self.save_array(base_filename + ".pos", self.pos)
self.save_array(base_filename + ".vel", self.vel)
self.save_array(base_filename + ".best", self.best)
self.save_array(Path(base_filename).with_suffix(".pos"), self.pos)
self.save_array(Path(base_filename).with_suffix(".vel"), self.vel)
self.save_array(Path(base_filename).with_suffix(".best"), self.best)
def load_population(self, base_filename):
"""
@@ -1096,9 +1094,9 @@ class Population(object):
the files must have the same format as produced by save_population.
the files must have the same number of rows.
"""
self.pos = self.load_array(base_filename + ".pos", self.pos)
self.vel = self.load_array(base_filename + ".vel", self.vel)
self.best = self.load_array(base_filename + ".best", self.best)
self.pos = self.load_array(Path(base_filename).with_suffix(".pos"), self.pos)
self.vel = self.load_array(Path(base_filename).with_suffix(".vel"), self.vel)
self.best = self.load_array(Path(base_filename).with_suffix(".best"), self.best)
self.size_act = self.pos.shape[0]
def save_results(self, filename):
@@ -1107,6 +1105,9 @@ class Population(object):
"""
self.save_array(filename, self.results)
def render_population(self, base_filename):
pass
class PopulationHandler(handlers.ModelHandler):
"""
@@ -1167,6 +1168,8 @@ class PopulationHandler(handlers.ModelHandler):
self._invalid_limit = 10
self.patch_file = "pmsco_patch.pop"
self._patch_last_mtime = 0
self._diag_path = None
self._results_path = None
def setup(self, project, slots):
"""
@@ -1200,8 +1203,13 @@ class PopulationHandler(handlers.ModelHandler):
self._pop_size = _req_size if _req_size >= _min_size else _def_size
self.setup_population()
self._invalid_limit = self._pop_size * 10
of = Path(self._project.output_file)
dp = of.parent / "diag"
dp.mkdir(exist_ok=True)
self._diag_path = dp / of.name
self._results_path = of.with_suffix(".dat")
with open(self._project.output_file + ".dat", "w") as outfile:
with open(self._results_path, "wt", encoding="latin1") as outfile:
outfile.write("# ")
outfile.write(" ".join(self._pop.results.dtype.names))
outfile.write("\n")
@@ -1256,7 +1264,7 @@ class PopulationHandler(handlers.ModelHandler):
self._check_patch_file()
self._pop.advance_population()
for pos in self._pop.pos_gen():
for pos, vel in zip(self._pop.pos_gen(), self._pop.vel_gen()):
time_pending += self._model_time
if time_pending > time_avail:
self._timeout = True
@@ -1268,6 +1276,7 @@ class PopulationHandler(handlers.ModelHandler):
new_task = parent_task.copy()
new_task.parent_id = parent_id
new_task.model = pos
new_task.delta = vel
new_task.change_id(model=pos['_model'])
new_tasks.append(new_task)
@@ -1322,9 +1331,8 @@ class PopulationHandler(handlers.ModelHandler):
assert not math.isnan(task.rfac)
task.model['_rfac'] = task.rfac
self._pop.add_result(task.model, task.rfac)
self._pop.save_population(self._project.output_file + ".pop")
with open(self._project.output_file + ".dat", "a") as outfile:
with open(self._results_path, "at", encoding="latin1") as outfile:
s = (str(task.model[name]) for name in self._pop.results.dtype.names)
outfile.write(" ".join(s))
outfile.write("\n")
@@ -1364,6 +1372,6 @@ class PopulationHandler(handlers.ModelHandler):
"""
super(PopulationHandler, self).save_report(root_task)
files = grfactor.render_results(self._project.output_file + ".dat", self._pop.results)
files = grfactor.render_results(Path(self._project.output_file).with_suffix(".dat"), self._pop.results)
for f in files:
self._project.files.add_file(f, root_task.id.model, "report")