-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic sync from the release candidate to main during a feature freeze. --------- Co-authored-by: Raul Torres <138264735+rauletorresc@users.noreply.github.com> Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com> Co-authored-by: Mehrdad Malek <39844030+mehrdad2m@users.noreply.github.com> Co-authored-by: Ahmed Darwish <exclass9.24@gmail.com> Co-authored-by: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: Romain Moyard <rmoyard@gmail.com> Co-authored-by: GitHub Actions Bot <>
- Loading branch information
1 parent
39e6baf
commit afa4759
Showing
6 changed files
with
233 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2022-2024 Xanadu Quantum Technologies Inc. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
This module contains warnings for using jax.scipy.linalg functions inside qjit. | ||
Due to improperly linked lapack symbols, occasionally these functions give wrong | ||
numerical results when used in a qjit context. | ||
As for now, we warn users to wrap all of these with a catalyst.accelerate() callback. | ||
This patch should be removed when we have proper linkage to lapack. | ||
See: | ||
https://app.shortcut.com/xanaduai/story/70899/find-a-system-to-automatically-create-a-custom-call-library-from-the-one-in-jax | ||
https://github.com/PennyLaneAI/catalyst/issues/753 | ||
https://github.com/PennyLaneAI/catalyst/issues/1071 | ||
""" | ||
|
||
import warnings | ||
|
||
import jax | ||
|
||
from catalyst.tracing.contexts import AccelerateContext | ||
|
||
|
||
class JaxLinalgWarner: | ||
def __init__(self, fn): | ||
self.fn = fn | ||
|
||
def __call__(self, *args, **kwargs): | ||
if not AccelerateContext.am_inside_accelerate(): | ||
warnings.warn( | ||
f""" | ||
jax.scipy.linalg.{self.fn.__name__} occasionally gives wrong numerical results | ||
when used within a qjit-compiled function. | ||
See https://github.com/PennyLaneAI/catalyst/issues/1071. | ||
In the meantime, we recommend catalyst.accelerate to call | ||
the underlying {self.fn.__name__} function directly: | ||
@qjit | ||
def f(A): | ||
return catalyst.accelerate(jax.scipy.linalg.{self.fn.__name__})(A) | ||
See https://docs.pennylane.ai/projects/catalyst/en/latest/code/api/catalyst.accelerate.html | ||
""" | ||
) | ||
return (self.fn)(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters