feat: Fixes for cloud tasks, lint run

main
Sofus Albert Høgsbro Rose 2024-04-02 20:39:55 +02:00
parent 505a12fa25
commit 01cfc61094
Signed by: so-rose
GPG Key ID: AD901CB0F3701434
107 changed files with 423 additions and 678 deletions

View File

@ -28,6 +28,13 @@ DEFAULT_PATH_DEPS = PATH_ADDON_ROOT / '.addon_dependencies'
## requirements.lock is written when packing the .zip.
## By default, the addon pydeps are kept in the addon dir.
####################
# - Local Addon Cache
####################
ADDON_CACHE = PATH_ADDON_ROOT / '.addon_cache'
ADDON_CACHE.mkdir(exist_ok=True)
## TODO: Addon preferences?
####################
# - Logging Info
####################

View File

@ -5,10 +5,7 @@ sp.printing.str.StrPrinter._default_settings['abbrev'] = True
## By configuring this in __init__.py, we guarantee it for all subimports.
## (Unless, elsewhere, this setting is changed. Be careful!)
from . import sockets
from . import node_tree
from . import nodes
from . import categories
from . import categories, node_tree, nodes, sockets
BL_REGISTER = [
*sockets.BL_REGISTER,

View File

@ -1,7 +1,6 @@
"""Tools for translating between BLMaxwell sockets and pure Blender sockets.
Attributes:
SOCKET_DEFS: Maps BLMaxwell SocketType objects to their corresponding SocketDef.
BL_SOCKET_3D_TYPE_PREFIXES: Blender socket prefixes which indicate that the Blender socket has three values.
BL_SOCKET_4D_TYPE_PREFIXES: Blender socket prefixes which indicate that the Blender socket has four values.
"""
@ -15,8 +14,7 @@ import sympy as sp
from ...utils import extra_sympy_units as spux
from ...utils import logger as _logger
from . import contracts as ct
from . import sockets as sck
from .contracts import SocketType as ST # noqa: N817
from . import sockets
log = _logger.get(__name__)
@ -25,26 +23,7 @@ BLSocketValue: typ.TypeAlias = typ.Any ## A Blender Socket Value
BLSocketSize: typ.TypeAlias = int
DescType: typ.TypeAlias = str
Unit: typ.TypeAlias = typ.Any ## Type of a valid unit
####################
# - Socket to SocketDef
####################
## TODO: It's only smelly because of the way we bubble up SocketDefs
SOCKET_DEFS = {
socket_type: getattr(
sck,
socket_type.value.removesuffix('SocketType') + 'SocketDef',
)
for socket_type in ST
if hasattr(sck, socket_type.value.removesuffix('SocketType') + 'SocketDef')
}
for socket_type in ST:
if not hasattr(
sck,
socket_type.value.removesuffix('SocketType') + 'SocketDef',
):
log.warning('Missing SocketDef for %s', socket_type.value)
## TODO: Move this kind of thing to contracts
####################
@ -96,7 +75,7 @@ def _size_from_bl_socket(
def _socket_type_from_bl_socket(
description: str,
bl_socket_type: BLSocketType,
) -> ST:
) -> ct.SocketType:
"""Parse a Blender socket for a matching BLMaxwell socket type, relying on both the Blender socket type and user-generated hints in the description.
Arguments:
@ -141,8 +120,8 @@ def _socket_type_from_bl_socket(
def _socket_def_from_bl_socket(
description: str,
bl_socket_type: BLSocketType,
) -> ST:
return SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)]
) -> ct.SocketType:
return sockets.SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)]
def socket_def_from_bl_socket(
@ -252,7 +231,6 @@ def writable_bl_socket_value(
Returns:
A value corresponding to the input, which is guaranteed to be compatible with the Blender socket (incl. via a GeoNodes modifier), as well as correctly scaled with respect to the given unit system.
"""
return _writable_bl_socket_value(
bl_interface_socket.description,

View File

@ -2,6 +2,7 @@
import bpy
import nodeitems_utils
from . import contracts as ct
from .nodes import BL_NODES

View File

@ -1,5 +1,3 @@
import sympy.physics.units as spu
from ....utils import extra_sympy_units as spuex
from .socket_types import SocketType as ST

View File

@ -3,7 +3,6 @@ import enum
from ....utils.blender_type_enum import (
BlenderTypeEnum,
append_cls_name_to_values,
wrap_values_in_MT,
)

View File

@ -17,8 +17,6 @@ UnitSystem: typ.TypeAlias = dict[ST, SympyExpr]
# - Unit Systems
####################
UNITS_BLENDER: UnitSystem = {
socket_type: _socket_units(socket_type)[socket_unit_prop]
for socket_type, socket_unit_prop in {
ST.PhysicalTime: spu.picosecond,
ST.PhysicalAngle: spu.radian,
ST.PhysicalLength: spu.micrometer,
@ -31,17 +29,14 @@ UNITS_BLENDER: UnitSystem = {
ST.PhysicalMass: spu.microgram,
ST.PhysicalSpeed: spu.um / spu.second,
ST.PhysicalAccelScalar: spu.um / spu.second**2,
ST.PhysicalForceScalar: spu.micronewton,
ST.PhysicalForceScalar: spux.micronewton,
ST.PhysicalAccel3D: spu.um / spu.second**2,
ST.PhysicalForce3D: spu.micronewton,
ST.PhysicalFreq: spu.terahertz,
ST.PhysicalForce3D: spux.micronewton,
ST.PhysicalFreq: spux.terahertz,
ST.PhysicalPol: spu.radian,
}.items()
} ## TODO: Load (dynamically?) from addon preferences
UNITS_TIDY3D: UnitSystem = {
socket_type: _socket_units(socket_type)[socket_unit_prop]
for socket_type, socket_unit_prop in {
ST.PhysicalTime: spu.picosecond,
ST.PhysicalAngle: spu.radian,
ST.PhysicalLength: spu.micrometer,
@ -54,10 +49,9 @@ UNITS_TIDY3D: UnitSystem = {
ST.PhysicalMass: spu.microgram,
ST.PhysicalSpeed: spu.um / spu.second,
ST.PhysicalAccelScalar: spu.um / spu.second**2,
ST.PhysicalForceScalar: spu.micronewton,
ST.PhysicalForceScalar: spux.micronewton,
ST.PhysicalAccel3D: spu.um / spu.second**2,
ST.PhysicalForce3D: spu.micronewton,
ST.PhysicalFreq: spu.terahertz,
ST.PhysicalForce3D: spux.micronewton,
ST.PhysicalFreq: spux.terahertz,
ST.PhysicalPol: spu.radian,
}.items()
}

View File

@ -1,12 +1,10 @@
import typing as typ
import typing_extensions as typx
import io
import numpy as np
import pydantic as pyd
import matplotlib.axis as mpl_ax
import typing as typ
import bpy
import matplotlib.axis as mpl_ax
import numpy as np
import typing_extensions as typx
from .. import contracts as ct
@ -161,7 +159,7 @@ class ManagedBLImage(ct.schemas.ManagedObj):
height_px = int(_height_inches * _dpi)
else:
msg = f'There must either be a preview area, or defined `width_inches`, `height_inches`, and `dpi`'
msg = 'There must either be a preview area, or defined `width_inches`, `height_inches`, and `dpi`'
raise ValueError(msg)
# Compute Plot Dimensions

View File

@ -1,16 +1,17 @@
# from . import kitchen_sink
from . import inputs
from . import outputs
from . import sources
from . import mediums
from . import structures
# from . import bounds
from . import monitors
from . import simulations
from . import utilities
from . import viz
from . import (
inputs,
mediums,
monitors,
outputs,
simulations,
sources,
structures,
utilities,
viz,
)
BL_REGISTER = [
# *kitchen_sink.BL_REGISTER,

View File

@ -21,7 +21,7 @@ _DEFAULT_LOOSE_SOCKET_SER = json.dumps(
'socket_def_names': [],
'models': [],
}
)
) ## TODO: What in the jesus christ is this
class MaxwellSimNode(bpy.types.Node):
@ -162,6 +162,7 @@ class MaxwellSimNode(bpy.types.Node):
for socket_set_id, socket_set_name in zip(
socket_set_ids,
socket_set_names,
strict=False,
)
],
default=socket_set_names[0],
@ -316,6 +317,7 @@ class MaxwellSimNode(bpy.types.Node):
semi_deser['socket_names'],
semi_deser['socket_def_names'],
semi_deser['models'],
strict=False,
)
if hasattr(sockets, socket_def_name)
}
@ -538,7 +540,7 @@ class MaxwellSimNode(bpy.types.Node):
):
return output_socket_method(self)
msg = f'No output method for ({output_socket_name}, {str(kind.value)}'
msg = f'No output method for ({output_socket_name}, {kind.value!s}'
raise ValueError(msg)
####################
@ -642,7 +644,6 @@ class MaxwellSimNode(bpy.types.Node):
Restricted to the MaxwellSimTreeType.
"""
return node_tree.bl_idname == ct.TreeType.MaxwellSim.value
def init(self, context: bpy.types.Context):

View File

@ -1,5 +1,4 @@
from . import bound_box
from . import bound_faces
from . import bound_box, bound_faces
BL_REGISTER = [
*bound_box.BL_REGISTER,

View File

@ -1,6 +1,4 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
from ... import contracts as ct
from ... import sockets

View File

@ -1,10 +1,11 @@
from . import pml_bound_face
from . import pec_bound_face
from . import pmc_bound_face
from . import bloch_bound_face
from . import periodic_bound_face
from . import absorbing_bound_face
from . import (
absorbing_bound_face,
bloch_bound_face,
pec_bound_face,
periodic_bound_face,
pmc_bound_face,
pml_bound_face,
)
BL_REGISTER = [
*pml_bound_face.BL_REGISTER,

View File

@ -1,8 +1,6 @@
# from . import scientific_constant
from . import number_constant
# from . import physical_constant
from . import blender_constant
from . import blender_constant, number_constant
BL_REGISTER = [
# *scientific_constant.BL_REGISTER,

View File

@ -9,7 +9,7 @@ class BlenderConstantNode(base.MaxwellSimNode):
node_type = ct.NodeType.BlenderConstant
bl_label = 'Blender Constant'
input_socket_sets = {
input_socket_sets: typ.ClassVar = {
'Object': {
'Value': sockets.BlenderObjectSocketDef(),
},
@ -42,6 +42,4 @@ class BlenderConstantNode(base.MaxwellSimNode):
BL_REGISTER = [
BlenderConstantNode,
]
BL_NODES = {
ct.NodeType.BlenderConstant: (ct.NodeCategory.MAXWELLSIM_INPUTS_CONSTANTS)
}
BL_NODES = {ct.NodeType.BlenderConstant: (ct.NodeCategory.MAXWELLSIM_INPUTS_CONSTANTS)}

View File

@ -1,8 +1,5 @@
import typing as typ
import bpy
import sympy as sp
from .... import contracts as ct
from .... import sockets
from ... import base
@ -12,7 +9,7 @@ class NumberConstantNode(base.MaxwellSimNode):
node_type = ct.NodeType.NumberConstant
bl_label = 'Numerical Constant'
input_socket_sets = {
input_socket_sets: typ.ClassVar = {
'Integer': {
'Value': sockets.IntegerNumberSocketDef(),
},

View File

@ -1,19 +1,16 @@
import bpy
import typing as typ
import sympy as sp
from .... import contracts
from .... import sockets
from ... import base
from .... import contracts, sockets
from ... import base, events
class PhysicalConstantNode(base.MaxwellSimTreeNode):
node_type = contracts.NodeType.PhysicalConstant
bl_label = 'Physical Constant'
# bl_icon = constants.ICON_SIM_INPUT
input_sockets = {}
input_socket_sets = {
input_socket_sets: typ.ClassVar = {
'time': {
'value': sockets.PhysicalTimeSocketDef(
label='Time',
@ -51,13 +48,12 @@ class PhysicalConstantNode(base.MaxwellSimTreeNode):
},
## I got bored so maybe the rest later
}
output_sockets = {}
output_socket_sets = input_socket_sets
output_socket_sets: typ.ClassVar = input_socket_sets
####################
# - Callbacks
####################
@base.computes_output_socket('value')
@events.computes_output_socket('value')
def compute_value(self: contracts.NodeTypeProtocol) -> sp.Expr:
return self.compute_input('value')

View File

@ -1,3 +1,4 @@
## TODO: Discover dropdown options from sci_constants.py
####################
# - Blender Registration
####################

View File

@ -2,6 +2,7 @@ from ... import contracts as ct
from ... import sockets
from .. import base
class PhysicalUnitSystemNode(base.MaxwellSimNode):
node_type = ct.NodeType.UnitSystem
bl_label = 'Unit System'

View File

@ -1,22 +1,20 @@
import bpy
import typing as typ
import sympy as sp
import sympy.physics.units as spu
import scipy as sc
from .....utils import extra_sympy_units as spux
from .....utils import sci_constants as constants
from ... import contracts as ct
from ... import sockets
from .. import base
VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second
class WaveConstantNode(base.MaxwellSimNode):
node_type = ct.NodeType.WaveConstant
bl_label = 'Wave Constant'
input_socket_sets = {
input_socket_sets: typ.ClassVar = {
# Single
'Vacuum WL': {
'WL': sockets.PhysicalLengthSocketDef(
@ -44,7 +42,7 @@ class WaveConstantNode(base.MaxwellSimNode):
}
####################
# - Callbacks
# - Event Methods: Listy Output
####################
@base.computes_output_socket(
'WL',
@ -53,14 +51,11 @@ class WaveConstantNode(base.MaxwellSimNode):
def compute_vac_wl(self, input_sockets: dict) -> sp.Expr:
if (vac_wl := input_sockets['WL']) is not None:
return vac_wl
if (freq := input_sockets['Freq']) is not None:
return constants.vac_speed_of_light / freq
elif (freq := input_sockets['Freq']) is not None:
return spu.convert_to(
VAC_SPEED_OF_LIGHT / freq,
spu.meter,
)
raise RuntimeError('Vac WL and Freq are both None')
msg = 'Vac WL and Freq are both None'
raise RuntimeError(msg)
@base.computes_output_socket(
'Freq',
@ -68,17 +63,15 @@ class WaveConstantNode(base.MaxwellSimNode):
)
def compute_freq(self, input_sockets: dict) -> sp.Expr:
if (vac_wl := input_sockets['WL']) is not None:
return spu.convert_to(
VAC_SPEED_OF_LIGHT / vac_wl,
spu.hertz,
)
elif (freq := input_sockets['Freq']) is not None:
return constants.vac_speed_of_light / vac_wl
if (freq := input_sockets['Freq']) is not None:
return freq
raise RuntimeError('Vac WL and Freq are both None')
msg = 'Vac WL and Freq are both None'
raise RuntimeError(msg)
####################
# - Listy Callbacks
# - Event Methods: Listy Output
####################
@base.computes_output_socket(
'WLs',
@ -87,16 +80,11 @@ class WaveConstantNode(base.MaxwellSimNode):
def compute_vac_wls(self, input_sockets: dict) -> sp.Expr:
if (vac_wls := input_sockets['WLs']) is not None:
return vac_wls
elif (freqs := input_sockets['Freqs']) is not None:
return [
spu.convert_to(
VAC_SPEED_OF_LIGHT / freq,
spu.meter,
)
for freq in freqs
][::-1]
if (freqs := input_sockets['Freqs']) is not None:
return [constants.vac_speed_of_light / freq for freq in freqs][::-1]
raise RuntimeError('Vac WLs and Freqs are both None')
msg = 'Vac WL and Freq are both None'
raise RuntimeError(msg)
@base.computes_output_socket(
'Freqs',
@ -104,25 +92,18 @@ class WaveConstantNode(base.MaxwellSimNode):
)
def compute_freqs(self, input_sockets: dict) -> sp.Expr:
if (vac_wls := input_sockets['WLs']) is not None:
return [
spu.convert_to(
VAC_SPEED_OF_LIGHT / vac_wl,
spu.hertz,
)
for vac_wl in vac_wls
][::-1]
elif (freqs := input_sockets['Freqs']) is not None:
return [constants.vac_speed_of_light / vac_wl for vac_wl in vac_wls][::-1]
if (freqs := input_sockets['Freqs']) is not None:
return freqs
raise RuntimeError('Vac WLs and Freqs are both None')
msg = 'Vac WL and Freq are both None'
raise RuntimeError(msg)
####################
# - Callbacks
# - Event Methods
####################
@base.on_value_changed(
prop_name='active_socket_set', props={'active_socket_set'}
)
def on_value_changed__active_socket_set(self, props: dict):
@base.on_value_changed(prop_name='active_socket_set', props={'active_socket_set'})
def on_active_socket_set_changed(self, props: dict):
# Singular: Normal Output Sockets
if props['active_socket_set'] in {'Vacuum WL', 'Frequency'}:
self.loose_output_sockets = {}
@ -145,7 +126,7 @@ class WaveConstantNode(base.MaxwellSimNode):
@base.on_init()
def on_init(self):
self.on_value_changed__active_socket_set()
self.on_active_socket_set_changed()
####################

View File

@ -1,15 +1,23 @@
import tempfile
import typing as typ
from pathlib import Path
import tidy3d as td
import tidy3d.web as td_web
from ...... import info
from ......services import tdcloud
from .... import contracts as ct
from .... import sockets
from ... import base
CACHE = {}
def _sim_data_cache_path(task_id: str) -> Path:
"""Compute an appropriate location for caching simulations downloaded from the internet, unique to each task ID.
Arguments:
task_id: The ID of the Tidy3D cloud task.
"""
return info.ADDON_CACHE / task_id / 'sim_data.hdf5'
####################
@ -19,87 +27,42 @@ class Tidy3DWebImporterNode(base.MaxwellSimNode):
node_type = ct.NodeType.Tidy3DWebImporter
bl_label = 'Tidy3D Web Importer'
input_sockets = {
input_sockets: typ.ClassVar = {
'Cloud Task': sockets.Tidy3DCloudTaskSocketDef(
should_exist=True,
),
'Cache Path': sockets.FilePathSocketDef(
default_path=Path('loaded_simulation.hdf5')
),
}
####################
# - Output Methods
# - Event Methods
####################
@base.computes_output_socket(
'FDTD Sim Data',
input_sockets={'Cloud Task', 'Cache Path'},
)
def compute_fdtd_sim_data(self, input_sockets: dict) -> str:
global CACHE
if not CACHE.get(self.instance_id):
CACHE[self.instance_id] = {'fdtd_sim_data': None}
if CACHE[self.instance_id]['fdtd_sim_data'] is not None:
return CACHE[self.instance_id]['fdtd_sim_data']
if not (
(cloud_task := input_sockets['Cloud Task']) is not None
and isinstance(cloud_task, tdcloud.CloudTask)
and cloud_task.status == 'success'
):
msg = "Won't attempt getting SimData"
raise RuntimeError(msg)
# Load the Simulation
cache_path = input_sockets['Cache Path']
if cache_path is None:
print('CACHE PATH IS NONE WHY')
return ## I guess?
if cache_path.is_file():
sim_data = td.SimulationData.from_file(str(cache_path))
else:
sim_data = td_web.api.webapi.load(
cloud_task.task_id,
path=str(cache_path),
)
CACHE[self.instance_id]['fdtd_sim_data'] = sim_data
return sim_data
@base.computes_output_socket(
'FDTD Sim',
input_sockets={'Cloud Task'},
)
def compute_fdtd_sim(self, input_sockets: dict) -> str:
if not isinstance(
cloud_task := input_sockets['Cloud Task'], tdcloud.CloudTask
):
msg = 'Input cloud task does not exist'
def compute_sim_data(self, input_sockets: dict) -> str:
# Validate Task Availability
if (cloud_task := input_sockets['Cloud Task']) is None:
msg = f'"{self.bl_label}" CloudTask doesn\'t exist'
raise RuntimeError(msg)
# Load the Simulation
with tempfile.NamedTemporaryFile(delete=False) as f:
_path_tmp = Path(f.name)
_path_tmp.rename(f.name + '.json')
path_tmp = Path(f.name + '.json')
# Validate Task Existence
if not isinstance(cloud_task, tdcloud.CloudTask):
msg = f'"{self.bl_label}" CloudTask input "{cloud_task}" has wrong "should_exists", as it isn\'t an instance of tdcloud.CloudTask'
raise TypeError(msg)
sim = td_web.api.webapi.load_simulation(
cloud_task.task_id,
path=str(path_tmp),
) ## TODO: Don't use td_web directly. Only through tdcloud
Path(path_tmp).unlink()
# Validate Task Status
if cloud_task.status != 'success':
msg = f'"{self.bl_label}" CloudTask is "{cloud_task.status}", not "success"'
raise RuntimeError(msg)
return sim
####################
# - Update
####################
@base.on_value_changed(
socket_name='Cloud Task', input_sockets={'Cloud Task'}
# Download and Return SimData
return tdcloud.TidyCloudTasks.download_task_sim_data(
cloud_task, _sim_data_cache_path(cloud_task.task_id)
)
def on_value_changed__cloud_task(self, input_sockets: dict):
@base.on_value_changed(socket_name='Cloud Task', input_sockets={'Cloud Task'})
def on_cloud_task_changed(self, input_sockets: dict):
if (
(cloud_task := input_sockets['Cloud Task']) is not None
and isinstance(cloud_task, tdcloud.CloudTask)
@ -107,15 +70,13 @@ class Tidy3DWebImporterNode(base.MaxwellSimNode):
):
self.loose_output_sockets = {
'FDTD Sim Data': sockets.MaxwellFDTDSimDataSocketDef(),
'FDTD Sim': sockets.MaxwellFDTDSimSocketDef(),
}
return
else:
self.loose_output_sockets = {}
@base.on_init()
def on_init(self):
self.on_value_changed__cloud_task()
self.on_cloud_task_changed()
####################
@ -125,7 +86,5 @@ BL_REGISTER = [
Tidy3DWebImporterNode,
]
BL_NODES = {
ct.NodeType.Tidy3DWebImporter: (
ct.NodeCategory.MAXWELLSIM_INPUTS_IMPORTERS
)
ct.NodeType.Tidy3DWebImporter: (ct.NodeCategory.MAXWELLSIM_INPUTS_IMPORTERS)
}

View File

@ -1,8 +1,5 @@
from pathlib import Path
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
from .. import contracts as ct
from .. import sockets

View File

@ -1,9 +1,7 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import tidy3d as td
from ... import contracts
from ... import sockets
from ... import contracts, sockets
from .. import base
@ -19,7 +17,7 @@ class DrudeLorentzMediumNode(base.MaxwellSimTreeNode):
input_sockets = (
{
'eps_inf': sockets.RealNumberSocketDef(
label=f'εr_∞',
label='εr_∞',
),
}
| {
@ -52,7 +50,7 @@ class DrudeLorentzMediumNode(base.MaxwellSimTreeNode):
def compute_medium(self: contracts.NodeTypeProtocol) -> td.Sellmeier:
## Retrieval
return td.Lorentz(
eps_inf=self.compute_input(f'eps_inf'),
eps_inf=self.compute_input('eps_inf'),
coeffs=[
(
self.compute_input(f'del_eps{i}'),

View File

@ -1,17 +1,14 @@
import typing as typ
import functools
import bpy
import tidy3d as td
import scipy as sc
import sympy as sp
import sympy.physics.units as spu
import numpy as np
import scipy as sc
import tidy3d as td
from .....utils import extra_sympy_units as spuex
from ... import contracts as ct
from ... import sockets
from ... import managed_objs
from ... import managed_objs, sockets
from .. import base
VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second

View File

@ -1,7 +1,9 @@
from . import add_non_linearity
from . import chi_3_susceptibility_non_linearity
from . import kerr_non_linearity
from . import two_photon_absorption_non_linearity
from . import (
add_non_linearity,
chi_3_susceptibility_non_linearity,
kerr_non_linearity,
two_photon_absorption_non_linearity,
)
BL_REGISTER = [
*add_non_linearity.BL_REGISTER,

View File

@ -1,9 +1,7 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import tidy3d as td
from ... import contracts
from ... import sockets
from ... import contracts, sockets
from .. import base

View File

@ -1,5 +1,5 @@
from . import eh_field_monitor
from . import field_power_flux_monitor
from . import eh_field_monitor, field_power_flux_monitor
# from . import epsilon_tensor_monitor
# from . import diffraction_monitor

View File

@ -1,18 +1,13 @@
import typing as typ
import functools
import bpy
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import numpy as np
import scipy as sc
import tidy3d as td
from .....utils import analyze_geonodes
from .....utils import extra_sympy_units as spux
from ... import contracts as ct
from ... import sockets
from ... import managed_objs
from ... import managed_objs, sockets
from .. import base
GEONODES_MONITOR_BOX = 'monitor_flux_box'

View File

@ -1,5 +1,4 @@
from . import viewer
from . import exporters
from . import exporters, viewer
BL_REGISTER = [
*viewer.BL_REGISTER,

View File

@ -1,5 +1,4 @@
from . import json_file_exporter
from . import tidy3d_web_exporter
from . import json_file_exporter, tidy3d_web_exporter
BL_REGISTER = [
*json_file_exporter.BL_REGISTER,

View File

@ -1,11 +1,9 @@
import typing as typ
import json
import typing as typ
from pathlib import Path
import bpy
import sympy as sp
import pydantic as pyd
import tidy3d as td
from .... import contracts as ct
from .... import sockets

View File

@ -1,9 +1,6 @@
from . import sim_domain
# from . import sim_grid
# from . import sim_grid_axes
from . import fdtd_sim
from . import fdtd_sim, sim_domain
BL_REGISTER = [
*sim_domain.BL_REGISTER,

View File

@ -1,6 +1,5 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import tidy3d as td
from ... import contracts as ct
from ... import sockets

View File

@ -1,13 +1,11 @@
import bpy
import sympy as sp
import sympy.physics.units as spu
import scipy as sc
from .....utils import analyze_geonodes
from ... import contracts as ct
from ... import sockets
from ... import managed_objs, sockets
from .. import base
from ... import managed_objs
GEONODES_DOMAIN_BOX = 'simdomain_box'

View File

@ -1,7 +1,9 @@
from . import automatic_sim_grid_axis
from . import manual_sim_grid_axis
from . import uniform_sim_grid_axis
from . import array_sim_grid_axis
from . import (
array_sim_grid_axis,
automatic_sim_grid_axis,
manual_sim_grid_axis,
uniform_sim_grid_axis,
)
BL_REGISTER = [
*automatic_sim_grid_axis.BL_REGISTER,

View File

@ -1,9 +1,6 @@
from . import temporal_shapes
from . import point_dipole_source
# from . import uniform_current_source
from . import plane_wave_source
from . import plane_wave_source, point_dipole_source, temporal_shapes
# from . import gaussian_beam_source
# from . import astigmatic_gaussian_beam_source
# from . import tfsf_source

View File

@ -1,16 +1,13 @@
import typing_extensions as typx
import math
import tidy3d as td
import bpy
import sympy as sp
import sympy.physics.units as spu
import bpy
import tidy3d as td
from .....utils import analyze_geonodes
from ... import managed_objs
from ... import contracts as ct
from ... import sockets
from ... import managed_objs, sockets
from .. import base
GEONODES_PLANE_WAVE = 'source_plane_wave'

View File

@ -1,14 +1,12 @@
import typing as typ
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import bpy
import sympy.physics.units as spu
import tidy3d as td
from ... import contracts as ct
from ... import sockets
from ... import managed_objs, sockets
from .. import base
from ... import managed_objs
class PointDipoleSourceNode(base.MaxwellSimNode):

View File

@ -1,4 +1,5 @@
from . import gaussian_pulse_temporal_shape
# from . import continuous_wave_temporal_shape
# from . import array_temporal_shape

View File

@ -1,9 +1,7 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import tidy3d as td
from .... import contracts
from .... import sockets
from .... import contracts, sockets
from ... import base

View File

@ -1,16 +1,13 @@
import typing as typ
import tidy3d as td
import numpy as np
import sympy as sp
import sympy.physics.units as spu
import bpy
import numpy as np
import sympy.physics.units as spu
import tidy3d as td
from ......utils import extra_sympy_units as spuex
from .... import contracts as ct
from .... import sockets
from .... import managed_objs
from .... import managed_objs, sockets
from ... import base

View File

@ -1,7 +1,5 @@
# from . import object_structure
from . import geonodes_structure
from . import primitives
from . import geonodes_structure, primitives
BL_REGISTER = [
# *object_structure.BL_REGISTER,

View File

@ -1,13 +1,9 @@
import tidy3d as td
import numpy as np
import sympy as sp
import sympy.physics.units as spu
import bpy
import bmesh
import bpy
import numpy as np
import tidy3d as td
from ... import contracts
from ... import sockets
from ... import contracts, sockets
from .. import base

View File

@ -1,7 +1,5 @@
from . import box_structure
# from . import cylinder_structure
from . import sphere_structure
from . import box_structure, sphere_structure
BL_REGISTER = [
*box_structure.BL_REGISTER,

View File

@ -1,9 +1,7 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import tidy3d as td
from .... import contracts
from .... import sockets
from .... import contracts, sockets
from ... import base

View File

@ -1,13 +1,10 @@
import tidy3d as td
import sympy as sp
import sympy.physics.units as spu
import bpy
import sympy.physics.units as spu
import tidy3d as td
from ......utils import analyze_geonodes
from .... import contracts as ct
from .... import sockets
from .... import managed_objs
from .... import managed_objs, sockets
from ... import base
GEONODES_STRUCTURE_SPHERE = 'structure_sphere'

View File

@ -1,5 +1,6 @@
# from . import math
from . import combine
# from . import separate
BL_REGISTER = [

View File

@ -1,8 +1,5 @@
import sympy as sp
import sympy.physics.units as spu
import scipy as sc
import bpy
import sympy as sp
from ... import contracts as ct
from ... import sockets

View File

@ -1,10 +1,8 @@
import tidy3d as td
import scipy as sc
import sympy as sp
import sympy.physics.units as spu
import scipy as sc
from .... import contracts
from .... import sockets
from .... import contracts, sockets
from ... import base

View File

@ -1,18 +1,10 @@
import typing as typ
import tidy3d as td
import numpy as np
import sympy as sp
import sympy.physics.units as spu
import bpy
from .....utils import analyze_geonodes
from ... import bl_socket_map
from ... import contracts as ct
from ... import sockets
from .. import base
from ... import managed_objs
from ... import managed_objs, sockets
from .. import base, events
CACHE = {}
@ -252,7 +244,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
####################
# - On Value Changed Methods
####################
@base.on_value_changed(
@events.on_value_changed(
socket_name='FDTD Sim Data',
managed_objs={'viz_object'},
input_sockets={'FDTD Sim Data'},
@ -275,7 +267,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
####################
# - Plotting
####################
@base.on_show_plot(
@events.on_show_plot(
managed_objs={'viz_plot'},
props={
'viz_monitor_name',
@ -330,7 +322,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
bl_select=True,
)
# @base.on_show_preview(
# @events.on_show_preview(
# managed_objs={"viz_object"},
# )
# def on_show_preview(

View File

@ -1,73 +1,35 @@
from . import base
from ....utils import logger
from .. import contracts as ct
from . import basic, blender, maxwell, number, physical, tidy3d, vector
from .scan_socket_defs import scan_for_socket_defs
from . import basic
log = logger.get(__name__)
sockets_modules = [basic, number, vector, physical, blender, maxwell, tidy3d]
AnySocketDef = basic.AnySocketDef
BoolSocketDef = basic.BoolSocketDef
StringSocketDef = basic.StringSocketDef
FilePathSocketDef = basic.FilePathSocketDef
####################
# - Scan for SocketDefs
####################
SOCKET_DEFS = {}
for sockets_module in sockets_modules:
SOCKET_DEFS |= scan_for_socket_defs(sockets_module)
from . import number
# Set Global Names from SOCKET_DEFS
## SOCKET_DEFS values are the classes themselves, which always have a __name__.
for socket_def_type in SOCKET_DEFS.values():
globals()[socket_def_type.__name__] = socket_def_type
IntegerNumberSocketDef = number.IntegerNumberSocketDef
RationalNumberSocketDef = number.RationalNumberSocketDef
RealNumberSocketDef = number.RealNumberSocketDef
ComplexNumberSocketDef = number.ComplexNumberSocketDef
from . import vector
Real2DVectorSocketDef = vector.Real2DVectorSocketDef
Complex2DVectorSocketDef = vector.Complex2DVectorSocketDef
Integer3DVectorSocketDef = vector.Integer3DVectorSocketDef
Real3DVectorSocketDef = vector.Real3DVectorSocketDef
Complex3DVectorSocketDef = vector.Complex3DVectorSocketDef
from . import physical
PhysicalUnitSystemSocketDef = physical.PhysicalUnitSystemSocketDef
PhysicalTimeSocketDef = physical.PhysicalTimeSocketDef
PhysicalAngleSocketDef = physical.PhysicalAngleSocketDef
PhysicalLengthSocketDef = physical.PhysicalLengthSocketDef
PhysicalAreaSocketDef = physical.PhysicalAreaSocketDef
PhysicalVolumeSocketDef = physical.PhysicalVolumeSocketDef
PhysicalPoint3DSocketDef = physical.PhysicalPoint3DSocketDef
PhysicalSize3DSocketDef = physical.PhysicalSize3DSocketDef
PhysicalMassSocketDef = physical.PhysicalMassSocketDef
PhysicalSpeedSocketDef = physical.PhysicalSpeedSocketDef
PhysicalAccelScalarSocketDef = physical.PhysicalAccelScalarSocketDef
PhysicalForceScalarSocketDef = physical.PhysicalForceScalarSocketDef
PhysicalPolSocketDef = physical.PhysicalPolSocketDef
PhysicalFreqSocketDef = physical.PhysicalFreqSocketDef
from . import blender
BlenderMaterialSocketDef = blender.BlenderMaterialSocketDef
BlenderObjectSocketDef = blender.BlenderObjectSocketDef
BlenderCollectionSocketDef = blender.BlenderCollectionSocketDef
BlenderImageSocketDef = blender.BlenderImageSocketDef
BlenderGeoNodesSocketDef = blender.BlenderGeoNodesSocketDef
BlenderTextSocketDef = blender.BlenderTextSocketDef
from . import maxwell
MaxwellBoundCondSocketDef = maxwell.MaxwellBoundCondSocketDef
MaxwellBoundCondsSocketDef = maxwell.MaxwellBoundCondsSocketDef
MaxwellMediumSocketDef = maxwell.MaxwellMediumSocketDef
MaxwellMediumNonLinearitySocketDef = maxwell.MaxwellMediumNonLinearitySocketDef
MaxwellSourceSocketDef = maxwell.MaxwellSourceSocketDef
MaxwellTemporalShapeSocketDef = maxwell.MaxwellTemporalShapeSocketDef
MaxwellStructureSocketDef = maxwell.MaxwellStructureSocketDef
MaxwellMonitorSocketDef = maxwell.MaxwellMonitorSocketDef
MaxwellFDTDSimSocketDef = maxwell.MaxwellFDTDSimSocketDef
MaxwellFDTDSimDataSocketDef = maxwell.MaxwellFDTDSimDataSocketDef
MaxwellSimGridSocketDef = maxwell.MaxwellSimGridSocketDef
MaxwellSimGridAxisSocketDef = maxwell.MaxwellSimGridAxisSocketDef
MaxwellSimDomainSocketDef = maxwell.MaxwellSimDomainSocketDef
from . import tidy3d
Tidy3DCloudTaskSocketDef = tidy3d.Tidy3DCloudTaskSocketDef
# Validate SocketType -> SocketDef
## All SocketTypes should have a SocketDef
for socket_type in ct.SocketType:
if (
globals().get(socket_type.value.removesuffix('SocketType') + 'SocketDef')
is None
):
log.warning('Missing SocketDef for %s', socket_type.value)
####################
# - Exports
####################
BL_REGISTER = [
*basic.BL_REGISTER,
*number.BL_REGISTER,
@ -77,3 +39,13 @@ BL_REGISTER = [
*maxwell.BL_REGISTER,
*tidy3d.BL_REGISTER,
]
__all__ = [
'basic',
'number',
'vector',
'physical',
'blender',
'maxwell',
'tidy3d',
] + [socket_def_type.__name__ for socket_def_type in SOCKET_DEFS.values()]

View File

@ -1,11 +1,11 @@
import typing as typ
import typing_extensions as typx
import functools
import typing as typ
import bpy
import sympy as sp
import sympy.physics.units as spu
import typing_extensions as typx
from .. import contracts as ct
@ -180,7 +180,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked:
return False
if self.is_output:
msg = f"Tried to sync 'link add' on output socket"
msg = "Tried to sync 'link add' on output socket"
raise RuntimeError(msg)
self.trigger_action('value_changed')
@ -195,7 +195,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked:
return False
if self.is_output:
msg = f"Tried to sync 'link add' on output socket"
msg = "Tried to sync 'link add' on output socket"
raise RuntimeError(msg)
self.trigger_action('value_changed')
@ -359,7 +359,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Can be overridden if more specific logic is required.
"""
prev_value = self.value / self.unit * self.prev_unit
## After changing units, self.value is expressed in the wrong unit.
## - Therefore, we removing the new unit, and re-add the prev unit.
@ -398,7 +397,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
text: str,
) -> None:
"""Called by Blender to draw the socket UI."""
if self.is_output:
self.draw_output(context, layout, node, text)
else:
@ -455,8 +453,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked:
row = col.row(align=False)
row.enabled = False
else:
if self.locked:
elif self.locked:
row.enabled = False
# Value Column(s)
@ -495,11 +492,9 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Can be overridden.
"""
pass
def draw_value_list(self, col: bpy.types.UILayout) -> None:
"""Called to draw the value list column in unlinked input sockets.
Can be overridden.
"""
pass

View File

@ -1,18 +1,11 @@
from . import any as any_socket
from . import bool as bool_socket
from . import file_path, string
AnySocketDef = any_socket.AnySocketDef
from . import bool as bool_socket
BoolSocketDef = bool_socket.BoolSocketDef
from . import string
StringSocketDef = string.StringSocketDef
from . import file_path
FilePathSocketDef = file_path.FilePathSocketDef
StringSocketDef = string.StringSocketDef
BL_REGISTER = [

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,11 +1,9 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,10 @@
import typing as typ
from pathlib import Path
import bpy
import sympy as sp
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################
@ -51,7 +49,7 @@ class FilePathBLSocket(base.MaxwellSimSocket):
class FilePathSocketDef(pyd.BaseModel):
socket_type: ct.SocketType = ct.SocketType.FilePath
default_path: Path = Path('')
default_path: Path = Path()
def init(self, bl_socket: FilePathBLSocket) -> None:
bl_socket.value = self.default_path

View File

@ -1,11 +1,9 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,10 +1,9 @@
import typing as typ
import bpy
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,10 +1,9 @@
import typing as typ
import bpy
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,10 +1,9 @@
import typing as typ
import bpy
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,19 +1,16 @@
from . import bound_cond
from . import bound_conds
from . import bound_cond, bound_conds
MaxwellBoundCondSocketDef = bound_cond.MaxwellBoundCondSocketDef
MaxwellBoundCondsSocketDef = bound_conds.MaxwellBoundCondsSocketDef
from . import medium
from . import medium_non_linearity
from . import medium, medium_non_linearity
MaxwellMediumSocketDef = medium.MaxwellMediumSocketDef
MaxwellMediumNonLinearitySocketDef = (
medium_non_linearity.MaxwellMediumNonLinearitySocketDef
)
from . import source
from . import temporal_shape
from . import source, temporal_shape
MaxwellSourceSocketDef = source.MaxwellSourceSocketDef
MaxwellTemporalShapeSocketDef = temporal_shape.MaxwellTemporalShapeSocketDef
@ -26,11 +23,7 @@ from . import monitor
MaxwellMonitorSocketDef = monitor.MaxwellMonitorSocketDef
from . import fdtd_sim
from . import fdtd_sim_data
from . import sim_grid
from . import sim_grid_axis
from . import sim_domain
from . import fdtd_sim, fdtd_sim_data, sim_domain, sim_grid, sim_grid_axis
MaxwellFDTDSimSocketDef = fdtd_sim.MaxwellFDTDSimSocketDef
MaxwellFDTDSimDataSocketDef = fdtd_sim_data.MaxwellFDTDSimDataSocketDef

View File

@ -1,12 +1,10 @@
import typing as typ
import typing_extensions as typx
import bpy
import pydantic as pyd
import tidy3d as td
import typing_extensions as typx
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellBoundCondBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,10 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
BOUND_FACE_ITEMS = [
('PML', 'PML', 'Perfectly matched layer'),

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellFDTDSimBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellFDTDSimDataBLSocket(base.MaxwellSimSocket):

View File

@ -1,15 +1,13 @@
import typing as typ
import bpy
import pydantic as pyd
import sympy as sp
import scipy as sc
import sympy.physics.units as spu
import tidy3d as td
import scipy as sc
from .....utils.pydantic_sympy import ConstrSympyExpr, Complex
from .. import base
from .....utils.pydantic_sympy import ConstrSympyExpr
from ... import contracts as ct
from .. import base
VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second
@ -93,7 +91,6 @@ class MaxwellMediumBLSocket(base.MaxwellSimSocket):
def sync_unit_change(self):
"""Override unit change to only alter frequency unit."""
self.value = (
self.wl * self.prev_unit,
complex(*self.rel_permittivity),

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellMediumNonLinearityBLSocket(base.MaxwellSimSocket):

View File

@ -1,13 +1,8 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import tidy3d as td
import scipy as sc
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellMonitorBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellSimDomainBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,10 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellSimGridBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellSimGridAxisBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellSourceBLSocket(base.MaxwellSimSocket):

View File

@ -1,10 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellStructureBLSocket(base.MaxwellSimSocket):

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct
from .. import base
class MaxwellTemporalShapeBLSocket(base.MaxwellSimSocket):

View File

@ -1,12 +1,12 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
import sympy as sp
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################
@ -75,7 +75,6 @@ class ComplexNumberBLSocket(base.MaxwellSimSocket):
Returns:
The sympy expression representing the complex number.
"""
v1, v2 = self.raw_value
return {
@ -91,7 +90,6 @@ class ComplexNumberBLSocket(base.MaxwellSimSocket):
- Cartesian: a,b -> a + ib
- Polar: r,t -> re^(it)
"""
self.raw_value = {
'CARTESIAN': (sp.re(value), sp.im(value)),
'POLAR': (sp.Abs(value), sp.arg(value)),

View File

@ -1,10 +1,9 @@
import typing as typ
import bpy
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
import sympy as sp
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,10 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -10,9 +10,7 @@ from . import angle
PhysicalAngleSocketDef = angle.PhysicalAngleSocketDef
from . import length
from . import area
from . import volume
from . import area, length, volume
PhysicalLengthSocketDef = length.PhysicalLengthSocketDef
PhysicalAreaSocketDef = area.PhysicalAreaSocketDef
@ -30,9 +28,7 @@ from . import mass
PhysicalMassSocketDef = mass.PhysicalMassSocketDef
from . import speed
from . import accel_scalar
from . import force_scalar
from . import accel_scalar, force_scalar, speed
PhysicalSpeedSocketDef = speed.PhysicalSpeedSocketDef
PhysicalAccelScalarSocketDef = accel_scalar.PhysicalAccelScalarSocketDef

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,13 +1,11 @@
import typing as typ
import bpy
import sympy as sp
import sympy.physics.units as spu
import pydantic as pyd
import sympy as sp
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
class PhysicalAreaBLSocket(base.MaxwellSimSocket):
@ -43,7 +41,6 @@ class PhysicalAreaBLSocket(base.MaxwellSimSocket):
Returns:
The area as a sympy expression (with units).
"""
return self.raw_value * self.unit
@default_value.setter
@ -52,7 +49,6 @@ class PhysicalAreaBLSocket(base.MaxwellSimSocket):
unit conversions to normalize the input value to the selected
units.
"""
self.raw_value = self.value_as_unit(value)

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,16 +1,13 @@
import typing as typ
import json
import numpy as np
import bpy
import sympy as sp
import sympy.physics.units as spu
import numpy as np
import pydantic as pyd
import sympy.physics.units as spu
from .....utils import extra_sympy_units as spux
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,13 +1,12 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import numpy as np
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,13 +1,13 @@
import typing as typ
import bpy
import pydantic as pyd
import sympy as sp
import sympy.physics.units as spu
import pydantic as pyd
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
class PhysicalPoint3DBLSocket(base.MaxwellSimSocket):

View File

@ -1,14 +1,13 @@
import typing as typ
import bpy
import sympy as sp
import sympy.physics.units as spu
import sympy.physics.optics.polarization as spo_pol
import pydantic as pyd
import sympy as sp
import sympy.physics.optics.polarization as spo_pol
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
StokesVector = SympyExpr

View File

@ -1,13 +1,12 @@
import typing as typ
import bpy
import pydantic as pyd
import sympy as sp
import sympy.physics.units as spu
import pydantic as pyd
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
class PhysicalSize3DBLSocket(base.MaxwellSimSocket):

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,12 @@
import typing as typ
import bpy
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,4 +1,3 @@
import bpy
import pydantic as pyd
@ -7,6 +6,8 @@ from ... import contracts as ct
from .. import base
ST = ct.SocketType
def SU(socket_type): # noqa: N802, D103
return ct.SOCKET_UNITS[socket_type]['values']
@ -45,9 +46,7 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket):
name='Show Unit System Definition',
description='Toggle to show unit system definition',
default=False,
update=(
lambda self, context: self.sync_prop('show_definition', context)
),
update=(lambda self, context: self.sync_prop('show_definition', context)),
)
unit_time: bpy.props.EnumProperty(
@ -93,18 +92,14 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket):
description='Unit of 2D points',
items=contract_units_to_items(ST.PhysicalPoint2D),
default=default_unit_key_for(ST.PhysicalPoint2D),
update=(
lambda self, context: self.sync_prop('unit_point_2d', context)
),
update=(lambda self, context: self.sync_prop('unit_point_2d', context)),
)
unit_point_3d: bpy.props.EnumProperty(
name='Point3D Unit',
description='Unit of 3D points',
items=contract_units_to_items(ST.PhysicalPoint3D),
default=default_unit_key_for(ST.PhysicalPoint3D),
update=(
lambda self, context: self.sync_prop('unit_point_3d', context)
),
update=(lambda self, context: self.sync_prop('unit_point_3d', context)),
)
unit_size_2d: bpy.props.EnumProperty(
@ -142,36 +137,28 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket):
description='Unit of acceleration',
items=contract_units_to_items(ST.PhysicalAccelScalar),
default=default_unit_key_for(ST.PhysicalAccelScalar),
update=(
lambda self, context: self.sync_prop('unit_accel_scalar', context)
),
update=(lambda self, context: self.sync_prop('unit_accel_scalar', context)),
)
unit_force_scalar: bpy.props.EnumProperty(
name='Force Scalar Unit',
description='Unit of scalar force',
items=contract_units_to_items(ST.PhysicalForceScalar),
default=default_unit_key_for(ST.PhysicalForceScalar),
update=(
lambda self, context: self.sync_prop('unit_force_scalar', context)
),
update=(lambda self, context: self.sync_prop('unit_force_scalar', context)),
)
unit_accel_3d: bpy.props.EnumProperty(
name='Accel3D Unit',
description='Unit of 3D vector acceleration',
items=contract_units_to_items(ST.PhysicalAccel3D),
default=default_unit_key_for(ST.PhysicalAccel3D),
update=(
lambda self, context: self.sync_prop('unit_accel_3d', context)
),
update=(lambda self, context: self.sync_prop('unit_accel_3d', context)),
)
unit_force_3d: bpy.props.EnumProperty(
name='Force3D Unit',
description='Unit of 3D vector force',
items=contract_units_to_items(ST.PhysicalForce3D),
default=default_unit_key_for(ST.PhysicalForce3D),
update=(
lambda self, context: self.sync_prop('unit_force_3d', context)
),
update=(lambda self, context: self.sync_prop('unit_force_3d', context)),
)
unit_freq: bpy.props.EnumProperty(
@ -187,9 +174,7 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket):
####################
def draw_label_row(self, row: bpy.types.UILayout, text) -> None:
row.label(text=text)
row.prop(
self, 'show_definition', toggle=True, text='', icon='MOD_LENGTH'
)
row.prop(self, 'show_definition', toggle=True, text='', icon='MOD_LENGTH')
def draw_value(self, col: bpy.types.UILayout) -> None:
if self.show_definition:
@ -263,7 +248,8 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket):
@property
def value(self) -> dict[ST, SympyExpr]:
return {
socket_type: SU(socket_type)[socket_unit_prop] for socket_type, socket_unit_prop in [
socket_type: SU(socket_type)[socket_unit_prop]
for socket_type, socket_unit_prop in [
(ST.PhysicalTime, self.unit_time),
(ST.PhysicalAngle, self.unit_angle),
(ST.PhysicalLength, self.unit_length),

View File

@ -1,13 +1,11 @@
import typing as typ
import bpy
import sympy as sp
import sympy.physics.units as spu
import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct
from .. import base
class PhysicalVolumeBLSocket(base.MaxwellSimSocket):

View File

@ -0,0 +1,21 @@
import types
import typing as typ
from .. import contracts as ct
def scan_for_socket_defs(
sockets_module: types.ModuleType,
) -> dict[ct.SocketType, typ.Type[ct.schemas.SocketDef]]:
return {
socket_type: getattr(
sockets_module,
socket_type.value.removesuffix('SocketType') + 'SocketDef',
)
for socket_type in ct.SocketType
if hasattr(
sockets_module, socket_type.value.removesuffix('SocketType') + 'SocketDef'
)
}
## TODO: Function for globals() filling too.

View File

@ -89,17 +89,13 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
name='Folder of Cloud Tasks',
description='An existing folder on the Tidy3D Cloud',
items=lambda self, _: self.retrieve_folders(),
update=(
lambda self, context: self.sync_prop('existing_folder_id', context)
),
update=(lambda self, context: self.sync_prop('existing_folder_id', context)),
)
existing_task_id: bpy.props.EnumProperty(
name='Existing Cloud Task',
description='An existing task on the Tidy3D Cloud, within the given folder',
items=lambda self, _: self.retrieve_tasks(),
update=(
lambda self, context: self.sync_prop('existing_task_id', context)
),
update=(lambda self, context: self.sync_prop('existing_task_id', context)),
)
# (Potential) New Task
@ -107,9 +103,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
name='New Cloud Task Name',
description='Name of a new task to submit to the Tidy3D Cloud',
default='',
update=(
lambda self, context: self.sync_prop('new_task_name', context)
),
update=(lambda self, context: self.sync_prop('new_task_name', context)),
)
####################
@ -158,9 +152,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
[
task.taskName,
'('
+ task.created_at.astimezone().strftime(
'%y-%m-%d @ %H:%M %Z'
)
+ task.created_at.astimezone().strftime('%y-%m-%d @ %H:%M %Z')
+ ')',
]
),
@ -205,9 +197,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
"""
# Propagate along Link
if self.is_linked:
msg = (
'Cannot sync newly created task to linked Cloud Task socket.'
)
msg = 'Cannot sync newly created task to linked Cloud Task socket.'
raise ValueError(msg)
## TODO: A little aggressive. Is there a good use case?
@ -223,9 +213,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
"""
# Propagate along Link
if self.is_linked:
msg = (
'Cannot sync newly created task to linked Cloud Task socket.'
)
msg = 'Cannot sync newly created task to linked Cloud Task socket.'
raise ValueError(msg)
## TODO: A little aggressive. Is there a good use case?
@ -238,9 +226,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
def draw_label_row(self, row: bpy.types.UILayout, text: str):
row.label(text=text)
auth_icon = (
'LOCKVIEW_ON' if tdcloud.IS_AUTHENTICATED else 'LOCKVIEW_OFF'
)
auth_icon = 'LOCKVIEW_ON' if tdcloud.IS_AUTHENTICATED else 'LOCKVIEW_OFF'
row.operator(
Authenticate.bl_idname,
text='',
@ -299,11 +285,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket):
@property
def value(
self,
) -> (
tuple[tdcloud.CloudTaskName, tdcloud.CloudFolder]
| tdcloud.CloudTask
| None
):
) -> tuple[tdcloud.CloudTaskName, tdcloud.CloudFolder] | tdcloud.CloudTask | None:
# Retrieve Folder
## Authentication is presumed OK
if (

View File

@ -1,12 +1,9 @@
from . import real_2d_vector
from . import complex_2d_vector
from . import complex_2d_vector, real_2d_vector
Real2DVectorSocketDef = real_2d_vector.Real2DVectorSocketDef
Complex2DVectorSocketDef = complex_2d_vector.Complex2DVectorSocketDef
from . import integer_3d_vector
from . import real_3d_vector
from . import complex_3d_vector
from . import complex_3d_vector, integer_3d_vector, real_3d_vector
Integer3DVectorSocketDef = integer_3d_vector.Integer3DVectorSocketDef
Real3DVectorSocketDef = real_3d_vector.Real3DVectorSocketDef

View File

@ -1,9 +1,8 @@
import typing as typ
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,9 +1,8 @@
import typing as typ
import pydantic as pyd
from .. import base
from ... import contracts as ct
from .. import base
####################

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy
import sympy as sp
import pydantic as pyd
import sympy as sp
from .....utils.pydantic_sympy import ConstrSympyExpr
from .. import base
from ... import contracts as ct
from .. import base
Integer3DVector = ConstrSympyExpr(
allow_variables=False,

Some files were not shown because too many files have changed in this diff Show More