morphopt 4.0.6__tar.gz → 4.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. {morphopt-4.0.6 → morphopt-4.0.7}/PKG-INFO +27 -1
  2. {morphopt-4.0.6 → morphopt-4.0.7}/README.md +26 -0
  3. {morphopt-4.0.6 → morphopt-4.0.7}/pyproject.toml +1 -1
  4. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/constants.py +4 -1
  5. morphopt-4.0.7/src/morphopt/opt_runner.py +164 -0
  6. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/controller.py +1 -1
  7. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/updaters.py +230 -76
  8. morphopt-4.0.7/src/morphopt/postprocess/__init__.py +56 -0
  9. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/postprocess/archive.py +1 -1
  10. morphopt-4.0.7/src/morphopt/postprocess/exports.py +440 -0
  11. morphopt-4.0.7/src/morphopt/postprocess/fields.py +508 -0
  12. morphopt-4.0.7/src/morphopt/postprocess/visualization.py +184 -0
  13. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/__init__.py +1 -1
  14. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/basefuncs.py +3 -1
  15. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/shapederivative.py +74 -12
  16. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/__init__.py +1 -1
  17. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/basefuncs.py +4 -2
  18. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/sensitivity.py +40 -6
  19. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/simpmaterial.py +12 -431
  20. morphopt-4.0.7/src/morphopt/simp/void_elements.py +430 -0
  21. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/__init__.py +3 -3
  22. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/app.py +8 -5
  23. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/cad.py +20 -19
  24. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/completion.py +56 -30
  25. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/definitions.py +53 -20
  26. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/devices.py +1 -0
  27. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/edit_history.py +19 -6
  28. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/editing.py +143 -40
  29. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/editor_routing.py +15 -4
  30. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/expressions.py +11 -3
  31. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/fields.py +14 -7
  32. morphopt-4.0.7/src/morphopt/ui/application/finite_element.py +300 -0
  33. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/load_cases.py +127 -36
  34. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/part_mesh.py +8 -4
  35. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/part_sets.py +84 -27
  36. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/quickstart.py +1 -1
  37. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/results.py +3 -1
  38. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/runs.py +52 -12
  39. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/updaters.py +132 -39
  40. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/validation.py +1 -1
  41. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/values.py +13 -2
  42. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/codegen/assets.py +1 -1
  43. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/launcher.py +10 -5
  44. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/locales/en-US.json +26 -1
  45. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/locales/zh-CN.json +26 -1
  46. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/mainwindow.py +30 -10
  47. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/__init__.py +4 -0
  48. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/objectives.py +34 -0
  49. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/registry.py +4 -0
  50. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/observe_panel.py +23 -17
  51. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/labels.py +39 -5
  52. morphopt-4.0.6/src/morphopt/ui/worker_environment.py → morphopt-4.0.7/src/morphopt/ui/processes.py +7 -3
  53. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/fonts.py +30 -11
  54. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/palette.py +18 -11
  55. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/stylesheet.py +1 -2
  56. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/themes/dark.py +8 -4
  57. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/themes/light.py +18 -5
  58. morphopt-4.0.7/src/morphopt/ui/theme/visualization.py +73 -0
  59. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/visualization/__init__.py +25 -24
  60. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/visualization/assets.py +6 -3
  61. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/visualization/geometry.py +20 -10
  62. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/visualization/loads.py +1 -4
  63. morphopt-4.0.7/src/morphopt/ui/visualization/rendering.py +61 -0
  64. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/visualization/scene.py +16 -4
  65. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/asset_browser.py +58 -29
  66. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/case_deletion.py +9 -2
  67. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/custom_classes.py +3 -1
  68. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/definition_actions.py +78 -31
  69. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/definition_manager.py +9 -4
  70. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/editor.py +1 -2
  71. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/file_dialogs.py +1 -3
  72. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/finite_element.py +26 -33
  73. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/font_settings.py +5 -2
  74. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/helper_editor.py +7 -6
  75. morphopt-4.0.7/src/morphopt/ui/widgets/history_export.py +342 -0
  76. morphopt-4.0.6/src/morphopt/ui/widgets/result_path.py → morphopt-4.0.7/src/morphopt/ui/widgets/labels.py +45 -3
  77. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/load_cases.py +79 -20
  78. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/model_tree.py +50 -20
  79. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/objective_editor.py +41 -18
  80. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/observation_pages.py +18 -96
  81. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/param_form.py +9 -1
  82. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/preview_renderer.py +30 -10
  83. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/quickstart.py +2 -4
  84. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/template_insert_dialog.py +1 -1
  85. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/updater_editor.py +9 -8
  86. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/viewer.py +13 -30
  87. morphopt-4.0.7/src/morphopt/ui/widgets/viewport.py +159 -0
  88. morphopt-4.0.7/src/morphopt/ui/widgets/visualization_settings.py +149 -0
  89. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/workspace_objective.py +40 -10
  90. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/workbench.py +16 -8
  91. morphopt-4.0.7/src/morphopt/ui/worker.py +92 -0
  92. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/utils/__init__.py +2 -0
  93. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/utils/gradient_check.py +7 -2
  94. {morphopt-4.0.6/src/morphopt/optcore → morphopt-4.0.7/src/morphopt/utils}/quadrature.py +5 -1
  95. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/PKG-INFO +27 -1
  96. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/SOURCES.txt +14 -23
  97. morphopt-4.0.6/src/morphopt/opt_runner.py +0 -103
  98. morphopt-4.0.6/src/morphopt/postprocess/__init__.py +0 -69
  99. morphopt-4.0.6/src/morphopt/postprocess/contours.py +0 -112
  100. morphopt-4.0.6/src/morphopt/postprocess/exporters.py +0 -174
  101. morphopt-4.0.6/src/morphopt/postprocess/fields.py +0 -361
  102. morphopt-4.0.6/src/morphopt/postprocess/history_gif.py +0 -121
  103. morphopt-4.0.6/src/morphopt/postprocess/native.py +0 -106
  104. morphopt-4.0.6/src/morphopt/postprocess/rendering.py +0 -85
  105. morphopt-4.0.6/src/morphopt/postprocess/surface_export.py +0 -133
  106. morphopt-4.0.6/src/morphopt/taskoptmization.py +0 -116
  107. morphopt-4.0.6/src/morphopt/ui/application/finite_element.py +0 -193
  108. morphopt-4.0.6/src/morphopt/ui/cad_worker.py +0 -28
  109. morphopt-4.0.6/src/morphopt/ui/fea_worker.py +0 -65
  110. morphopt-4.0.6/src/morphopt/ui/history_gif_worker.py +0 -19
  111. morphopt-4.0.6/src/morphopt/ui/surface_export_worker.py +0 -19
  112. morphopt-4.0.6/src/morphopt/ui/visualization/rendering.py +0 -42
  113. morphopt-4.0.6/src/morphopt/ui/widgets/elided_label.py +0 -47
  114. morphopt-4.0.6/src/morphopt/ui/widgets/history_gif_export.py +0 -241
  115. morphopt-4.0.6/src/morphopt/ui/widgets/language_selector.py +0 -43
  116. morphopt-4.0.6/src/morphopt/ui/widgets/surface_export.py +0 -165
  117. morphopt-4.0.6/src/morphopt/ui/widgets/theme_selector.py +0 -48
  118. morphopt-4.0.6/src/morphopt/ui/widgets/values.py +0 -33
  119. {morphopt-4.0.6 → morphopt-4.0.7}/setup.cfg +0 -0
  120. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/__init__.py +0 -0
  121. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/codesign/__init__.py +3 -3
  122. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/codesign/constraints.py +0 -0
  123. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/codesign/offset_boundary_part.py +0 -0
  124. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/codesign/update_offset_boundary_part.py +2 -2
  125. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/__init__.py +0 -0
  126. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/history.py +0 -0
  127. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/__init__.py +0 -0
  128. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/base_model_component.py +0 -0
  129. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/baseparam.py +0 -0
  130. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/__init__.py +0 -0
  131. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/base_component.py +0 -0
  132. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/body_force.py +0 -0
  133. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/boundary_condition.py +0 -0
  134. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/contact.py +0 -0
  135. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/couple.py +0 -0
  136. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/point_load.py +0 -0
  137. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/pressure.py +0 -0
  138. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/reference_point.py +0 -0
  139. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/fea/spring.py +0 -0
  140. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/feaparams.py +0 -0
  141. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/geometry.py +0 -0
  142. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/materials/__init__.py +0 -0
  143. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/materials/base_material.py +0 -0
  144. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/materials/homogeneous_material.py +0 -0
  145. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/materials/models.py +0 -0
  146. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/materialsparams.py +0 -0
  147. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/params.py +0 -0
  148. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/__init__.py +0 -0
  149. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/base_part.py +0 -0
  150. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/box_part.py +0 -0
  151. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/cad_part.py +0 -0
  152. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/fixed_part.py +0 -0
  153. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/modelparams/parts/inp_part.py +0 -0
  154. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/objfunc.py +0 -0
  155. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/protocal.py +1 -1
  156. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/optcore/solver.py +0 -0
  157. morphopt-4.0.6/src/morphopt/postprocess/context.py → morphopt-4.0.7/src/morphopt/postprocess/_runtime.py +0 -0
  158. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/__init__.py +0 -0
  159. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/boundary_part.py +0 -0
  160. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/boundarys.py +0 -0
  161. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/distancesurface.py +0 -0
  162. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/surfacefairness.py +0 -0
  163. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/objectivefuncs/volumemaximization.py +0 -0
  164. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/__init__.py +0 -0
  165. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/base_constraints.py +0 -0
  166. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/base_surface.py +0 -0
  167. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/brep_surface.py +0 -0
  168. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/bsp_constraints.py +0 -0
  169. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/bsp_surface.py +0 -0
  170. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/cpgeo_constraints.py +0 -0
  171. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/cpgeo_surface.py +0 -0
  172. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/mesh_surface.py +0 -0
  173. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/surfaces/nurbs_face.py +0 -0
  174. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/shapeopt/update_boundary_part.py +0 -0
  175. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/__init__.py +0 -0
  176. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/boundarys.py +0 -0
  177. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/densityfield.py +0 -0
  178. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/objectivefuncs/volfrac.py +0 -0
  179. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/simp/update_simpmaterial.py +0 -0
  180. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/__main__.py +0 -0
  181. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application/__init__.py +0 -0
  182. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/application_icon.py +0 -0
  183. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/assets/morphopt.svg +0 -0
  184. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/codegen/__init__.py +0 -0
  185. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/codegen/custom_classes.py +0 -0
  186. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/codegen/generator.py +0 -0
  187. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/codegen/workspace.py +0 -0
  188. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/i18n.py +0 -0
  189. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/__init__.py +0 -0
  190. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/base_nodes.py +0 -0
  191. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/chamberlayout.py +0 -0
  192. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/configuration.py +0 -0
  193. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/fields.py +0 -0
  194. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/loaders.py +0 -0
  195. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/material_models.py +0 -0
  196. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/cad.py +0 -0
  197. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/custom_code.py +0 -0
  198. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/loads.py +0 -0
  199. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/materials.py +0 -0
  200. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/parts.py +0 -0
  201. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/penalties.py +0 -0
  202. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/structural.py +0 -0
  203. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/surfaces.py +0 -0
  204. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/node_types/symmetry.py +0 -0
  205. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/model/problem.py +0 -0
  206. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/__init__.py +0 -0
  207. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/edit_history.py +0 -0
  208. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/history.py +0 -0
  209. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/navigation.py +0 -0
  210. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/presentation/result_fields.py +0 -0
  211. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/refresh.py +0 -0
  212. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/schemes/__init__.py +0 -0
  213. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/schemes/base.py +0 -0
  214. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/schemes/snippets.py +0 -0
  215. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/__init__.py +0 -0
  216. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/manager.py +1 -1
  217. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/styles/__init__.py +0 -0
  218. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/styles/base.qss +0 -0
  219. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/styles/controls.qss +0 -0
  220. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/styles/inputs.qss +0 -0
  221. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/theme/themes/__init__.py +0 -0
  222. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/__init__.py +0 -0
  223. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/codeeditor.py +1 -1
  224. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/collection_controls.py +0 -0
  225. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/controller_editor.py +0 -0
  226. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/edit_history.py +0 -0
  227. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/editor_pages.py +0 -0
  228. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/history_dialogs.py +0 -0
  229. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/part_set_list.py +0 -0
  230. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/run_dialogs.py +0 -0
  231. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/solver_editor.py +0 -0
  232. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/ui/widgets/source_view.py +0 -0
  233. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt/utils/history_read.py +0 -0
  234. {morphopt-4.0.6/src/morphopt → morphopt-4.0.7/src/morphopt/utils}/paths.py +0 -0
  235. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/dependency_links.txt +0 -0
  236. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/entry_points.txt +0 -0
  237. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/requires.txt +0 -0
  238. {morphopt-4.0.6 → morphopt-4.0.7}/src/morphopt.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: morphopt
3
- Version: 4.0.6
3
+ Version: 4.0.7
4
4
  Summary: A morphing optimization framework using PyTorch and torchfea.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -80,6 +80,32 @@ The GUI opens directly into the full definition workbench with its standard sect
80
80
 
81
81
  The [UI quick start](docs/UIguide.md) covers the complete example from model definition to optimization and result inspection. The [script quick start](docs/scriptguide.md) provides the equivalent runnable Python task.
82
82
 
83
+ ### Run the UI in a virtual environment
84
+
85
+ Create and activate a Conda environment, then install and launch MorphOpt:
86
+
87
+ ```bash
88
+ conda create -n morphopt python=3.12
89
+ conda activate morphopt
90
+ python -m pip install morphopt
91
+ morphopt-ui
92
+ ```
93
+
94
+ For an existing environment, activate it instead. To run the source checkout, install the project in editable mode from its root directory:
95
+
96
+ ```bash
97
+ conda activate morphopt
98
+ cd /path/to/morphopt
99
+ python -m pip install -e .
100
+ morphopt-ui
101
+ ```
102
+
103
+ Replace the environment name and project path as appropriate. Installation is required once per environment; subsequent launches require only environment activation and the launch command. The equivalent module entry point uses the active environment's Python interpreter:
104
+
105
+ ```bash
106
+ python -m morphopt.ui
107
+ ```
108
+
83
109
  ### Numeric configuration
84
110
 
85
111
  Shared UI defaults and tunable kernel parameters live in [`src/morphopt/constants.py`](src/morphopt/constants.py), grouped under `CONSTANT.UI` and `CONSTANT.KERNEL`. Code accesses them directly, for example `CONSTANT.UI.VIEWER.RENDER.LABEL_FONT_SIZE` or `CONSTANT.KERNEL.SOLVER.NUM_PROCESS`. Edit a value there to change its default; restart MorphOpt for the change to take effect. Coordinate indices, tensor dimensions, and coefficients that define mathematical formulas remain in code. UI translations remain in JSON files under `src/morphopt/ui/locales/`.
@@ -52,6 +52,32 @@ The GUI opens directly into the full definition workbench with its standard sect
52
52
 
53
53
  The [UI quick start](docs/UIguide.md) covers the complete example from model definition to optimization and result inspection. The [script quick start](docs/scriptguide.md) provides the equivalent runnable Python task.
54
54
 
55
+ ### Run the UI in a virtual environment
56
+
57
+ Create and activate a Conda environment, then install and launch MorphOpt:
58
+
59
+ ```bash
60
+ conda create -n morphopt python=3.12
61
+ conda activate morphopt
62
+ python -m pip install morphopt
63
+ morphopt-ui
64
+ ```
65
+
66
+ For an existing environment, activate it instead. To run the source checkout, install the project in editable mode from its root directory:
67
+
68
+ ```bash
69
+ conda activate morphopt
70
+ cd /path/to/morphopt
71
+ python -m pip install -e .
72
+ morphopt-ui
73
+ ```
74
+
75
+ Replace the environment name and project path as appropriate. Installation is required once per environment; subsequent launches require only environment activation and the launch command. The equivalent module entry point uses the active environment's Python interpreter:
76
+
77
+ ```bash
78
+ python -m morphopt.ui
79
+ ```
80
+
55
81
  ### Numeric configuration
56
82
 
57
83
  Shared UI defaults and tunable kernel parameters live in [`src/morphopt/constants.py`](src/morphopt/constants.py), grouped under `CONSTANT.UI` and `CONSTANT.KERNEL`. Code accesses them directly, for example `CONSTANT.UI.VIEWER.RENDER.LABEL_FONT_SIZE` or `CONSTANT.KERNEL.SOLVER.NUM_PROCESS`. Edit a value there to change its default; restart MorphOpt for the change to take effect. Coordinate indices, tensor dimensions, and coefficients that define mathematical formulas remain in code. UI translations remain in JSON files under `src/morphopt/ui/locales/`.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "morphopt"
3
- version = "4.0.6"
3
+ version = "4.0.7"
4
4
  description = "A morphing optimization framework using PyTorch and torchfea."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -1082,13 +1082,16 @@ class _Constants:
1082
1082
  class CODESIGN_GEOMETRY:
1083
1083
  DEFAULT_SHELL_THICKNESS = 1.0
1084
1084
 
1085
+ class UPDATER_OBJECTIVES:
1086
+ QUADRATIC_MEMORY_PAIRS = 10
1087
+
1085
1088
  class OPTIMIZER:
1086
1089
  LINE_SEARCH_C1 = 0.0001
1087
1090
  LINE_SEARCH_BACKTRACK_RATIO = 0.2
1088
1091
  LINE_SEARCH_MIN_STEP_TOLERANCE = 1e-14
1089
1092
  LBFGS_MEMORY_PAIRS = 10
1090
1093
  LBFGS_CONVERGENCE_TOLERANCE = 1e-10
1091
- LBFGS_CURVATURE_TOLERANCE = 1e-14
1094
+ BFGS_CURVATURE_TOLERANCE = 1e-8
1092
1095
  LBFGS_SHAPE_MEMORY_PAIRS = 20
1093
1096
  LBFGS_MATERIAL_MEMORY_PAIRS = 20
1094
1097
 
@@ -0,0 +1,164 @@
1
+ """Optimization entry points, worker execution and checkpoint restart loop."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import multiprocessing as mp
6
+ import os
7
+ from multiprocessing.queues import Queue
8
+
9
+
10
+ def _main_script(path_result: str | None) -> str:
11
+ """Locate the initial task or the archived script of a resumed run."""
12
+ if path_result is None:
13
+ import __main__
14
+
15
+ return __main__.__file__
16
+ return os.path.join(path_result, "scripts", "MAIN_SCRIPT_FOR_RESTART.py")
17
+
18
+
19
+ def start_optimization(
20
+ device: str = "cpu",
21
+ restart_per_iteration: int = 20,
22
+ path_result: str | None = None,
23
+ target_iteration: int | None = None,
24
+ ) -> None:
25
+ """Run optimization in spawned processes and resume each completed segment.
26
+
27
+ ``path_result`` selects an existing run; otherwise the task in ``__main__``
28
+ starts a new run. ``target_iteration=None`` resumes its latest checkpoint.
29
+ """
30
+ mp.set_start_method("spawn", force=True)
31
+ process = mp.Process(
32
+ target=_run_task,
33
+ kwargs={
34
+ "path_result": path_result,
35
+ "main_filepath": _main_script(path_result),
36
+ "device": device,
37
+ "target_iteration": target_iteration,
38
+ "restart_per_iteration": restart_per_iteration,
39
+ },
40
+ )
41
+ process.start()
42
+ process.join()
43
+ exitcode = process.exitcode
44
+ process.close()
45
+ if exitcode != 0:
46
+ raise ChildProcessError(f"Optimization task failed with exit code {exitcode}.")
47
+
48
+
49
+ def debug_optimization(
50
+ device: str = "cpu",
51
+ restart_per_iteration: int = 20,
52
+ path_result: str | None = None,
53
+ target_iteration: int | None = None,
54
+ ) -> None:
55
+ """Run the task in the current process with serial, debugger-friendly FEA."""
56
+ mp.set_start_method("spawn", force=True)
57
+ _run_worker(
58
+ device=device,
59
+ path_result=path_result,
60
+ target_iteration=target_iteration,
61
+ restart_per_iteration=restart_per_iteration,
62
+ main_filepath=_main_script(path_result),
63
+ debug=True,
64
+ )
65
+
66
+
67
+ def _run_task(
68
+ path_result: str | None,
69
+ main_filepath: str,
70
+ device: str = "cpu",
71
+ target_iteration: int | None = None,
72
+ restart_per_iteration: int = 20,
73
+ ) -> None:
74
+ """Continue worker segments from the latest completed checkpoint."""
75
+ import warnings
76
+ from queue import Empty
77
+
78
+ from .optcore.history import History
79
+
80
+ warnings.filterwarnings("ignore", category=UserWarning)
81
+ completed = 0
82
+ if path_result is not None:
83
+ history = History()
84
+ history.load(foldpath=path_result + "/log/", iteration=target_iteration)
85
+ completed = history.iteration
86
+ path_queue = mp.Queue()
87
+ try:
88
+ while True:
89
+ process = mp.Process(
90
+ target=_run_worker,
91
+ kwargs={
92
+ "device": device,
93
+ "target_iteration": target_iteration,
94
+ "path_result": path_result,
95
+ "restart_per_iteration": restart_per_iteration,
96
+ "main_filepath": main_filepath,
97
+ "pathqueue": path_queue,
98
+ },
99
+ )
100
+ process.start()
101
+ # Drain checkpoints while the worker is alive so its queue feeder
102
+ # cannot block shutdown while the supervisor waits for completion.
103
+ while True:
104
+ try:
105
+ progress = path_queue.get(timeout=0.1)
106
+ except Empty:
107
+ if process.is_alive():
108
+ continue
109
+ break
110
+ path_result = progress["path_result"]
111
+ completed = progress["iteration"]
112
+ process.join()
113
+ exitcode = process.exitcode
114
+ process.close()
115
+ if exitcode != 0:
116
+ if completed == 0:
117
+ raise ChildProcessError(
118
+ "Optimization failed before the first completed iteration "
119
+ f"(exit code {exitcode}). See the worker traceback."
120
+ )
121
+ print(f"Process failed with exit code {exitcode}, continuing...")
122
+ target_iteration = None
123
+ finally:
124
+ path_queue.close()
125
+ path_queue.join_thread()
126
+
127
+
128
+ def _run_worker(
129
+ main_filepath: str,
130
+ device: str = "cpu",
131
+ target_iteration: int | None = None,
132
+ path_result: str | None = None,
133
+ restart_per_iteration: int = 20,
134
+ pathqueue: Queue | None = None,
135
+ debug: bool = False,
136
+ ) -> str:
137
+ """Load one task and run a new or restored controller in this process."""
138
+ os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
139
+ import sys
140
+ import warnings
141
+
142
+ import torch
143
+
144
+ import morphopt
145
+
146
+ warnings.filterwarnings("ignore", category=UserWarning)
147
+ torch.set_default_dtype(torch.float64)
148
+ torch.set_default_device(device)
149
+ filename = os.path.splitext(os.path.basename(main_filepath))[0]
150
+ os.chdir(os.path.dirname(main_filepath))
151
+ sys.path.append(os.getcwd())
152
+ controller_class = __import__(filename).ThisController
153
+ controller: morphopt.Controller = controller_class()
154
+ controller.restart_per_iteration = restart_per_iteration
155
+ controller.optdevice = device
156
+ controller.dataqueue = pathqueue
157
+ controller._debug_mode = debug
158
+ if target_iteration == 0 or path_result is None:
159
+ controller.start_optimization(main_filepath=main_filepath)
160
+ else:
161
+ controller.restart_optimization(
162
+ path_result=path_result, target_iteration=target_iteration
163
+ )
164
+ return controller.path_result
@@ -19,7 +19,7 @@ import torch
19
19
  import morphopt
20
20
 
21
21
  from ..constants import CONSTANT
22
- from ..paths import sanitize_name
22
+ from ..utils.paths import sanitize_name
23
23
  from .history import History
24
24
 
25
25
  logger = logging.getLogger(__name__)
@@ -1,7 +1,9 @@
1
1
  import os
2
2
  from collections.abc import Callable
3
+ from pathlib import Path
3
4
  from typing import TypeAlias
4
5
 
6
+ import numpy as np
5
7
  import torch
6
8
 
7
9
  import morphopt
@@ -22,6 +24,197 @@ UpdaterTargetType: TypeAlias = type[UpdaterTarget] | tuple[type[UpdaterTarget],
22
24
  """Accepted class specification for an updater target."""
23
25
 
24
26
 
27
+ class QuadraticHistory(ProtocalSavable):
28
+ """Limited-memory BFGS pairs shared by objectives and optimizers.
29
+
30
+ Each consumer owns an independent instance in its parameter coordinates.
31
+ Only positive curvature pairs are retained. Without a pair the physical
32
+ model is linear and the optimizer uses the identity preconditioner.
33
+ Products require O(memory_size * num_parameters) work and storage;
34
+ no dense Hessian or inverse Hessian is constructed.
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ memory_size: int = CONSTANT.KERNEL.UPDATER_OBJECTIVES.QUADRATIC_MEMORY_PAIRS,
40
+ ) -> None:
41
+ if (
42
+ isinstance(memory_size, bool)
43
+ or not isinstance(memory_size, int)
44
+ or memory_size < 1
45
+ ):
46
+ raise ValueError("memory_size must be a positive integer.")
47
+ self.memory_size = memory_size
48
+ self.clear()
49
+
50
+ def clear(self) -> None:
51
+ """Discard observations and matrix factors, preserving the memory limit."""
52
+ self.point: torch.Tensor | None = None
53
+ self.gradient: torch.Tensor | None = None
54
+ self._layout: tuple[int, ...] = ()
55
+ self._steps: list[torch.Tensor] = []
56
+ self._changes: list[torch.Tensor] = []
57
+ self._products: list[torch.Tensor] = []
58
+ self._step_products: list[torch.Tensor] = []
59
+ self._curvatures: list[torch.Tensor] = []
60
+ self._scale: torch.Tensor | None = None
61
+
62
+ @property
63
+ def history_size(self) -> int:
64
+ """Number of retained positive-curvature observation pairs."""
65
+ return len(self._steps)
66
+
67
+ def observe(
68
+ self,
69
+ point: torch.Tensor,
70
+ gradient: torch.Tensor,
71
+ layout: tuple[int, ...] = (),
72
+ ) -> None:
73
+ """Record one point and the gradient of the consumer's objective.
74
+
75
+ A changed parameter count or block layout discards previous pairs.
76
+ Zero steps and gradient differences that fail the relative curvature
77
+ condition are skipped; the latest point and gradient still replace
78
+ the anchor. Physical objectives supply unscaled FEA gradients;
79
+ optimizers supply gradients of the complete inner objective.
80
+ """
81
+ point = point.detach().clone().flatten()
82
+ gradient = gradient.detach().clone().flatten().to(point)
83
+ if point.shape != gradient.shape:
84
+ raise ValueError(
85
+ "Surrogate parameters and gradient must have the same size."
86
+ )
87
+ if not torch.isfinite(point).all() or not torch.isfinite(gradient).all():
88
+ raise ValueError("Surrogate parameters and gradient must be finite.")
89
+ if self.point is not None and (
90
+ self.point.shape != point.shape or self._layout != layout
91
+ ):
92
+ self.clear()
93
+ if self.point is not None:
94
+ step = point - self.point
95
+ change = gradient - self.gradient
96
+ curvature = step @ change
97
+ threshold = (
98
+ CONSTANT.KERNEL.OPTIMIZER.BFGS_CURVATURE_TOLERANCE
99
+ * step.norm()
100
+ * change.norm()
101
+ )
102
+ if curvature > threshold:
103
+ self._steps.append(step)
104
+ self._changes.append(change)
105
+ self._steps = self._steps[-self.memory_size :]
106
+ self._changes = self._changes[-self.memory_size :]
107
+ self.point, self.gradient, self._layout = point, gradient, layout
108
+ self._build_hessian()
109
+
110
+ def _build_hessian(self) -> None:
111
+ """Cache direct BFGS rank-update factors at the current anchor."""
112
+ self._products = []
113
+ self._step_products = []
114
+ self._curvatures = []
115
+ self._scale = None
116
+ if not self._steps:
117
+ return
118
+ step, change = self._steps[-1], self._changes[-1]
119
+ self._scale = (change @ change) / (step @ change)
120
+ for step, change in zip(self._steps, self._changes):
121
+ product = self.hessian_product(step)
122
+ self._products.append(product)
123
+ self._step_products.append(step @ product)
124
+ self._curvatures.append(step @ change)
125
+
126
+ def hessian_product(self, vector: torch.Tensor) -> torch.Tensor:
127
+ """Apply B, rather than the inverse-Hessian used for search directions."""
128
+ if self._scale is None:
129
+ return torch.zeros_like(vector)
130
+ result = self._scale * vector
131
+ for product, denominator, change, curvature in zip(
132
+ self._products, self._step_products, self._changes, self._curvatures
133
+ ):
134
+ result = result - product * (product @ vector) / denominator
135
+ result = result + change * (change @ vector) / curvature
136
+ return result
137
+
138
+ def inverse_hessian_product(self, vector: torch.Tensor) -> torch.Tensor:
139
+ """Apply the matching inverse BFGS approximation by two-loop recursion.
140
+
141
+ Before the first retained pair, return the input for a steepest-descent
142
+ search direction. The outer objective independently uses a zero
143
+ quadratic term until physical curvature becomes available.
144
+ """
145
+ if not self._steps:
146
+ return vector.clone()
147
+ result = vector.clone()
148
+ coefficients = []
149
+ for step, change, curvature in zip(
150
+ reversed(self._steps), reversed(self._changes), reversed(self._curvatures)
151
+ ):
152
+ coefficient = (step @ result) / curvature
153
+ coefficients.append(coefficient)
154
+ result = result - coefficient * change
155
+ result = result / self._scale
156
+ for step, change, curvature, coefficient in zip(
157
+ self._steps, self._changes, self._curvatures, reversed(coefficients)
158
+ ):
159
+ result = result + step * (coefficient - (change @ result) / curvature)
160
+ return result
161
+
162
+ def __call__(self, point: torch.Tensor) -> torch.Tensor:
163
+ """Return g.T d + 0.5 d.T B d, with zero value at the anchor."""
164
+ if self.point is None:
165
+ raise RuntimeError(
166
+ "Observe a gradient before evaluating the quadratic model."
167
+ )
168
+ delta = point.flatten() - self.point
169
+ return self.gradient @ delta + 0.5 * (delta @ self.hessian_product(delta))
170
+
171
+ def _state_path(self, foldpath: str, iteration: int) -> Path:
172
+ """Locate this iteration inside the owner's history directory."""
173
+ return Path(foldpath) / f"surrogate_{iteration}.npz"
174
+
175
+ def save(self, foldpath: str, iteration: int) -> None:
176
+ """Persist the latest observation and retained curvature pairs."""
177
+ path = self._state_path(foldpath, iteration)
178
+ path.parent.mkdir(parents=True, exist_ok=True)
179
+ size = self.point.numel() if self.point is not None else 0
180
+ np.savez_compressed(
181
+ path,
182
+ observed=self.point is not None,
183
+ point=(self.point.cpu().numpy() if self.point is not None else np.empty(0)),
184
+ gradient=(
185
+ self.gradient.cpu().numpy()
186
+ if self.gradient is not None
187
+ else np.empty(0)
188
+ ),
189
+ layout=np.asarray(self._layout, dtype=np.int64),
190
+ steps=(
191
+ torch.stack(self._steps).cpu().numpy()
192
+ if self._steps
193
+ else np.empty((0, size))
194
+ ),
195
+ changes=(
196
+ torch.stack(self._changes).cpu().numpy()
197
+ if self._changes
198
+ else np.empty((0, size))
199
+ ),
200
+ )
201
+
202
+ def load(self, foldpath: str, iteration: int) -> None:
203
+ """Restore observations on the active default device and rebuild B."""
204
+ with np.load(self._state_path(foldpath, iteration), allow_pickle=False) as state:
205
+ observed = state["observed"].item()
206
+ self.point = torch.tensor(state["point"]) if observed else None
207
+ self.gradient = torch.tensor(state["gradient"]) if observed else None
208
+ self._layout = tuple(int(value) for value in state["layout"])
209
+ self._steps = [
210
+ torch.tensor(value) for value in state["steps"][-self.memory_size :]
211
+ ]
212
+ self._changes = [
213
+ torch.tensor(value) for value in state["changes"][-self.memory_size :]
214
+ ]
215
+ self._build_hessian()
216
+
217
+
25
218
  class BaseUpdater(ProtocalInitializable, ProtocalSavable):
26
219
  """Base class for all sub-updaters.
27
220
 
@@ -182,7 +375,10 @@ class BaseUpdater(ProtocalInitializable, ProtocalSavable):
182
375
  ):
183
376
  return alpha, obj_new
184
377
  alpha *= self._rou1
185
- if (alpha * direction).abs().max() < CONSTANT.KERNEL.OPTIMIZER.LINE_SEARCH_MIN_STEP_TOLERANCE:
378
+ if (
379
+ (alpha * direction).abs().max()
380
+ < CONSTANT.KERNEL.OPTIMIZER.LINE_SEARCH_MIN_STEP_TOLERANCE
381
+ ):
186
382
  return 0.0, obj0
187
383
 
188
384
  class LBFGS(BaseOpt):
@@ -193,47 +389,16 @@ class BaseUpdater(ProtocalInitializable, ProtocalSavable):
193
389
  tol_error: float = CONSTANT.KERNEL.OPTIMIZER.LBFGS_CONVERGENCE_TOLERANCE,
194
390
  ) -> None:
195
391
  super().__init__(closure=closure)
196
- self.SK = []
197
- self.YK = []
198
- self.rhok = []
199
-
200
- self.num_limit = num_limit
201
- """
202
- the number of pairs of Hessian and gradient stored in the memory
203
- """
392
+ self.history = QuadraticHistory(memory_size=num_limit)
204
393
 
205
394
  self.tol_error = tol_error
206
395
  """
207
396
  the tolerance for the convergence of the optimization process
208
397
  """
209
398
 
210
- def Hg_loop(self, dv: torch.Tensor) -> torch.Tensor:
211
- """
212
- Compute the product of the inverse Hessian matrix and the gradient vector.
213
- This is done using the BFGS update formula.
214
-
215
- Parameters:
216
- dv (torch.Tensor): The gradient vector.
217
-
218
- Returns:
219
- torch.Tensor: The product of the inverse Hessian matrix and the gradient vector.
220
- """
221
-
222
- q = dv.clone()
223
- alpha = torch.zeros(len(self.SK))
224
- for i in range(len(self.SK) - 1, -1, -1):
225
- alpha[i] = self.rhok[i] * self.SK[i].dot(q)
226
- q = q - alpha[i] * self.YK[i]
227
-
228
- y = q / (self.rhok[-1] * self.YK[-1].dot(self.YK[-1]))
229
-
230
- for i in range(len(self.SK)):
231
- beta = self.rhok[i] * self.YK[i].dot(y)
232
- y = y + (alpha[i] - beta) * self.SK[i]
233
-
234
- return y
235
-
236
- def step(self, x_now: torch.Tensor, gk_now: torch.Tensor = None):
399
+ def step(
400
+ self, x_now: torch.Tensor, gk_now: torch.Tensor | None = None
401
+ ) -> tuple[float, torch.Tensor, torch.Tensor]:
237
402
 
238
403
  obj_now = self.closure(x_now)
239
404
  if gk_now is None:
@@ -241,56 +406,29 @@ class BaseUpdater(ProtocalInitializable, ProtocalSavable):
241
406
 
242
407
  gk_now.view(-1)[gk_now.view(-1).isnan()] = 0
243
408
 
244
- # if the first iteration, use steepest descent direction
245
- if len(self.SK) == 0:
409
+ if self.history.point is None:
410
+ self.history.observe(x_now, gk_now)
411
+ dk = self.history.inverse_hessian_product(-gk_now)
412
+ if not torch.isfinite(dk).all() or (dk * gk_now).sum() > 0:
413
+ self.history.clear()
414
+ self.history.observe(x_now, gk_now)
246
415
  dk = -gk_now
247
- else:
248
- dk = self.Hg_loop(-gk_now)
249
- if dk.view(-1).isnan().any():
250
- dk = -gk_now
251
- self.SK = []
252
- self.YK = []
253
- self.rhok = []
254
-
255
- # if the gradient is not positive, use steepest descent direction
256
- if (dk * gk_now).sum() > 0:
257
- dk = -dk
258
416
 
259
417
  # line search
260
418
  alpha, obj_new = self._LineSearchBacktracking(
261
419
  x0=x_now, dx=gk_now, direction=dk, alpha0=1.0, obj0=obj_now
262
420
  )
263
421
 
264
- # if the step length is too small, stop the iteration
265
- if abs(alpha) <= self.tol_error:
266
- self.SK = []
267
- self.YK = []
268
- self.rhok = []
269
-
270
- x_new = x_now + alpha * dk
271
-
272
- if obj_new > obj_now:
273
- self.SK = []
274
- self.YK = []
275
- self.rhok = []
422
+ if alpha == 0 or obj_new > obj_now:
423
+ self.history.clear()
276
424
  return 0.0, torch.zeros_like(x_now), gk_now
277
425
 
426
+ x_new = x_now + alpha * dk
278
427
  gk_new: torch.Tensor = self.grad(x_new).flatten()
279
-
280
- yk = gk_new.flatten() - gk_now.flatten()
281
- sk = alpha * dk.flatten()
282
-
283
- # BFGS method
284
- curvature_tolerance = CONSTANT.KERNEL.OPTIMIZER.LBFGS_CURVATURE_TOLERANCE
285
- if yk.norm() > curvature_tolerance and sk.norm() > curvature_tolerance:
286
- self.SK.append(sk)
287
- self.YK.append(yk)
288
- self.rhok.append(1 / yk.dot(sk))
289
-
290
- if len(self.SK) > self.num_limit:
291
- self.SK = self.SK[1:]
292
- self.YK = self.YK[1:]
293
- self.rhok = self.rhok[1:]
428
+ if abs(alpha) <= self.tol_error:
429
+ self.history.clear()
430
+ else:
431
+ self.history.observe(x_new, gk_new)
294
432
 
295
433
  return alpha, dk, gk_new
296
434
 
@@ -765,11 +903,27 @@ class Updaters(ProtocalInitializable, ProtocalSavable):
765
903
  """Save the state of every sub-updater."""
766
904
  for updater in self.updaters.values():
767
905
  updater.save(foldpath=foldpath, iteration=iteration)
906
+ directory = updater.save_directory(
907
+ foldpath, updater.interface_name or "all"
908
+ )
909
+ for name, objective in updater.obj_funcs.items():
910
+ objective.save(
911
+ foldpath=os.path.join(directory, "objectives", name),
912
+ iteration=iteration,
913
+ )
768
914
 
769
915
  def load(self, foldpath: str, iteration: int) -> None:
770
916
  """Restore the state of every sub-updater."""
771
917
  for updater in self.updaters.values():
772
918
  updater.load(foldpath=foldpath, iteration=iteration)
919
+ directory = updater.save_directory(
920
+ foldpath, updater.interface_name or "all"
921
+ )
922
+ for name, objective in updater.obj_funcs.items():
923
+ objective.load(
924
+ foldpath=os.path.join(directory, "objectives", name),
925
+ iteration=iteration,
926
+ )
773
927
 
774
928
  def pathlog_required(self) -> list[str]:
775
929
  """The log sub-paths every sub-updater needs (deduplicated)."""