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. ## requirements.lock is written when packing the .zip.
## By default, the addon pydeps are kept in the addon dir. ## 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 # - 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. ## By configuring this in __init__.py, we guarantee it for all subimports.
## (Unless, elsewhere, this setting is changed. Be careful!) ## (Unless, elsewhere, this setting is changed. Be careful!)
from . import sockets from . import categories, node_tree, nodes, sockets
from . import node_tree
from . import nodes
from . import categories
BL_REGISTER = [ BL_REGISTER = [
*sockets.BL_REGISTER, *sockets.BL_REGISTER,

View File

@ -1,7 +1,6 @@
"""Tools for translating between BLMaxwell sockets and pure Blender sockets. """Tools for translating between BLMaxwell sockets and pure Blender sockets.
Attributes: 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_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. 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 extra_sympy_units as spux
from ...utils import logger as _logger from ...utils import logger as _logger
from . import contracts as ct from . import contracts as ct
from . import sockets as sck from . import sockets
from .contracts import SocketType as ST # noqa: N817
log = _logger.get(__name__) log = _logger.get(__name__)
@ -25,26 +23,7 @@ BLSocketValue: typ.TypeAlias = typ.Any ## A Blender Socket Value
BLSocketSize: typ.TypeAlias = int BLSocketSize: typ.TypeAlias = int
DescType: typ.TypeAlias = str DescType: typ.TypeAlias = str
Unit: typ.TypeAlias = typ.Any ## Type of a valid unit Unit: typ.TypeAlias = typ.Any ## Type of a valid unit
## TODO: Move this kind of thing to contracts
####################
# - 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)
#################### ####################
@ -96,7 +75,7 @@ def _size_from_bl_socket(
def _socket_type_from_bl_socket( def _socket_type_from_bl_socket(
description: str, description: str,
bl_socket_type: BLSocketType, 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. """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: Arguments:
@ -141,8 +120,8 @@ def _socket_type_from_bl_socket(
def _socket_def_from_bl_socket( def _socket_def_from_bl_socket(
description: str, description: str,
bl_socket_type: BLSocketType, bl_socket_type: BLSocketType,
) -> ST: ) -> ct.SocketType:
return SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)] return sockets.SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)]
def socket_def_from_bl_socket( def socket_def_from_bl_socket(
@ -252,7 +231,6 @@ def writable_bl_socket_value(
Returns: 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. 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( return _writable_bl_socket_value(
bl_interface_socket.description, bl_interface_socket.description,

View File

@ -2,6 +2,7 @@
import bpy import bpy
import nodeitems_utils import nodeitems_utils
from . import contracts as ct from . import contracts as ct
from .nodes import BL_NODES 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 from .socket_types import SocketType as ST

View File

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

View File

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

View File

@ -1,12 +1,10 @@
import typing as typ
import typing_extensions as typx
import io import io
import typing as typ
import numpy as np
import pydantic as pyd
import matplotlib.axis as mpl_ax
import bpy import bpy
import matplotlib.axis as mpl_ax
import numpy as np
import typing_extensions as typx
from .. import contracts as ct from .. import contracts as ct
@ -161,7 +159,7 @@ class ManagedBLImage(ct.schemas.ManagedObj):
height_px = int(_height_inches * _dpi) height_px = int(_height_inches * _dpi)
else: 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) raise ValueError(msg)
# Compute Plot Dimensions # Compute Plot Dimensions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,22 +1,20 @@
import bpy import typing as typ
import sympy as sp import sympy as sp
import sympy.physics.units as spu import sympy.physics.units as spu
import scipy as sc
from .....utils import extra_sympy_units as spux from .....utils import extra_sympy_units as spux
from .....utils import sci_constants as constants
from ... import contracts as ct from ... import contracts as ct
from ... import sockets from ... import sockets
from .. import base from .. import base
VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second
class WaveConstantNode(base.MaxwellSimNode): class WaveConstantNode(base.MaxwellSimNode):
node_type = ct.NodeType.WaveConstant node_type = ct.NodeType.WaveConstant
bl_label = 'Wave Constant' bl_label = 'Wave Constant'
input_socket_sets = { input_socket_sets: typ.ClassVar = {
# Single # Single
'Vacuum WL': { 'Vacuum WL': {
'WL': sockets.PhysicalLengthSocketDef( 'WL': sockets.PhysicalLengthSocketDef(
@ -44,7 +42,7 @@ class WaveConstantNode(base.MaxwellSimNode):
} }
#################### ####################
# - Callbacks # - Event Methods: Listy Output
#################### ####################
@base.computes_output_socket( @base.computes_output_socket(
'WL', 'WL',
@ -53,14 +51,11 @@ class WaveConstantNode(base.MaxwellSimNode):
def compute_vac_wl(self, input_sockets: dict) -> sp.Expr: def compute_vac_wl(self, input_sockets: dict) -> sp.Expr:
if (vac_wl := input_sockets['WL']) is not None: if (vac_wl := input_sockets['WL']) is not None:
return vac_wl 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: msg = 'Vac WL and Freq are both None'
return spu.convert_to( raise RuntimeError(msg)
VAC_SPEED_OF_LIGHT / freq,
spu.meter,
)
raise RuntimeError('Vac WL and Freq are both None')
@base.computes_output_socket( @base.computes_output_socket(
'Freq', 'Freq',
@ -68,17 +63,15 @@ class WaveConstantNode(base.MaxwellSimNode):
) )
def compute_freq(self, input_sockets: dict) -> sp.Expr: def compute_freq(self, input_sockets: dict) -> sp.Expr:
if (vac_wl := input_sockets['WL']) is not None: if (vac_wl := input_sockets['WL']) is not None:
return spu.convert_to( return constants.vac_speed_of_light / vac_wl
VAC_SPEED_OF_LIGHT / vac_wl, if (freq := input_sockets['Freq']) is not None:
spu.hertz,
)
elif (freq := input_sockets['Freq']) is not None:
return freq 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( @base.computes_output_socket(
'WLs', 'WLs',
@ -87,16 +80,11 @@ class WaveConstantNode(base.MaxwellSimNode):
def compute_vac_wls(self, input_sockets: dict) -> sp.Expr: def compute_vac_wls(self, input_sockets: dict) -> sp.Expr:
if (vac_wls := input_sockets['WLs']) is not None: if (vac_wls := input_sockets['WLs']) is not None:
return vac_wls return vac_wls
elif (freqs := input_sockets['Freqs']) is not None: if (freqs := input_sockets['Freqs']) is not None:
return [ return [constants.vac_speed_of_light / freq for freq in freqs][::-1]
spu.convert_to(
VAC_SPEED_OF_LIGHT / freq,
spu.meter,
)
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( @base.computes_output_socket(
'Freqs', 'Freqs',
@ -104,25 +92,18 @@ class WaveConstantNode(base.MaxwellSimNode):
) )
def compute_freqs(self, input_sockets: dict) -> sp.Expr: def compute_freqs(self, input_sockets: dict) -> sp.Expr:
if (vac_wls := input_sockets['WLs']) is not None: if (vac_wls := input_sockets['WLs']) is not None:
return [ return [constants.vac_speed_of_light / vac_wl for vac_wl in vac_wls][::-1]
spu.convert_to( if (freqs := input_sockets['Freqs']) is not None:
VAC_SPEED_OF_LIGHT / vac_wl,
spu.hertz,
)
for vac_wl in vac_wls
][::-1]
elif (freqs := input_sockets['Freqs']) is not None:
return freqs 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( @base.on_value_changed(prop_name='active_socket_set', props={'active_socket_set'})
prop_name='active_socket_set', props={'active_socket_set'} def on_active_socket_set_changed(self, props: dict):
)
def on_value_changed__active_socket_set(self, props: dict):
# Singular: Normal Output Sockets # Singular: Normal Output Sockets
if props['active_socket_set'] in {'Vacuum WL', 'Frequency'}: if props['active_socket_set'] in {'Vacuum WL', 'Frequency'}:
self.loose_output_sockets = {} self.loose_output_sockets = {}
@ -145,7 +126,7 @@ class WaveConstantNode(base.MaxwellSimNode):
@base.on_init() @base.on_init()
def on_init(self): 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 tempfile
import typing as typ
from pathlib import Path from pathlib import Path
import tidy3d as td import tidy3d as td
import tidy3d.web as td_web
from ...... import info
from ......services import tdcloud from ......services import tdcloud
from .... import contracts as ct from .... import contracts as ct
from .... import sockets from .... import sockets
from ... import base 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 node_type = ct.NodeType.Tidy3DWebImporter
bl_label = 'Tidy3D Web Importer' bl_label = 'Tidy3D Web Importer'
input_sockets = { input_sockets: typ.ClassVar = {
'Cloud Task': sockets.Tidy3DCloudTaskSocketDef( 'Cloud Task': sockets.Tidy3DCloudTaskSocketDef(
should_exist=True, should_exist=True,
), ),
'Cache Path': sockets.FilePathSocketDef(
default_path=Path('loaded_simulation.hdf5')
),
} }
#################### ####################
# - Output Methods # - Event Methods
#################### ####################
@base.computes_output_socket( @base.computes_output_socket(
'FDTD Sim Data', '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'}, input_sockets={'Cloud Task'},
) )
def compute_fdtd_sim(self, input_sockets: dict) -> str: def compute_sim_data(self, input_sockets: dict) -> str:
if not isinstance( # Validate Task Availability
cloud_task := input_sockets['Cloud Task'], tdcloud.CloudTask if (cloud_task := input_sockets['Cloud Task']) is None:
): msg = f'"{self.bl_label}" CloudTask doesn\'t exist'
msg = 'Input cloud task does not exist'
raise RuntimeError(msg) raise RuntimeError(msg)
# Load the Simulation # Validate Task Existence
with tempfile.NamedTemporaryFile(delete=False) as f: if not isinstance(cloud_task, tdcloud.CloudTask):
_path_tmp = Path(f.name) msg = f'"{self.bl_label}" CloudTask input "{cloud_task}" has wrong "should_exists", as it isn\'t an instance of tdcloud.CloudTask'
_path_tmp.rename(f.name + '.json') raise TypeError(msg)
path_tmp = Path(f.name + '.json')
sim = td_web.api.webapi.load_simulation( # Validate Task Status
cloud_task.task_id, if cloud_task.status != 'success':
path=str(path_tmp), msg = f'"{self.bl_label}" CloudTask is "{cloud_task.status}", not "success"'
) ## TODO: Don't use td_web directly. Only through tdcloud raise RuntimeError(msg)
Path(path_tmp).unlink()
return sim # Download and Return SimData
return tdcloud.TidyCloudTasks.download_task_sim_data(
#################### cloud_task, _sim_data_cache_path(cloud_task.task_id)
# - Update
####################
@base.on_value_changed(
socket_name='Cloud Task', input_sockets={'Cloud Task'}
) )
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 ( if (
(cloud_task := input_sockets['Cloud Task']) is not None (cloud_task := input_sockets['Cloud Task']) is not None
and isinstance(cloud_task, tdcloud.CloudTask) and isinstance(cloud_task, tdcloud.CloudTask)
@ -107,15 +70,13 @@ class Tidy3DWebImporterNode(base.MaxwellSimNode):
): ):
self.loose_output_sockets = { self.loose_output_sockets = {
'FDTD Sim Data': sockets.MaxwellFDTDSimDataSocketDef(), 'FDTD Sim Data': sockets.MaxwellFDTDSimDataSocketDef(),
'FDTD Sim': sockets.MaxwellFDTDSimSocketDef(),
} }
return else:
self.loose_output_sockets = {} self.loose_output_sockets = {}
@base.on_init() @base.on_init()
def on_init(self): def on_init(self):
self.on_value_changed__cloud_task() self.on_cloud_task_changed()
#################### ####################
@ -125,7 +86,5 @@ BL_REGISTER = [
Tidy3DWebImporterNode, Tidy3DWebImporterNode,
] ]
BL_NODES = { BL_NODES = {
ct.NodeType.Tidy3DWebImporter: ( ct.NodeType.Tidy3DWebImporter: (ct.NodeCategory.MAXWELLSIM_INPUTS_IMPORTERS)
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 as sp
import sympy.physics.units as spu
from .. import contracts as ct from .. import contracts as ct
from .. import sockets from .. import sockets

View File

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

View File

@ -1,17 +1,14 @@
import typing as typ import typing as typ
import functools
import bpy import bpy
import tidy3d as td import scipy as sc
import sympy as sp import sympy as sp
import sympy.physics.units as spu import sympy.physics.units as spu
import numpy as np import tidy3d as td
import scipy as sc
from .....utils import extra_sympy_units as spuex from .....utils import extra_sympy_units as spuex
from ... import contracts as ct from ... import contracts as ct
from ... import sockets from ... import managed_objs, sockets
from ... import managed_objs
from .. import base from .. import base
VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second 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 (
from . import chi_3_susceptibility_non_linearity add_non_linearity,
from . import kerr_non_linearity chi_3_susceptibility_non_linearity,
from . import two_photon_absorption_non_linearity kerr_non_linearity,
two_photon_absorption_non_linearity,
)
BL_REGISTER = [ BL_REGISTER = [
*add_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 sympy.physics.units as spu
import tidy3d as td
from ... import contracts from ... import contracts, sockets
from ... import sockets
from .. import base from .. import base

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,9 @@
from . import automatic_sim_grid_axis from . import (
from . import manual_sim_grid_axis array_sim_grid_axis,
from . import uniform_sim_grid_axis automatic_sim_grid_axis,
from . import array_sim_grid_axis manual_sim_grid_axis,
uniform_sim_grid_axis,
)
BL_REGISTER = [ BL_REGISTER = [
*automatic_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 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 gaussian_beam_source
# from . import astigmatic_gaussian_beam_source # from . import astigmatic_gaussian_beam_source
# from . import tfsf_source # from . import tfsf_source

View File

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

View File

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

View File

@ -1,4 +1,5 @@
from . import gaussian_pulse_temporal_shape from . import gaussian_pulse_temporal_shape
# from . import continuous_wave_temporal_shape # from . import continuous_wave_temporal_shape
# from . import array_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 sympy.physics.units as spu
import tidy3d as td
from .... import contracts from .... import contracts, sockets
from .... import sockets
from ... import base from ... import base

View File

@ -1,16 +1,13 @@
import typing as typ 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 bpy
import numpy as np
import sympy.physics.units as spu
import tidy3d as td
from ......utils import extra_sympy_units as spuex from ......utils import extra_sympy_units as spuex
from .... import contracts as ct from .... import contracts as ct
from .... import sockets from .... import managed_objs, sockets
from .... import managed_objs
from ... import base from ... import base

View File

@ -1,7 +1,5 @@
# from . import object_structure # from . import object_structure
from . import geonodes_structure from . import geonodes_structure, primitives
from . import primitives
BL_REGISTER = [ BL_REGISTER = [
# *object_structure.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 bmesh
import bpy
import numpy as np
import tidy3d as td
from ... import contracts from ... import contracts, sockets
from ... import sockets
from .. import base from .. import base

View File

@ -1,7 +1,5 @@
from . import box_structure
# from . import cylinder_structure # from . import cylinder_structure
from . import sphere_structure from . import box_structure, sphere_structure
BL_REGISTER = [ BL_REGISTER = [
*box_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 sympy.physics.units as spu
import tidy3d as td
from .... import contracts from .... import contracts, sockets
from .... import sockets
from ... import base 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 bpy
import sympy.physics.units as spu
import tidy3d as td
from ......utils import analyze_geonodes from ......utils import analyze_geonodes
from .... import contracts as ct from .... import contracts as ct
from .... import sockets from .... import managed_objs, sockets
from .... import managed_objs
from ... import base from ... import base
GEONODES_STRUCTURE_SPHERE = 'structure_sphere' GEONODES_STRUCTURE_SPHERE = 'structure_sphere'

View File

@ -1,5 +1,6 @@
# from . import math # from . import math
from . import combine from . import combine
# from . import separate # from . import separate
BL_REGISTER = [ 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 bpy
import sympy as sp
from ... import contracts as ct from ... import contracts as ct
from ... import sockets from ... import sockets

View File

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

View File

@ -1,18 +1,10 @@
import typing as typ 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 bpy
from .....utils import analyze_geonodes
from ... import bl_socket_map
from ... import contracts as ct from ... import contracts as ct
from ... import sockets from ... import managed_objs, sockets
from .. import base from .. import base, events
from ... import managed_objs
CACHE = {} CACHE = {}
@ -252,7 +244,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
#################### ####################
# - On Value Changed Methods # - On Value Changed Methods
#################### ####################
@base.on_value_changed( @events.on_value_changed(
socket_name='FDTD Sim Data', socket_name='FDTD Sim Data',
managed_objs={'viz_object'}, managed_objs={'viz_object'},
input_sockets={'FDTD Sim Data'}, input_sockets={'FDTD Sim Data'},
@ -275,7 +267,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
#################### ####################
# - Plotting # - Plotting
#################### ####################
@base.on_show_plot( @events.on_show_plot(
managed_objs={'viz_plot'}, managed_objs={'viz_plot'},
props={ props={
'viz_monitor_name', 'viz_monitor_name',
@ -330,7 +322,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode):
bl_select=True, bl_select=True,
) )
# @base.on_show_preview( # @events.on_show_preview(
# managed_objs={"viz_object"}, # managed_objs={"viz_object"},
# ) # )
# def on_show_preview( # 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 # - Scan for SocketDefs
StringSocketDef = basic.StringSocketDef ####################
FilePathSocketDef = basic.FilePathSocketDef 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 # Validate SocketType -> SocketDef
RationalNumberSocketDef = number.RationalNumberSocketDef ## All SocketTypes should have a SocketDef
RealNumberSocketDef = number.RealNumberSocketDef for socket_type in ct.SocketType:
ComplexNumberSocketDef = number.ComplexNumberSocketDef if (
globals().get(socket_type.value.removesuffix('SocketType') + 'SocketDef')
from . import vector is None
):
Real2DVectorSocketDef = vector.Real2DVectorSocketDef log.warning('Missing SocketDef for %s', socket_type.value)
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
####################
# - Exports
####################
BL_REGISTER = [ BL_REGISTER = [
*basic.BL_REGISTER, *basic.BL_REGISTER,
*number.BL_REGISTER, *number.BL_REGISTER,
@ -77,3 +39,13 @@ BL_REGISTER = [
*maxwell.BL_REGISTER, *maxwell.BL_REGISTER,
*tidy3d.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 functools
import typing as typ
import bpy import bpy
import sympy as sp import sympy as sp
import sympy.physics.units as spu import sympy.physics.units as spu
import typing_extensions as typx
from .. import contracts as ct from .. import contracts as ct
@ -180,7 +180,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked: if self.locked:
return False return False
if self.is_output: 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) raise RuntimeError(msg)
self.trigger_action('value_changed') self.trigger_action('value_changed')
@ -195,7 +195,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked: if self.locked:
return False return False
if self.is_output: 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) raise RuntimeError(msg)
self.trigger_action('value_changed') self.trigger_action('value_changed')
@ -359,7 +359,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Can be overridden if more specific logic is required. Can be overridden if more specific logic is required.
""" """
prev_value = self.value / self.unit * self.prev_unit prev_value = self.value / self.unit * self.prev_unit
## After changing units, self.value is expressed in the wrong unit. ## After changing units, self.value is expressed in the wrong unit.
## - Therefore, we removing the new unit, and re-add the prev unit. ## - Therefore, we removing the new unit, and re-add the prev unit.
@ -398,7 +397,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
text: str, text: str,
) -> None: ) -> None:
"""Called by Blender to draw the socket UI.""" """Called by Blender to draw the socket UI."""
if self.is_output: if self.is_output:
self.draw_output(context, layout, node, text) self.draw_output(context, layout, node, text)
else: else:
@ -455,8 +453,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
if self.locked: if self.locked:
row = col.row(align=False) row = col.row(align=False)
row.enabled = False row.enabled = False
else: elif self.locked:
if self.locked:
row.enabled = False row.enabled = False
# Value Column(s) # Value Column(s)
@ -495,11 +492,9 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Can be overridden. Can be overridden.
""" """
pass
def draw_value_list(self, col: bpy.types.UILayout) -> None: def draw_value_list(self, col: bpy.types.UILayout) -> None:
"""Called to draw the value list column in unlinked input sockets. """Called to draw the value list column in unlinked input sockets.
Can be overridden. Can be overridden.
""" """
pass

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,8 @@
import typing as typ
import bpy
import pydantic as pyd import pydantic as pyd
import tidy3d as td
from .. import base
from ... import contracts as ct from ... import contracts as ct
from .. import base
class MaxwellMediumNonLinearityBLSocket(base.MaxwellSimSocket): 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 pydantic as pyd
import tidy3d as td
import scipy as sc
from .. import base
from ... import contracts as ct from ... import contracts as ct
from .. import base
class MaxwellMonitorBLSocket(base.MaxwellSimSocket): class MaxwellMonitorBLSocket(base.MaxwellSimSocket):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,11 @@
import typing as typ
import bpy import bpy
import sympy.physics.units as spu
import pydantic as pyd import pydantic as pyd
import sympy.physics.units as spu
from .....utils.pydantic_sympy import SympyExpr from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct 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 bpy
import sympy as sp import numpy as np
import sympy.physics.units as spu
import pydantic as pyd import pydantic as pyd
import sympy.physics.units as spu
from .....utils import extra_sympy_units as spux from .....utils import extra_sympy_units as spux
from .....utils.pydantic_sympy import SympyExpr from .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct from ... import contracts as ct
from .. import base
#################### ####################

View File

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

View File

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

View File

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

View File

@ -1,14 +1,13 @@
import typing as typ
import bpy 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 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 .....utils.pydantic_sympy import SympyExpr
from .. import base
from ... import contracts as ct from ... import contracts as ct
from .. import base
StokesVector = SympyExpr StokesVector = SympyExpr

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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