-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using with SageMath #58
Comments
Hey @darkl! Could you provide a little more information about your dev environment (e.g. Pylance version, VSCode version etc)? This will help us debug. Additionally, could you check if this reproduces on the latest version, 2020.7.0? |
Pylance version: v2020.7.0 It doesn't seem to generate intellisense/documentation with the latest version. Thanks! |
From that guide, this looks to be a completely different notebook/language type than Python, no? It relies on patching the Python extension to treat the Sage stuff as python, when it actually isn't. I'm not sure that this is a supported scenario, as the Python extension's notebook support is currently only suited for Python code (and contains many workarounds to get rich features from regular Python code editing into the notebook view). Perhaps @microsoft/datascience-vsc-team may be more able to define what's expected here. |
I wouldn't say it's a completely different language, SageMath is an extension of Python, and any code written in Python in theory should run of Sage. Since the source code of SageMath is written in Python, I did expect to be able to get intellisense/documentation for methods. I would remark that listing of the methods works well after initializing an object of some type (much better than the web browser interface), but the trouble is that no parameters intellisense/documentation is provided. |
Fair enough, thanks for the correction.
I think you may just have the tooltip hidden. If you hover over the selected completion line, does a ">" appear where you can expand the tooltip to get more info? VS Code unfortunately hides this info by default. |
Dev from microsoft/datascience-vsc-team here, just wanted to add for context that we are working on support for multiple language kernels in our notebook experience, tracked in microsoft/vscode-python#12111 and https://github.com/microsoft/vscode-python/issues/11919 :) |
Unfortunately, there is no ">" and Ctrl+Space just shows all the variables/functions available in the scope. |
The key thing here is that SageMath is a superset of Python. If you look at the original example, the code in its entirety is: finiteField = GF(25)
finiteField. But where did The reason this appears to work at all is because the notebook code calls both the kernel and Pylance to get completions, then merges their info together. The kernel has the live data, and because you've patched Sage in as the kernel, it knows how to answer the question and gets a result. Pylance answers "IDK", and the frontend just uses what the kernel answered, which currently isn't as rich as what the language server offers for normal Python code. Perhaps this could change in general (the notebook code recently changed to allow some of the live data to come through), but that's a different discussion about how to handle non-Python languages. Python code runs in Sage, but that doesn't imply the Sage can be read as Python, and Pylance only knows about Python. |
Hey @darkl, I'm the one who wrote the instructions you linked for getting Sage to work with VSCode's Jupyter. I don't use Pylance myself but I suspect the issue you're seeing is actually a Pylance <-> VSCode Jupyter issue, and not one specific to Sage. In any case, it should be possible to use Pylance with Sage if you use Python modules. If you have Sage notebook running locally, this can be accomplished by:
1. Creating the Python moduleThe Python module should at least have a
To use Sage functions in your source files, all you have to do is import # /path/to/your/python/modules/mymodule/implementation.py
from sage.all import *
x = var('x') # Using sage's `var` function.
y = sin(x) # Checking the type of `y` here will give you the sage `Expression` type
z = 3.4 # In a Sage notebook, this `z` would be a `RealNumber`, however you will find that it is a `float`.
# This is a drawback of using the module pattern but the solution is using the assignment example below:
z2 = RealNumber(3.4) # Use the `RealNumber()` object constructor (and `Integer()` etc.) to assign literals. To address linting in VSCode, you'll need to specify the path to the Sage Python library in the VSCode "python.autoComplete.extraPaths": [
"/path/to/your/SageMath-9.2/local/lib/python3.8/site-packages"
] Pylance should probably read this config as well, otherwise you'll need to provide similar paths to Pylance's configs. With these source files, you should be able to use Pylance with Sage. 2 & 3. Setting up Sage notebook for Python module usageTo accomplish, I have the following as my first cell of my Sage notebook:
4. Importing your Python module in your Sage notebookNow, in your Sage notebook, you can import your module within one of your cells and use its code: from mymodule.implementation import z2
z2 + 3 # This will print out '6.4' Notes:Most Sage functionality will be imported from |
Hi @Daniel-Khodabakhsh, thanks for the detailed reply! I will give it a try! Elad |
Alice splits the M-Series message into several parts using Shamir's Threshold Secret Sharing scheme and distributes it between Bob, Carol and Oscar. Retrieve the M message using SageMath. p = 98610077260239398222090992029437657450932580712058628707362467948344492057365826464402904054263162278966613878648712696840664890977708159054505909356614775685384800153427070438012782055016614367597928500125115244063783154699188478772541892057527093871947446448825987166591681265594660523952919275117854741557 |
Hello my friends |
I am using VSCode with SageMath Jupyter notebooks. I followed these instructions for that. It works well, but I was wondering if I could use Pylance for intellisense and autocomplete? For instance, I would like to see documentation for the methods of the SageMath objects. Currently I don't.
Thanks for your help
Elad
The text was updated successfully, but these errors were encountered: