-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: Unable to configure handler 'file_default' #526
Comments
I have this same issue, but in a different context. I believe the root issue is that pyswarms is trying to configure a logger that outputs to a local file at init, but if the process doesn't have write permissions to the working directory then it fails. Personally, I find the logger defaults more annoying than helpful, particularly given that it preemptively creates a log file at init, rather than when the optimization routine is begun. I think this issue could be closed simply by making that move. Similarly, toggling the progress bar and the log file during optimization should be independent, not coupled together via My full traceback below, note the ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:180, in Reporter._setup_logger(self, path)
179 try:
--> 180 with open(value, "rt") as f:
181 config = yaml.safe_load(f.read())
TypeError: expected str, bytes or os.PathLike object, not NoneType
During handling of the above exception, another exception occurred:
PermissionError Traceback (most recent call last)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:573, in DictConfigurator.configure(self)
572 try:
--> 573 handler = self.configure_handler(handlers[name])
574 handler.name = name
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:758, in DictConfigurator.configure_handler(self, config)
757 try:
--> 758 result = factory(**kwargs)
759 except TypeError as te:
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/handlers.py:155, in RotatingFileHandler.__init__(self, filename, mode, maxBytes, backupCount, encoding, delay, errors)
154 encoding = io.text_encoding(encoding)
--> 155 BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
156 delay=delay, errors=errors)
157 self.maxBytes = maxBytes
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/handlers.py:58, in BaseRotatingHandler.__init__(self, filename, mode, encoding, delay, errors)
55 """
56 Use the specified filename for streamed logging
57 """
---> 58 logging.FileHandler.__init__(self, filename, mode=mode,
59 encoding=encoding, delay=delay,
60 errors=errors)
61 self.mode = mode
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/__init__.py:1181, in FileHandler.__init__(self, filename, mode, encoding, delay, errors)
1180 else:
-> 1181 StreamHandler.__init__(self, self._open())
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/__init__.py:1213, in FileHandler._open(self)
1212 open_func = self._builtin_open
-> 1213 return open_func(self.baseFilename, self.mode,
1214 encoding=self.encoding, errors=self.errors)
PermissionError: [Errno 13] Permission denied: '/home/report.log'
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import sbdb
File /home/projects/sbdb/sbdb/__init__.py:9
7 from .librarian import *
8 from .liquid_handling import *
----> 9 from .optimization import *
10 from .processing import *
11 from .schema import *
File /home/projects/sbdb/sbdb/optimization/__init__.py:1
----> 1 from .assay_optimizer import *
2 from .denovo_probes import DeNovoProbes
3 from .mutable_primers import MutablePrimers
File /home/projects/sbdb/sbdb/optimization/assay_optimizer.py:14
12 from scipy.special import erfcx
13 from scipy.stats.qmc import Sobol, LatinHypercube
---> 14 import pyswarms as ps
15 import pytensor.tensor as pt
16 import pytensor.gradient as pg
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/__init__.py:17
14 __email__ = "[email protected]"
15 __version__ = "1.3.0"
---> 17 from .single import global_best, local_best, general_optimizer
18 from .discrete import binary
19 from .utils.decorators import cost
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/single/__init__.py:17
1 """
2 The :mod:`pyswarms.single` module implements various techniques in
3 continuous single-objective optimization. These require only one
(...)
14 multiplication can lead to an :code:`OverflowError`.
15 """
---> 17 from .global_best import GlobalBestPSO
18 from .local_best import LocalBestPSO
19 from .general_optimizer import GeneralOptimizerPSO
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/single/global_best.py:67
63 import multiprocessing as mp
65 from collections import deque
---> 67 from ..backend.operators import compute_pbest, compute_objective_function
68 from ..backend.topology import Star
69 from ..backend.handlers import BoundaryHandler, VelocityHandler, OptionsHandler
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/backend/__init__.py:7
1 """
2 The :code:`pyswarms.backend` module abstracts various operations
3 for swarm optimization: generating boundaries, updating positions, etc.
4 You can use the methods implemented here to build your own PSO implementations.
5 """
----> 7 from .generators import *
8 from .handlers import *
9 from .operators import *
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/backend/generators.py:21
18 from ..utils.reporter import Reporter
19 from .swarms import Swarm
---> 21 rep = Reporter(logger=logging.getLogger(__name__))
24 def generate_swarm(
25 n_particles, dimensions, bounds=None, center=1.00, init_pos=None
26 ):
27 """Generate a swarm
28
29 Parameters
(...)
58 When the argument passed to bounds is not an iterable.
59 """
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:118, in Reporter.__init__(self, log_path, config_path, logger, printer)
85 self._env_key = "LOG_CFG"
86 self._default_config = {
87 "version": 1,
88 "disable_existing_loggers": False,
(...)
116 },
117 }
--> 118 self._setup_logger(config_path)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:184, in Reporter._setup_logger(self, path)
182 logging.config.dictConfig(config)
183 except (TypeError, FileNotFoundError):
--> 184 self._load_defaults()
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:188, in Reporter._load_defaults(self)
186 def _load_defaults(self):
187 """Load default logging configuration"""
--> 188 logging.config.dictConfig(self._default_config)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:823, in dictConfig(config)
821 def dictConfig(config):
822 """Configure logging using a dictionary."""
--> 823 dictConfigClass(config).configure()
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:580, in DictConfigurator.configure(self)
578 deferred.append(name)
579 else:
--> 580 raise ValueError('Unable to configure handler '
581 '%r' % name) from e
583 # Now do any that were deferred
584 for name in deferred:
ValueError: Unable to configure handler 'file_default' |
Hi, I managed to solve the problem by changing the source code and ## the
lines which made it crash, it seems that the problem was the way pyswarms was using the logger
everything else seems to work
…On Mon, Jun 17, 2024, 22:08 John Goertz ***@***.***> wrote:
I have this same issue, but in a different context. I believe the root
issue is that pyswarms is trying to configure a logger that outputs to a
local file at init, but if the process doesn't have write permissions to
the working directory then it fails.
Personally, I find the logger defaults more annoying than helpful,
particularly given that it *preemptively* creates a log file at init,
rather than when the optimization routine is begun. I think this issue
could be closed simply by making that move. Similarly, toggling the
progress bar and the log file during optimization should be independent,
not coupled together via verbose.
My full traceback below, note the PermissionError in the middle:
---------------------------------------------------------------------------TypeError Traceback (most recent call last)File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:180, in Reporter._setup_logger(self, path)
179 try:--> 180 with open(value, "rt") as f:
181 config = yaml.safe_load(f.read())
TypeError: expected str, bytes or os.PathLike object, not NoneType
During handling of the above exception, another exception occurred:
PermissionError Traceback (most recent call last)File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:573, in DictConfigurator.configure(self)
572 try:--> 573 handler = self.configure_handler(handlers[name])
574 handler.name = name
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:758, in DictConfigurator.configure_handler(self, config)
757 try:--> 758 result = factory(**kwargs)
759 except TypeError as te:
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/handlers.py:155, in RotatingFileHandler.__init__(self, filename, mode, maxBytes, backupCount, encoding, delay, errors)
154 encoding = io.text_encoding(encoding)--> 155 BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
156 delay=delay, errors=errors)
157 self.maxBytes = maxBytes
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/handlers.py:58, in BaseRotatingHandler.__init__(self, filename, mode, encoding, delay, errors)
55 """ 56 Use the specified filename for streamed logging 57 """---> 58 logging.FileHandler.__init__(self, filename, mode=mode,
59 encoding=encoding, delay=delay,
60 errors=errors)
61 self.mode = mode
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/__init__.py:1181, in FileHandler.__init__(self, filename, mode, encoding, delay, errors)
1180 else:-> 1181 StreamHandler.__init__(self, self._open())
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/__init__.py:1213, in FileHandler._open(self)
1212 open_func = self._builtin_open-> 1213 return open_func(self.baseFilename, self.mode,
1214 encoding=self.encoding, errors=self.errors)
PermissionError: [Errno 13] Permission denied: '/home/report.log'
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)Cell In[1], line 1----> 1 import sbdb
File /home/projects/sbdb/sbdb/__init__.py:9
7 from .librarian import *
8 from .liquid_handling import *----> 9 from .optimization import *
10 from .processing import *
11 from .schema import *
File /home/projects/sbdb/sbdb/optimization/__init__.py:1----> 1 from .assay_optimizer import *
2 from .denovo_probes import DeNovoProbes
3 from .mutable_primers import MutablePrimers
File /home/projects/sbdb/sbdb/optimization/assay_optimizer.py:14
12 from scipy.special import erfcx
13 from scipy.stats.qmc import Sobol, LatinHypercube---> 14 import pyswarms as ps
15 import pytensor.tensor as pt
16 import pytensor.gradient as pg
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/__init__.py:17
14 __email__ = ***@***.***"
15 __version__ = "1.3.0"---> 17 from .single import global_best, local_best, general_optimizer
18 from .discrete import binary
19 from .utils.decorators import cost
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/single/__init__.py:17
1 """ 2 The :mod:`pyswarms.single` module implements various techniques in 3 continuous single-objective optimization. These require only one (...) 14 multiplication can lead to an :code:`OverflowError`. 15 """---> 17 from .global_best import GlobalBestPSO
18 from .local_best import LocalBestPSO
19 from .general_optimizer import GeneralOptimizerPSO
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/single/global_best.py:67
63 import multiprocessing as mp
65 from collections import deque---> 67 from ..backend.operators import compute_pbest, compute_objective_function
68 from ..backend.topology import Star
69 from ..backend.handlers import BoundaryHandler, VelocityHandler, OptionsHandler
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/backend/__init__.py:7
1 """ 2 The :code:`pyswarms.backend` module abstracts various operations 3 for swarm optimization: generating boundaries, updating positions, etc. 4 You can use the methods implemented here to build your own PSO implementations. 5 """----> 7 from .generators import *
8 from .handlers import *
9 from .operators import *
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/backend/generators.py:21
18 from ..utils.reporter import Reporter
19 from .swarms import Swarm---> 21 rep = Reporter(logger=logging.getLogger(__name__))
24 def generate_swarm(
25 n_particles, dimensions, bounds=None, center=1.00, init_pos=None
26 ):
27 """Generate a swarm 28 29 Parameters (...) 58 When the argument passed to bounds is not an iterable. 59 """
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:118, in Reporter.__init__(self, log_path, config_path, logger, printer)
85 self._env_key = "LOG_CFG"
86 self._default_config = {
87 "version": 1,
88 "disable_existing_loggers": False,
(...)
116 },
117 }--> 118 self._setup_logger(config_path)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:184, in Reporter._setup_logger(self, path)
182 logging.config.dictConfig(config)
183 except (TypeError, FileNotFoundError):--> 184 self._load_defaults()
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/site-packages/pyswarms/utils/reporter/reporter.py:188, in Reporter._load_defaults(self)
186 def _load_defaults(self):
187 """Load default logging configuration"""--> 188 logging.config.dictConfig(self._default_config)
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:823, in dictConfig(config)
821 def dictConfig(config):
822 """Configure logging using a dictionary."""--> 823 dictConfigClass(config).configure()
File /home/mambaforge/envs/sbdb-dev/lib/python3.11/logging/config.py:580, in DictConfigurator.configure(self)
578 deferred.append(name)
579 else:--> 580 raise ValueError('Unable to configure handler '
581 '%r' % name) from e
583 # Now do any that were deferred
584 for name in deferred:
ValueError: Unable to configure handler 'file_default'
—
Reply to this email directly, view it on GitHub
<#526 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BHVPJGITUXHRE6W57UOHM4DZH4XZDAVCNFSM6AAAAABHDJJBQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZUGIZDONBUGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Describe the bug
When I only import pyswarms it crashes on init
To Reproduce
Create an android application with com.chaquo.python
as a python compiler,
in the default config install pyswarms (which will install all the other libraries)
chaquopy {
defaultConfig {
pip {
install("pyswarms==1.3.0")
}
}
then if you run a python method with chaquopy, on import it would throw out this error
com.chaquo.python.PyException: ValueError: Unable to configure handler 'file_default'
at .logging.config.configure(config.py:570)
at .logging.config.dictConfig(config.py:808)
at .pyswarms.utils.reporter.reporter._load_defaults(reporter.py:188)
at .pyswarms.utils.reporter.reporter._setup_logger(reporter.py:184)
at .pyswarms.utils.reporter.reporter.init(reporter.py:118)
at .pyswarms.backend.generators.(generators.py:21)
at .java.chaquopy.import_override(import.pxi:26)
at .pyswarms.backend.(init.py:7)
at .java.chaquopy.import_override(import.pxi:26)
at .pyswarms.single.global_best.(global_best.py:65)
at .java.chaquopy.import_override(import.pxi:26)
at .pyswarms.single.(init.py:17)
at .java.chaquopy.import_override(import.pxi:26)
at .pyswarms.(init.py:17)
at .java.chaquopy.import_override(import.pxi:26)
Expected behavior
Expected to not crash at import
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: