socklight 0.2.0__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.
- socklight-0.2.0/.github/workflows/ci.yml +81 -0
- socklight-0.2.0/.gitignore +21 -0
- socklight-0.2.0/CMakeLists.txt +120 -0
- socklight-0.2.0/LICENSE +201 -0
- socklight-0.2.0/NOTICE +7 -0
- socklight-0.2.0/PKG-INFO +9 -0
- socklight-0.2.0/README.md +216 -0
- socklight-0.2.0/VENDORED.md +32 -0
- socklight-0.2.0/ci/build-pyodide.sh +17 -0
- socklight-0.2.0/csrc/bridge.c +221 -0
- socklight-0.2.0/csrc/bridge.h +56 -0
- socklight-0.2.0/csrc/device.c +381 -0
- socklight-0.2.0/csrc/device.h +65 -0
- socklight-0.2.0/csrc/osdi.h +228 -0
- socklight-0.2.0/csrc/socklight_osdi.c +246 -0
- socklight-0.2.0/docs/design.md +348 -0
- socklight-0.2.0/docs/iq-convention.md +59 -0
- socklight-0.2.0/examples/mzi_tia.py +93 -0
- socklight-0.2.0/pyproject.toml +41 -0
- socklight-0.2.0/src/socklight/__init__.py +21 -0
- socklight-0.2.0/src/socklight/_bridge.py +78 -0
- socklight-0.2.0/src/socklight/_sax/__init__.py +38 -0
- socklight-0.2.0/src/socklight/_sax/_compat.py +38 -0
- socklight-0.2.0/src/socklight/_sax/constants.py +282 -0
- socklight-0.2.0/src/socklight/_sax/ports.py +307 -0
- socklight-0.2.0/src/socklight/models/__init__.py +36 -0
- socklight-0.2.0/src/socklight/models/bends.py +88 -0
- socklight-0.2.0/src/socklight/models/couplers.py +285 -0
- socklight-0.2.0/src/socklight/models/crossings.py +62 -0
- socklight-0.2.0/src/socklight/models/factories.py +330 -0
- socklight-0.2.0/src/socklight/models/isolators.py +142 -0
- socklight-0.2.0/src/socklight/models/mmis.py +291 -0
- socklight-0.2.0/src/socklight/models/probes.py +81 -0
- socklight-0.2.0/src/socklight/models/reflectors.py +119 -0
- socklight-0.2.0/src/socklight/models/splitters.py +69 -0
- socklight-0.2.0/src/socklight/models/straight.py +179 -0
- socklight-0.2.0/src/socklight/models/terminators.py +58 -0
- socklight-0.2.0/src/socklight/netlist.py +251 -0
- socklight-0.2.0/src/socklight/registry.py +138 -0
- socklight-0.2.0/tests/conftest.py +181 -0
- socklight-0.2.0/tests/data/circulax_heater.json +61 -0
- socklight-0.2.0/tests/data/sax_reference.json +1758 -0
- socklight-0.2.0/tests/test_circulax.py +46 -0
- socklight-0.2.0/tests/test_heater.py +128 -0
- socklight-0.2.0/tests/test_helpers.py +70 -0
- socklight-0.2.0/tests/test_native_sweep.py +59 -0
- socklight-0.2.0/tests/test_netlist.py +341 -0
- socklight-0.2.0/tests/test_osdi.py +196 -0
- socklight-0.2.0/tests/test_reference.py +31 -0
- socklight-0.2.0/tests/test_registry.py +255 -0
- socklight-0.2.0/tests/test_sweep.py +45 -0
- socklight-0.2.0/tests/test_vendor.py +64 -0
- socklight-0.2.0/tools/circulax_heater.py +116 -0
- socklight-0.2.0/tools/reference_values.py +58 -0
- socklight-0.2.0/va/heater.va +43 -0
- socklight-0.2.0/va/optical_source.va +22 -0
- socklight-0.2.0/va/optical_term.va +14 -0
- socklight-0.2.0/va/photodetector.va +19 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
13
|
+
|
|
14
|
+
# VACASK and openvaf-r (with the wasm32-unknown-emscripten target) come from
|
|
15
|
+
# PyPI: vacask is a dependency, vacask-bin a build requirement (pyproject.toml).
|
|
16
|
+
# cibuildwheel builds each wheel and runs the tests against the installed wheel,
|
|
17
|
+
# natively and in Pyodide.
|
|
18
|
+
jobs:
|
|
19
|
+
wheels-linux:
|
|
20
|
+
name: Wheels (${{ matrix.os }})
|
|
21
|
+
strategy:
|
|
22
|
+
fail-fast: false
|
|
23
|
+
matrix:
|
|
24
|
+
os: [ubuntu-24.04, ubuntu-24.04-arm]
|
|
25
|
+
runs-on: ${{ matrix.os }}
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v6
|
|
28
|
+
- uses: pypa/cibuildwheel@v4.3.5
|
|
29
|
+
- uses: actions/upload-artifact@v6
|
|
30
|
+
with:
|
|
31
|
+
name: wheels-${{ matrix.os }}
|
|
32
|
+
path: wheelhouse/*.whl
|
|
33
|
+
|
|
34
|
+
wheels-pyodide:
|
|
35
|
+
# Pyodide 314 (Python 3.14, Emscripten 5.0.3), the Pyodide marimo ships.
|
|
36
|
+
name: Wheels (Pyodide)
|
|
37
|
+
runs-on: ubuntu-24.04
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v6
|
|
40
|
+
- uses: pypa/cibuildwheel@v4.3.5
|
|
41
|
+
env:
|
|
42
|
+
CIBW_PLATFORM: pyodide
|
|
43
|
+
CIBW_BUILD: cp314-pyodide_wasm32
|
|
44
|
+
# PyPI accepts the PEP 783 tag only: fail here rather than mid-release.
|
|
45
|
+
- name: Check the platform tag
|
|
46
|
+
run: |
|
|
47
|
+
ls wheelhouse
|
|
48
|
+
ls wheelhouse/*-cp314-cp314-pyemscripten_2026_0_wasm32.whl
|
|
49
|
+
- uses: actions/upload-artifact@v6
|
|
50
|
+
with:
|
|
51
|
+
name: wheels-pyodide
|
|
52
|
+
path: wheelhouse/*.whl
|
|
53
|
+
|
|
54
|
+
sdist:
|
|
55
|
+
name: sdist
|
|
56
|
+
runs-on: ubuntu-24.04
|
|
57
|
+
steps:
|
|
58
|
+
- uses: actions/checkout@v6
|
|
59
|
+
- run: pipx run build --sdist
|
|
60
|
+
- uses: actions/upload-artifact@v6
|
|
61
|
+
with:
|
|
62
|
+
name: sdist
|
|
63
|
+
path: dist/*.tar.gz
|
|
64
|
+
|
|
65
|
+
# Publishes on a v* tag. pypi.org must list this repository, this workflow
|
|
66
|
+
# file (ci.yml) and the environment "pypi" as a trusted publisher of socklight.
|
|
67
|
+
pypi:
|
|
68
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
69
|
+
needs: [wheels-linux, wheels-pyodide, sdist]
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
environment:
|
|
72
|
+
name: pypi
|
|
73
|
+
url: https://pypi.org/p/socklight
|
|
74
|
+
permissions:
|
|
75
|
+
id-token: write
|
|
76
|
+
steps:
|
|
77
|
+
- uses: actions/download-artifact@v6
|
|
78
|
+
with:
|
|
79
|
+
path: dist
|
|
80
|
+
merge-multiple: true
|
|
81
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.venv/
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
*.egg-info/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
# scikit-build-core editable.mode = "inplace" configures and builds in the source tree
|
|
9
|
+
/.cmake/
|
|
10
|
+
/.ninja_deps
|
|
11
|
+
/.ninja_log
|
|
12
|
+
/.skbuild-info.json
|
|
13
|
+
/CMakeCache.txt
|
|
14
|
+
/CMakeFiles/
|
|
15
|
+
/CMakeInit.txt
|
|
16
|
+
/build.ninja
|
|
17
|
+
/cmake_install.cmake
|
|
18
|
+
/src/socklight/socklight.osdi
|
|
19
|
+
/src/socklight/va/
|
|
20
|
+
/wheelhouse/
|
|
21
|
+
/.pyodide_build/
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
project(socklight LANGUAGES C)
|
|
3
|
+
|
|
4
|
+
# socklight.osdi: one OSDI device per model in socklight's Python registry.
|
|
5
|
+
# Built against the Python headers only; the Py* symbols resolve from the
|
|
6
|
+
# process that loads it (VACASK's Python extension), so libpython is not linked.
|
|
7
|
+
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module)
|
|
8
|
+
|
|
9
|
+
set(SOCKLIGHT_MAX_MODELS 1024 CACHE STRING "Descriptor slots in socklight.osdi (the most models one process can register)")
|
|
10
|
+
if(NOT SOCKLIGHT_MAX_MODELS MATCHES "^[1-9][0-9]*$")
|
|
11
|
+
message(FATAL_ERROR "SOCKLIGHT_MAX_MODELS must be a positive integer, got '${SOCKLIGHT_MAX_MODELS}'")
|
|
12
|
+
endif()
|
|
13
|
+
|
|
14
|
+
# One SL_SLOT(k) line per descriptor slot; socklight_osdi.c expands it into the
|
|
15
|
+
# slot's trampolines and their table.
|
|
16
|
+
set(_slots "")
|
|
17
|
+
math(EXPR _last "${SOCKLIGHT_MAX_MODELS} - 1")
|
|
18
|
+
foreach(k RANGE 0 ${_last})
|
|
19
|
+
string(APPEND _slots "SL_SLOT(${k})\n")
|
|
20
|
+
endforeach()
|
|
21
|
+
set(_gen "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/socklight_generated")
|
|
22
|
+
file(CONFIGURE OUTPUT "${_gen}/sl_slots.inc" CONTENT "${_slots}")
|
|
23
|
+
|
|
24
|
+
add_library(socklight_osdi MODULE
|
|
25
|
+
csrc/socklight_osdi.c
|
|
26
|
+
csrc/device.c
|
|
27
|
+
csrc/bridge.c
|
|
28
|
+
)
|
|
29
|
+
target_include_directories(socklight_osdi PRIVATE csrc "${_gen}")
|
|
30
|
+
target_link_libraries(socklight_osdi PRIVATE Python::Module)
|
|
31
|
+
target_compile_definitions(socklight_osdi PRIVATE SOCKLIGHT_MAX_MODELS=${SOCKLIGHT_MAX_MODELS})
|
|
32
|
+
target_link_libraries(socklight_osdi PRIVATE m)
|
|
33
|
+
set_target_properties(socklight_osdi PROPERTIES
|
|
34
|
+
OUTPUT_NAME socklight
|
|
35
|
+
PREFIX ""
|
|
36
|
+
SUFFIX ".osdi"
|
|
37
|
+
C_STANDARD 11
|
|
38
|
+
C_EXTENSIONS ON
|
|
39
|
+
C_VISIBILITY_PRESET hidden
|
|
40
|
+
)
|
|
41
|
+
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
|
42
|
+
target_compile_options(socklight_osdi PRIVATE -Wall -Wextra)
|
|
43
|
+
endif()
|
|
44
|
+
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
45
|
+
# Pyodide: a WebAssembly side module, loaded by VACASK's dlopen like the native
|
|
46
|
+
# library. The Py* symbols stay undefined and resolve against the Pyodide main
|
|
47
|
+
# module, like any extension module's.
|
|
48
|
+
target_link_options(socklight_osdi PRIVATE -sSIDE_MODULE=1)
|
|
49
|
+
endif()
|
|
50
|
+
|
|
51
|
+
# scikit-build-core's editable.mode = "inplace" configures in the source
|
|
52
|
+
# directory: put the library next to the package sources.
|
|
53
|
+
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
54
|
+
set_target_properties(socklight_osdi PROPERTIES
|
|
55
|
+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/src/socklight")
|
|
56
|
+
endif()
|
|
57
|
+
|
|
58
|
+
install(TARGETS socklight_osdi LIBRARY DESTINATION socklight)
|
|
59
|
+
|
|
60
|
+
# Verilog-A helpers (va/*.va), compiled with OpenVAF-reloaded into socklight/va/<name>.osdi.
|
|
61
|
+
# Default: the openvaf-r that vacask-bin ships (a build requirement, see
|
|
62
|
+
# pyproject.toml; since 0.3.4.dev5 it has the wasm32-unknown-emscripten target),
|
|
63
|
+
# else openvaf-r on PATH.
|
|
64
|
+
set(OPENVAF_COMPILER "" CACHE STRING "openvaf-r, the OpenVAF compiler used for va/*.va (name on PATH or full path; default: vacask-bin's)")
|
|
65
|
+
if(NOT OPENVAF_COMPILER)
|
|
66
|
+
execute_process(
|
|
67
|
+
COMMAND "${Python_EXECUTABLE}" -c "import vacask_bin; print(vacask_bin.OPENVAF_CMD)"
|
|
68
|
+
OUTPUT_VARIABLE _vacask_bin_openvaf OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
69
|
+
RESULT_VARIABLE _res ERROR_QUIET)
|
|
70
|
+
if(_res EQUAL 0 AND EXISTS "${_vacask_bin_openvaf}")
|
|
71
|
+
set(OPENVAF_COMPILER "${_vacask_bin_openvaf}")
|
|
72
|
+
else()
|
|
73
|
+
set(OPENVAF_COMPILER "openvaf-r")
|
|
74
|
+
endif()
|
|
75
|
+
endif()
|
|
76
|
+
message(STATUS "OpenVAF compiler: ${OPENVAF_COMPILER}")
|
|
77
|
+
find_program(_openvaf NAMES "${OPENVAF_COMPILER}" REQUIRED NO_CMAKE_FIND_ROOT_PATH)
|
|
78
|
+
# Extra openvaf-r arguments for the target, and the environment it runs in.
|
|
79
|
+
# openvaf-r defaults to --target_cpu native: models built on one machine can then
|
|
80
|
+
# die with "Illegal instruction" on another. Wheels must run anywhere.
|
|
81
|
+
set(OPENVAF_TARGET_CPU "generic" CACHE STRING "CPU the va/*.va models are compiled for (openvaf-r --target_cpu; 'native' for local builds)")
|
|
82
|
+
set(_openvaf_target --target_cpu "${OPENVAF_TARGET_CPU}")
|
|
83
|
+
set(_openvaf_launcher "")
|
|
84
|
+
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
85
|
+
# As VACASK's Pyodide build: the models become WebAssembly side modules,
|
|
86
|
+
# compiled for wasm32-unknown-emscripten and linked by the wasm-ld of the
|
|
87
|
+
# Emscripten SDK that builds socklight.osdi.
|
|
88
|
+
execute_process(COMMAND "${_openvaf}" --supported-targets
|
|
89
|
+
OUTPUT_VARIABLE _targets RESULT_VARIABLE _res)
|
|
90
|
+
if(NOT _res EQUAL 0 OR NOT _targets MATCHES "wasm32-unknown-emscripten")
|
|
91
|
+
message(FATAL_ERROR "${_openvaf} cannot compile for WebAssembly (no wasm32-unknown-emscripten target)")
|
|
92
|
+
endif()
|
|
93
|
+
get_filename_component(_cc_dir "${CMAKE_C_COMPILER}" DIRECTORY)
|
|
94
|
+
find_program(WASM_LD wasm-ld
|
|
95
|
+
HINTS "${EMSCRIPTEN_ROOT_PATH}/../bin" "$ENV{EMSDK}/upstream/bin" "${_cc_dir}/../bin"
|
|
96
|
+
NO_CMAKE_FIND_ROOT_PATH REQUIRED)
|
|
97
|
+
message(STATUS "WebAssembly linker for va/*.va: ${WASM_LD}")
|
|
98
|
+
set(_openvaf_target --target wasm32-unknown-emscripten)
|
|
99
|
+
set(_openvaf_launcher "${CMAKE_COMMAND}" -E env "OPENVAF_WASM_LD=${WASM_LD}")
|
|
100
|
+
endif()
|
|
101
|
+
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
102
|
+
set(_va_out "${CMAKE_SOURCE_DIR}/src/socklight/va")
|
|
103
|
+
else()
|
|
104
|
+
set(_va_out "${CMAKE_CURRENT_BINARY_DIR}/va")
|
|
105
|
+
endif()
|
|
106
|
+
file(MAKE_DIRECTORY "${_va_out}")
|
|
107
|
+
set(_va_osdi "")
|
|
108
|
+
foreach(_name optical_source optical_term photodetector heater)
|
|
109
|
+
set(_src "${CMAKE_CURRENT_SOURCE_DIR}/va/${_name}.va")
|
|
110
|
+
set(_dst "${_va_out}/${_name}.osdi")
|
|
111
|
+
add_custom_command(
|
|
112
|
+
OUTPUT "${_dst}"
|
|
113
|
+
COMMAND ${_openvaf_launcher} "${_openvaf}" ${_openvaf_target} "${_src}" -o "${_dst}"
|
|
114
|
+
DEPENDS "${_src}"
|
|
115
|
+
COMMENT "OpenVAF ${_name}.va"
|
|
116
|
+
VERBATIM)
|
|
117
|
+
list(APPEND _va_osdi "${_dst}")
|
|
118
|
+
endforeach()
|
|
119
|
+
add_custom_target(socklight_va ALL DEPENDS ${_va_osdi})
|
|
120
|
+
install(FILES ${_va_osdi} DESTINATION socklight/va)
|
socklight-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Floris Laporte
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
socklight-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
socklight
|
|
2
|
+
Copyright (c) socklight contributors
|
|
3
|
+
|
|
4
|
+
This product includes software derived from sax (https://github.com/flaport/sax,
|
|
5
|
+
as developed at gdsfactory/sax), commit c22ed91, licensed under the Apache License,
|
|
6
|
+
Version 2.0. See LICENSE and VENDORED.md. Vendored files are modified: jax is replaced
|
|
7
|
+
by numpy.
|
socklight-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# socklight
|
|
2
|
+
|
|
3
|
+
sax's optical models on numpy, exposed to the VACASK circuit simulator as OSDI devices. Every
|
|
4
|
+
model in socklight's Python registry becomes one device of `socklight.osdi`, which VACASK's
|
|
5
|
+
Python extension loads like any other OSDI file. The design is in `docs/design.md`; the optical
|
|
6
|
+
port convention is in `docs/iq-convention.md`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pip install socklight
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Wheels exist for Linux (x86_64, aarch64; CPython 3.10–3.14) and for Pyodide 314
|
|
15
|
+
(Python 3.14, the Pyodide marimo ships), where `micropip.install("socklight")` works the same.
|
|
16
|
+
They pull in VACASK's Python extension (`vacask`).
|
|
17
|
+
|
|
18
|
+
Building from source needs a C compiler and CMake. The Verilog-A helpers are compiled with
|
|
19
|
+
the `openvaf-r` that `vacask-bin` (a build requirement) ships; pass `-DOPENVAF_COMPILER=...`
|
|
20
|
+
through `CMAKE_ARGS` to use another one. For a development install:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install vacask-bin scikit-build-core pytest
|
|
24
|
+
pip install -e . --no-build-isolation
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`socklight.osdi` is built against the Python headers only and does not link libpython. It
|
|
28
|
+
works only inside a Python process that has `vacask` imported. The standalone `vacask` binary
|
|
29
|
+
cannot load it.
|
|
30
|
+
|
|
31
|
+
## A minimal deck
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import socklight # registers the standard library (socklight.models)
|
|
35
|
+
|
|
36
|
+
netlist = f"""mmi demo
|
|
37
|
+
ground 0
|
|
38
|
+
load "{socklight.osdi_path()}"
|
|
39
|
+
load "{socklight.va_path("optical_source")}"
|
|
40
|
+
load "{socklight.va_path("optical_term")}"
|
|
41
|
+
model src optical_source
|
|
42
|
+
model term optical_term
|
|
43
|
+
model mmi 'socklight.models:mmi2x2' loss_db=0.3
|
|
44
|
+
s1 (o1_i o1_q) src p=1
|
|
45
|
+
x1 (o1_i o1_q o2_i o2_q o3_i o3_q o4_i o4_q) mmi wl=1.55
|
|
46
|
+
t2 (o2_i o2_q) term
|
|
47
|
+
t3 (o3_i o3_q) term
|
|
48
|
+
t4 (o4_i o4_q) term
|
|
49
|
+
"""
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Run it with the `vacask` Python API (parse, elaborate, run an `op` analysis); `tests/conftest.py`
|
|
53
|
+
shows how.
|
|
54
|
+
|
|
55
|
+
- The device name is the model's resource path, `package.module:callable`. VACASK identifiers
|
|
56
|
+
cannot contain `.` or `:`, so put it in single quotes on the `model` line.
|
|
57
|
+
- Each optical port `p` has two terminals, `p_i p_q`. Ports are listed in `sorted()` order.
|
|
58
|
+
For `mmi2x2` that is `o1 o2 o3 o4`.
|
|
59
|
+
- Every model parameter can be set on the `model` line or on an instance; the instance wins.
|
|
60
|
+
A parameter you don't set takes the Python signature default. A parameter whose default is
|
|
61
|
+
`None` is not passed to the model unless you set it.
|
|
62
|
+
- Every numeric parameter is a real in the deck. One whose Python default is an `int` or `bool`
|
|
63
|
+
(e.g. `loss_dB_cm=3`) still accepts any real: the model gets an `int` when the value is
|
|
64
|
+
integral (`loss_db_cm=2` gives `2`) and a `float` otherwise (`loss_db_cm=2.5` gives `2.5`).
|
|
65
|
+
- `socklight.va_path(name)` gives the Verilog-A helpers: `optical_source`, `optical_term`,
|
|
66
|
+
`photodetector` and `heater` (see `docs/iq-convention.md`).
|
|
67
|
+
|
|
68
|
+
### Parameter names are lowercase
|
|
69
|
+
|
|
70
|
+
VACASK lowercases device and parameter names when it loads an OSDI file. Netlists must
|
|
71
|
+
write them in lowercase, including in sweeps. So sax's `loss_dB` is `loss_db` in a deck,
|
|
72
|
+
as is `parameter="loss_db"` in a sweep. socklight still calls the model with the original
|
|
73
|
+
`loss_dB`.
|
|
74
|
+
|
|
75
|
+
## Your own models
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import socklight
|
|
79
|
+
|
|
80
|
+
def ring(wl=1.55, kappa=0.1, loss_dB=0.0):
|
|
81
|
+
... # return a sax SDict at scalar wl
|
|
82
|
+
|
|
83
|
+
socklight.register("mypdk.models:ring", ring)
|
|
84
|
+
socklight.register_models("mypdk.models", {"ring": ring, "taper": taper}) # register() for each
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Register every model **before** the first netlist loads `socklight.osdi`. Its constructor
|
|
88
|
+
snapshots the registry once per process.
|
|
89
|
+
|
|
90
|
+
- After that, registering a new name, or a model whose ports or parameters (names, kinds,
|
|
91
|
+
defaults) differ, raises `RuntimeError` naming what changed.
|
|
92
|
+
- Registering the same signature again replaces the function. The next circuit setup uses
|
|
93
|
+
the new function, so a notebook can edit a model body without restarting.
|
|
94
|
+
- `register()` validates up front. It raises on a malformed name, a parameter without a
|
|
95
|
+
default, two names or parameters that collide case-insensitively, and a probe call that
|
|
96
|
+
fails.
|
|
97
|
+
|
|
98
|
+
## From a gdsfactory netlist
|
|
99
|
+
|
|
100
|
+
`socklight.netlist.netlist_to_deck` turns a flat netlist, as `Component.get_netlist()` returns it,
|
|
101
|
+
into a deck. It imports neither gdsfactory nor sax.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from socklight.netlist import netlist_to_deck
|
|
105
|
+
|
|
106
|
+
socklight.register_models("cspdk.si220", PDK.models) # before any deck loads socklight.osdi
|
|
107
|
+
deck = netlist_to_deck(c.get_netlist(), "cspdk.si220", params={"wl": 1.31})
|
|
108
|
+
i, q = deck.external["o1"] # nodes of external port o1: append a source here
|
|
109
|
+
netlist = deck.text + f'load "{socklight.va_path("optical_source")}"\nmodel src optical_source\n' \
|
|
110
|
+
+ f"s1 ({i} {q}) src p=1\n" # ...and terms or photodetectors on the other external ports
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- `models` is a prefix (component `coupler` uses `"cspdk.si220:coupler"`) or a mapping from
|
|
114
|
+
component to registered name. A component without a registered model raises `KeyError`.
|
|
115
|
+
- An instance's parameters are its `settings` with `info` merged over them, as `sax.circuit`
|
|
116
|
+
does. Keys that are not parameters of the model are left out and listed in `deck.dropped`
|
|
117
|
+
(layout-only settings such as `width` or `npoints` are normal there). `None` means "use the
|
|
118
|
+
model's default".
|
|
119
|
+
- `params` go to every instance whose model has that parameter, unless the instance sets it
|
|
120
|
+
itself: the instance wins.
|
|
121
|
+
- `variables=("wl",)` is `params` by reference: each instance whose model has `wl` (and does not
|
|
122
|
+
set it) gets `wl=wl`, a VACASK circuit variable, so a single sweep moves every instance. A name
|
|
123
|
+
in both `params` and `variables` raises `ValueError`. `deck.variables` lists them; declare each
|
|
124
|
+
one before elaboration or VACASK will not resolve it:
|
|
125
|
+
|
|
126
|
+
socklight runs inside a Python process, and VACASK's Python API ignores a deck's `control`
|
|
127
|
+
block, so declare and sweep the variable through the API:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from vacask import (Circuit, OpenvafCompiler, Parser, ParserTables, Status, Value,
|
|
131
|
+
Analysis, PTAnalysis, PTSave, PTSweep, PV, simulator)
|
|
132
|
+
|
|
133
|
+
deck = netlist_to_deck(c.get_netlist(), "cspdk.si220", variables=("wl",))
|
|
134
|
+
text = deck.text + "..." # append sources and detectors
|
|
135
|
+
|
|
136
|
+
simulator.setup()
|
|
137
|
+
s = Status()
|
|
138
|
+
tab = ParserTables("models")
|
|
139
|
+
Parser(tab).parseNetlistString(text)
|
|
140
|
+
tab.verify(s)
|
|
141
|
+
compiler = OpenvafCompiler()
|
|
142
|
+
cir = Circuit(tab, compiler, s)
|
|
143
|
+
cir.setVariable("wl", Value(1.55)) # before elaborate
|
|
144
|
+
cir.elaborate([], "__topdef__", "__topinst__", status=s)
|
|
145
|
+
|
|
146
|
+
desc = PTAnalysis("op1", "op")
|
|
147
|
+
sweep = PTSweep("s")
|
|
148
|
+
sweep.add(PV("variable", "wl"))
|
|
149
|
+
sweep.add(PV("values", [1.50, 1.52, 1.55, 1.58, 1.60]))
|
|
150
|
+
desc.add(sweep)
|
|
151
|
+
analysis = Analysis.create(desc, cir, s)
|
|
152
|
+
analysis.add(PTSave("default"))
|
|
153
|
+
analysis.run(s) # writes op1.raw, one point per wavelength
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Keep `tab`, `compiler` and `desc` referenced until the run is done: with vacask 0.3.4.dev6 the
|
|
157
|
+
circuit and the analysis do not keep them alive themselves.
|
|
158
|
+
- Each net is one node pair `n<k>_i n<k>_q`. An external port `p` is `p_i p_q` (sanitized if `p`
|
|
159
|
+
is not a VACASK identifier). An instance port that is on no net and not external is
|
|
160
|
+
terminated with `optical_term`. The deck always loads it as model `optical_term`, so appended
|
|
161
|
+
lines can use it.
|
|
162
|
+
- The deck has no sources, detectors or analysis. Append them.
|
|
163
|
+
|
|
164
|
+
## Errors
|
|
165
|
+
|
|
166
|
+
VACASK reports only error codes for OSDI failures, so socklight records the details on the
|
|
167
|
+
Python side:
|
|
168
|
+
|
|
169
|
+
- `socklight.load_error()`: why `socklight.osdi` exported no devices (a registry over capacity
|
|
170
|
+
or a failed snapshot), else `None`.
|
|
171
|
+
- `socklight.last_error()`: the last setup failure, as a dict with `model`, `params` and
|
|
172
|
+
`traceback`. Possible causes:
|
|
173
|
+
- the model raised;
|
|
174
|
+
- it returned a non-finite entry;
|
|
175
|
+
- its ports changed;
|
|
176
|
+
- `I + S` is singular;
|
|
177
|
+
- the instance connects too few terminals ("connected k of 2n terminals").
|
|
178
|
+
|
|
179
|
+
The simulation fails with "Fatal error during setup".
|
|
180
|
+
|
|
181
|
+
## Sweeping wavelength
|
|
182
|
+
|
|
183
|
+
`wl` is an ordinary parameter, so VACASK's own sweep works, whether `wl` is given on the
|
|
184
|
+
instance, on the model line, or not at all:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
control
|
|
188
|
+
sweep wl_sweep instance="x1" parameter="wl" values=[1.50, 1.52, 1.54, 1.55, 1.56]
|
|
189
|
+
analysis op1 op
|
|
190
|
+
endc
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Each point re-runs the device's setup, where the model is evaluated. `eval` and `load` never
|
|
194
|
+
call Python. When the sweep finishes, VACASK restores the original value.
|
|
195
|
+
`tests/test_native_sweep.py` builds such sweeps from Python. You can also re-elaborate one
|
|
196
|
+
circuit per point, as `tests/test_sweep.py` does.
|
|
197
|
+
|
|
198
|
+
## Examples and cross-checks
|
|
199
|
+
|
|
200
|
+
- `examples/mzi_tia.py`: a heater-tuned MZI feeding a photodetector and a TIA built from VACASK's
|
|
201
|
+
bundled `opamp`. Sweeping the heater voltage from 0 to 4 V swings the TIA output between
|
|
202
|
+
about 0 V and -4.9 V.
|
|
203
|
+
- `tools/circulax_heater.py`, run in a venv with jax, sax, circulax and cspdk (not socklight):
|
|
204
|
+
- It builds the same heater MZI in circulax with cspdk's `ThermalPhaseShifter` and writes
|
|
205
|
+
`tests/data/circulax_heater.json`. `tests/test_circulax.py` compares that file with the
|
|
206
|
+
VACASK run of the socklight heater.
|
|
207
|
+
- Over an 11-point sweep from 0 to 2 V, the two detector powers differ by at most 4.3e-9.
|
|
208
|
+
circulax against a closed-form numpy MZI also differs by 4.3e-9.
|
|
209
|
+
- Agreement is expected for the forward configuration only. circulax's heater is a VCVS and
|
|
210
|
+
is non-reciprocal at `o2`, so reverse drive is not compared.
|
|
211
|
+
- Why the two ranges differ: the heater has R = 0.375 ohm/um × 320 um = 120 ohm, and its phase
|
|
212
|
+
is `dphi = pi × 12.5 × V^2 / 120`.
|
|
213
|
+
- 0 to 2 V gives up to 0.42 pi, part of one fringe. That is enough for a point-by-point
|
|
214
|
+
numerical comparison and keeps the circulax run small.
|
|
215
|
+
- 0 to 4 V gives up to 1.67 pi, so the demo passes through full extinction and shows the
|
|
216
|
+
TIA's whole output swing.
|