tfopt 0.2.0__py3-none-any.whl

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 (68) hide show
  1. config_loader.py +38 -0
  2. tfopt/__init__.py +25 -0
  3. tfopt/__main__.py +5 -0
  4. tfopt/_exit.py +66 -0
  5. tfopt/analysis/__init__.py +74 -0
  6. tfopt/analysis/diagrams.py +221 -0
  7. tfopt/api.py +662 -0
  8. tfopt/app/__init__.py +17 -0
  9. tfopt/app/__main__.py +72 -0
  10. tfopt/app/backend.py +593 -0
  11. tfopt/app/server.py +230 -0
  12. tfopt/app/static/app.css +233 -0
  13. tfopt/app/static/app.js +431 -0
  14. tfopt/app/static/index.html +129 -0
  15. tfopt/bundle/__init__.py +13 -0
  16. tfopt/bundle/build.py +566 -0
  17. tfopt/bundle/contract/1.0/manifest.schema.json +316 -0
  18. tfopt/bundle/contract/1.0/tables.json +1186 -0
  19. tfopt/bundle/contract.py +231 -0
  20. tfopt/cli.py +266 -0
  21. tfopt/examples/__init__.py +119 -0
  22. tfopt/fitanalysis/__init__.py +0 -0
  23. tfopt/fitanalysis/__main__.py +12 -0
  24. tfopt/fitanalysis/curves.py +52 -0
  25. tfopt/fitanalysis/figures.py +96 -0
  26. tfopt/fitanalysis/helper.py +2 -0
  27. tfopt/fitanalysis/helpers/__init__.py +1 -0
  28. tfopt/fitanalysis/helpers/plotter.py +372 -0
  29. tfopt/fitanalysis/metrics.py +12 -0
  30. tfopt/fitanalysis/networks.py +46 -0
  31. tfopt/fitanalysis/regulatory.py +237 -0
  32. tfopt/fitanalysis/workbook.py +264 -0
  33. tfopt/local/__init__.py +0 -0
  34. tfopt/local/__main__.py +62 -0
  35. tfopt/local/config/__init__.py +0 -0
  36. tfopt/local/config/constants.py +120 -0
  37. tfopt/local/config/logconf.py +112 -0
  38. tfopt/local/exporter/__init__.py +0 -0
  39. tfopt/local/exporter/latexit.py +13 -0
  40. tfopt/local/exporter/plotout.py +285 -0
  41. tfopt/local/exporter/sheetutils.py +193 -0
  42. tfopt/local/objfn/__init__.py +0 -0
  43. tfopt/local/objfn/minfn.py +67 -0
  44. tfopt/local/opt/__init__.py +0 -0
  45. tfopt/local/opt/optrun.py +279 -0
  46. tfopt/local/opt/slsqp.py +65 -0
  47. tfopt/local/opt/workers.py +81 -0
  48. tfopt/local/optcon/__init__.py +0 -0
  49. tfopt/local/optcon/construct.py +134 -0
  50. tfopt/local/optcon/feasibility.py +116 -0
  51. tfopt/local/optcon/filter.py +101 -0
  52. tfopt/local/utils/__init__.py +0 -0
  53. tfopt/local/utils/iodata.py +238 -0
  54. tfopt/local/utils/params.py +131 -0
  55. tfopt/optimality/KKT.py +14 -0
  56. tfopt/optimality/__init__.py +1 -0
  57. tfopt/optimality/kkt_diagnostics.py +182 -0
  58. tfopt/processing/__init__.py +1 -0
  59. tfopt/processing/cleanup.py +14 -0
  60. tfopt/processing/map.py +14 -0
  61. tfopt/processing/tfseries.py +188 -0
  62. tfopt-0.2.0.dist-info/METADATA +158 -0
  63. tfopt-0.2.0.dist-info/RECORD +68 -0
  64. tfopt-0.2.0.dist-info/WHEEL +5 -0
  65. tfopt-0.2.0.dist-info/entry_points.txt +4 -0
  66. tfopt-0.2.0.dist-info/licenses/LICENSE +28 -0
  67. tfopt-0.2.0.dist-info/licenses/THIRD_PARTY.md +83 -0
  68. tfopt-0.2.0.dist-info/top_level.txt +2 -0
tfopt/app/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """``tfopt-app``: a guided GUI for TFOpt in the browser (as KinOpt's ``kinopt-app``).
2
+
3
+ Steps: inputs (input1, input3, input4 or the example; the time grids) → validation → configuration → run → results
4
+ (tables and the run bundle). The server is the Python standard library, the page is plain HTML/JS/CSS shipped in the
5
+ package; it calls the same library functions as the command line (``tfopt.api``). See ``tfopt.app.server`` for the
6
+ security measures.
7
+ """
8
+ from tfopt.app.backend import Session
9
+ from tfopt.app.server import make_server, url
10
+
11
+ __all__ = ["Session", "main", "make_server", "url"]
12
+
13
+
14
+ def main(argv=None) -> int:
15
+ """Entry point of ``tfopt-app``: start the server, print the URL with the token, open the browser."""
16
+ from tfopt.app.__main__ import main as _main
17
+ return _main(argv)
tfopt/app/__main__.py ADDED
@@ -0,0 +1,72 @@
1
+ """``tfopt-app`` / ``python -m tfopt.app`` / ``tfopt app``: start the GUI server and open it in the browser."""
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import sys
6
+ import webbrowser
7
+ from pathlib import Path
8
+
9
+
10
+ def main(argv=None) -> int:
11
+ """Start the GUI for a working folder; stop with Ctrl+C.
12
+
13
+ Args:
14
+ argv (list[str] | None): Arguments (default: ``sys.argv[1:]``).
15
+
16
+ Returns:
17
+ int: Exit status.
18
+ """
19
+ from tfopt.app.backend import DEFAULT_MAX_UPLOAD_BYTES, Session
20
+ from tfopt.app.server import make_server, url
21
+
22
+ p = argparse.ArgumentParser(prog="tfopt-app", description="TFOpt's guided GUI in the browser (local only).")
23
+ p.add_argument("--workdir", type=Path, default=Path("tfopt-app"),
24
+ help="working folder: uploads and runs are written only here (default ./tfopt-app)")
25
+ p.add_argument("--port", type=int, default=0, help="port on 127.0.0.1 (default: a free port)")
26
+ p.add_argument("--max-upload-mb", type=float, default=DEFAULT_MAX_UPLOAD_BYTES / 2**20,
27
+ help="largest accepted upload in MB (default 50)")
28
+ p.add_argument("--config", type=Path, default=None,
29
+ help="config.toml whose settings (time grids included, not its paths) pre-fill the configuration "
30
+ "(default: TFOPT_CONFIG, or in a clone the repository's config.toml; without one, enter the "
31
+ "time grids)")
32
+ p.add_argument("--no-browser", action="store_true", help="only print the URL")
33
+ args = p.parse_args(argv)
34
+
35
+ config = args.config
36
+ if config is None:
37
+ import config_loader
38
+ found = config_loader.config_path()
39
+ config = found if found.is_file() else None
40
+ try:
41
+ session = Session(args.workdir, max_upload_bytes=int(args.max_upload_mb * 2**20), config=config)
42
+ except (OSError, ValueError) as exc:
43
+ print(f"tfopt-app: cannot use the configuration {config}: {exc}", file=sys.stderr)
44
+ return 2
45
+ httpd = make_server(session, port=args.port)
46
+ link = url(httpd, session)
47
+ print(f"TFOpt app, working folder {session.workdir}")
48
+ print(f"Settings from {session.config}" if session.config else
49
+ "No config.toml found: enter the time grids in the configuration step (or pass --config)")
50
+ print(f"Open (the link contains this session's token; do not share it): {link}")
51
+ print("Stop with Ctrl+C.", flush=True)
52
+ if not args.no_browser:
53
+ webbrowser.open(link)
54
+ try:
55
+ httpd.serve_forever()
56
+ except KeyboardInterrupt:
57
+ pass
58
+ finally:
59
+ for run in session.runs():
60
+ if run["state"] == "running":
61
+ session.cancel(run["run"])
62
+ httpd.server_close()
63
+ return 0
64
+
65
+
66
+ def console_main() -> None:
67
+ """Console script ``tfopt-app``: `main` with a clean exit (``tfopt._exit.run_and_exit``)."""
68
+ from tfopt._exit import run_and_exit
69
+ run_and_exit(main)
70
+
71
+ if __name__ == "__main__":
72
+ console_main()