-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rostislav V. Rjabow
committed
Apr 10, 2023
1 parent
a2f1a33
commit 2671b11
Showing
10 changed files
with
157 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from abc import ABC, abstractmethod, abstractproperty | ||
from collections import namedtuple | ||
from pathlib import Path | ||
|
||
|
||
PackageBrief = namedtuple('PackageBrief', ['name', 'probe_fun']) | ||
|
||
|
||
M_SCRIPTS = Path(__file__).parent / 'script' | ||
OUTPUT_DIR = Path(__file__).parent / 'out' | ||
GATEWAY_DIR = Path(__file__).parent / 'gateway' | ||
PACKAGES = [PackageBrief(name='jsonlab', probe_fun='loadjson'), | ||
PackageBrief(name='iso2mesh', probe_fun='s2m')] | ||
|
||
|
||
class BackendABC(ABC): | ||
@abstractmethod | ||
def __init__(self, engine_type: str): | ||
pass | ||
|
||
@ | ||
|
||
class OctaveBackend(BackendABC): | ||
def __init__(self, engine_type: str): | ||
self.engine_type = engine_type.lower() | ||
if self.engine_type == 'octave': | ||
self.EngineError2 = self.EngineError1 = __import__('oct2py.utils', globals(), locals(), ['Oct2PyError'], 0) | ||
self.engine = __import__('oct2py', globals(), locals(), ['Oct2Py'], 0) | ||
else: | ||
matlab_stuff = __import__('matlab.engine', globals(), locals(), ['MatlabEngine', | ||
'MatlabExecutionError', | ||
'RejectedExecutionError'], 0) | ||
self.EngineError1 = matlab_stuff.MatlabExecutionError | ||
self.EngineError1 = matlab_stuff.RejectedExecutionError | ||
self.engine = matlab_stuff.MatlabEngine | ||
|
||
def __getattr__(self, item): | ||
def inner(*args, nout: int = 0): | ||
with self.engine() as engine: | ||
# import | ||
engine.addpath(M_SCRIPTS) | ||
try: | ||
packages_to_load = filter(lambda p: p['name'] in PACKAGES, engine.pkg('list').tolist()[0]) | ||
for package in packages_to_load: | ||
engine.addpath(str(Path(package['dir']))) | ||
except IndexError: | ||
raise ImportError('No local packages installed for Octave') # TODO: another exception type | ||
try: | ||
return engine.feval(item, *args, nargout=nout) | ||
except self.EngineError1: | ||
return engine.feval(item, *args, nout=nout) | ||
return inner | ||
|
||
|
||
def get_backend(engine_type='octave'): | ||
return Backend(engine_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class BlenderPhotonicsError(Exception): | ||
pass | ||
|
||
|
||
class BlenderPhotonicsDependencyError(BlenderPhotonicsError): | ||
"""Errors concerning missing system or Python utilities/modules/packages""" | ||
def __init__(self, dep: str, *args, **kwargs): | ||
self.missing_dep = dep | ||
super().__init__(f'Required dependency not found: {dep}', *args) | ||
|
||
|
||
class BlenderPhotonicsMeshingError(BlenderPhotonicsError): | ||
"""Meshing failure, typically a forwarding of some backend error""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.