Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9834e96c
提交
9834e96c
authored
1月 22, 2026
作者:
jessegrabowski
提交者:
Ricardo Vieira
1月 23, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restore jax bilinear_to_direct rewrite when `solve_sylvester` is not available
上级
ca26e81a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
68 行增加
和
0 行删除
+68
-0
rewriting.py
pytensor/tensor/_linalg/solve/rewriting.py
+37
-0
test_slinalg.py
tests/link/jax/test_slinalg.py
+31
-0
没有找到文件。
pytensor/tensor/_linalg/solve/rewriting.py
浏览文件 @
9834e96c
...
...
@@ -6,6 +6,10 @@ from pytensor.graph import Constant, graph_inputs
from
pytensor.graph.rewriting.basic
import
copy_stack_trace
,
dfs_rewriter
,
node_rewriter
from
pytensor.scan.op
import
Scan
from
pytensor.scan.rewriting
import
scan_seqopt1
from
pytensor.tensor._linalg.solve.linear_control
import
(
SolveBilinearDiscreteLyapunov
,
solve_discrete_lyapunov
,
)
from
pytensor.tensor._linalg.solve.tridiagonal
import
(
tridiagonal_lu_factor
,
tridiagonal_lu_solve
,
...
...
@@ -269,3 +273,36 @@ scan_seqopt1.register(
use_db_name_as_tag
=
False
,
position
=
2
,
)
def
_load_solve_sylvester
():
# Thin import wrapper to help with testing
from
jax.scipy.linalg
import
solve_sylvester
return
solve_sylvester
@node_rewriter
([
SolveBilinearDiscreteLyapunov
])
def
jax_bilinear_lyapunov_to_direct
(
fgraph
,
node
):
"""
Replace SolveBilinearDiscreteLyapunov with a direct computation that is supported by JAX < 0.8
"""
try
:
_load_solve_sylvester
()
return
None
except
ImportError
:
# solve_sylvester is only available in jax > 0.8, which is not available on conda-forge.
# If it's not available, we can drop back to method="direct"
A
,
B
=
node
.
inputs
result
=
solve_discrete_lyapunov
(
A
,
B
,
method
=
"direct"
)
return
[
result
]
optdb
.
register
(
"jax_bilinear_lyapunov_to_direct"
,
dfs_rewriter
(
jax_bilinear_lyapunov_to_direct
),
"jax"
,
position
=
0.9
,
# Run before canonicalization
)
tests/link/jax/test_slinalg.py
浏览文件 @
9834e96c
...
...
@@ -291,6 +291,37 @@ def test_jax_solve_discrete_lyapunov(
)
def
test_bilinear_to_direct_rewrite
(
monkeypatch
):
mock_called
=
[]
def
mock_load_solve_sylvester
():
mock_called
.
append
(
True
)
raise
ImportError
(
"Simulated ImportError for testing."
)
monkeypatch
.
setattr
(
"pytensor.tensor._linalg.solve.rewriting._load_solve_sylvester"
,
mock_load_solve_sylvester
,
)
A
=
pt
.
tensor
(
name
=
"A"
,
shape
=
(
3
,
3
))
B
=
pt
.
tensor
(
name
=
"B"
,
shape
=
(
3
,
3
))
out
=
linear_control
.
solve_discrete_lyapunov
(
A
,
B
,
method
=
"bilinear"
)
atol
=
rtol
=
1e-8
if
config
.
floatX
==
"float64"
else
1e-3
compare_jax_and_py
(
[
A
,
B
],
[
out
],
[
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
config
.
floatX
),
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
config
.
floatX
),
],
jax_mode
=
"JAX"
,
assert_fn
=
partial
(
np
.
testing
.
assert_allclose
,
atol
=
atol
,
rtol
=
rtol
),
)
assert
mock_called
@pytest.mark.parametrize
(
"permute_l, p_indices"
,
[(
True
,
False
),
(
False
,
True
),
(
False
,
False
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论