Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions autofit/non_linear/abstract.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import configparser
from abc import ABC, abstractmethod
import logging
import pickle
import numpy as np
import multiprocessing as mp
import pickle
from abc import ABC, abstractmethod
from time import sleep
from typing import Dict
from copy import copy

import numpy as np

from autoconf import conf
from autofit.mapper import model_mapper as mm
from autofit.non_linear.paths import Paths, convert_paths
from autofit.text import formatter
from autofit.text import samples_text
from autofit.text import model_text
from autofit.text import samples_text

logging.basicConfig()
logger = logging.getLogger(__name__) # TODO: Logging issue
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(
paths.non_linear_name = self.config("tag", "name", str)

if paths.non_linear_tag is "":
paths.non_linear_tag = self.tag
paths.non_linear_tag_function = lambda: self.tag

log_file = conf.instance.general.get("output", "log_file", str).replace(" ", "")
self.paths = paths
Expand Down Expand Up @@ -452,7 +452,7 @@ def initial_points_from_model(self, number_of_points, model):
An object that represents possible instances of some model with a given dimensionality which is the number
of free dimensions of the model.
"""

init_pos = np.zeros(shape=(number_of_points, model.prior_count))

if self.initialize_method in "ball":
Expand Down Expand Up @@ -514,7 +514,6 @@ def make_pool(self):
class Analysis:

def __init__(self, log_likelihood_cap=None):

self.log_likelihood_cap = log_likelihood_cap

def log_likelihood_function(self, instance):
Expand Down Expand Up @@ -630,8 +629,9 @@ def init(queue):
global idx
idx = queue.get()


def f(x):
global idx
process = mp.current_process()
sleep(1)
return (idx, process.pid, x * x)
return (idx, process.pid, x * x)
33 changes: 28 additions & 5 deletions autofit/non_linear/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ def wrapper(self, *args, **kwargs):

non_linear_instance = kwargs["non_linear_class"]()
non_linear_name = non_linear_instance.config("tag", "name", str)
non_linear_tag = non_linear_instance.tag

def non_linear_tag_function():
return non_linear_instance.tag

else:

non_linear_name = None
non_linear_tag = None

def non_linear_tag_function():
return ""

func(
self,
Expand All @@ -67,7 +71,7 @@ def wrapper(self, *args, **kwargs):
folders=kwargs.pop("phase_folders", tuple()),
path_prefix=kwargs.pop("phase_path", None),
non_linear_name=non_linear_name,
non_linear_tag=non_linear_tag,
non_linear_tag_function=non_linear_tag_function,
remove_files=remove_files,
),
**kwargs,
Expand All @@ -84,7 +88,7 @@ def __init__(
folders=tuple(),
path_prefix=None,
non_linear_name=None,
non_linear_tag=None,
non_linear_tag_function=lambda: "",
remove_files=False,
):
"""Manages the path structure for non-linear search output, for analyses both not using and using the phase
Expand Down Expand Up @@ -134,9 +138,27 @@ def __init__(
self.name = name or ""
self.tag = tag or ""
self.non_linear_name = non_linear_name or ""
self.non_linear_tag = non_linear_tag or ""
self.non_linear_tag_function = non_linear_tag_function
self.remove_files = remove_files

def __getstate__(self):
state = self.__dict__.copy()
state["non_linear_tag"] = state.pop("non_linear_tag_function")()
return state

def __setstate__(self, state):
non_linear_tag = state.pop(
"non_linear_tag"
)
self.non_linear_tag_function = lambda: non_linear_tag
self.__dict__.update(
state
)

@property
def non_linear_tag(self):
return self.non_linear_tag_function()

@property
def path(self):
return link.make_linked_folder(self.sym_path)
Expand Down Expand Up @@ -212,6 +234,7 @@ def name_folder(self):
return "/".join((conf.instance.output_path, self.path_prefix, self.name))

@property
@make_path
def sym_path(self) -> str:
return "{}/{}/{}/{}/{}/samples".format(
conf.instance.output_path, self.path_prefix, self.name, self.tag, self.non_linear_tag
Expand Down
10 changes: 9 additions & 1 deletion test_autofit/unit/tools/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
directory = path.dirname(path.realpath(__file__))


def test_dynamic(phase):
paths = phase.paths
non_linear_tag = paths.non_linear_tag

phase.search.nwalkers += 1

assert paths.non_linear_tag != non_linear_tag


class PatchPaths(af.Paths):
@property
def path(self):
Expand All @@ -34,7 +43,6 @@ def make_paths():


def test_backup_zip_remove(paths):

os.mkdir(paths.sym_path)
os.mkdir(paths.path)

Expand Down