Skip to content
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

improved print_constant #1120

Merged
merged 20 commits into from May 14, 2024
Merged

improved print_constant #1120

merged 20 commits into from May 14, 2024

Conversation

bauom
Copy link
Contributor

@bauom bauom commented May 30, 2022

Print unknown constants using their values. This fixes #1047 but may be reverted in #1811 to prefer declaring constants with names. However this PR also adds support for NaN in C and an associated test. It also removes the duplicate _print_Constant function.

@EmilyBourne
Copy link
Member

Is this PR ready for its initial review or is it still in draft status? Both are indicated at the moment

@bauom
Copy link
Contributor Author

bauom commented May 31, 2022

Is this PR ready for its initial review or is it still in draft status? Both are indicated at the moment

i was explaining to the new interns something and i forgot it my bad.

@EmilyBourne
Copy link
Member

@bauom what is the status of this PR?

@bauom
Copy link
Contributor Author

bauom commented Nov 9, 2022

@bauom what is the status of this PR?

sorry i have totally forgotten about this PR i will fix it ASAP.

@bauom
Copy link
Contributor Author

bauom commented Dec 21, 2022

@EmilyBourne
i don't know if the issue below is a know issue.
the code below gives to different errors when using pyccel vs epyccel

def ret_pi():
    from math import pi
    return pi

pyccel error:

|fatal [syntax]: epyccel.py [29,11]| Pyccel has encountered syntax that has not been implemented yet. Please create an issue at https://github.com/pyccel/pyccel/issues and provide a small example of your problem. Do not forget to specify your target language (.join)

i used this code to run it with epyccel:

from numpy import pi
from pyccel.epyccel import epyccel
import numpy as np

def ret_pi():
    from math import pi
    return pi


def test_pi(language):
    f = ret_pi
    pf = epyccel(f, language=language)
    assert np.equal(f(), pf() )

test_pi('c')

epyccel error:

ERROR at shared library generation stage
Traceback (most recent call last):
  File "/home/bauom/dev/sandbox/test.py", line 15, in <module>
    test_pi('c')
  File "/home/bauom/dev/sandbox/test.py", line 12, in test_pi
    pf = epyccel(f, language=language)
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 333, in epyccel
    mod, fun = epyccel_seq( python_function_or_module, **kwargs )
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 168, in epyccel_seq
    execute_pyccel(pymod_filename,
  File "/home/bauom/dev/pyccel/pyccel/codegen/pipeline.py", line 386, in execute_pyccel
    generated_filepath = create_shared_library(codegen,
  File "/home/bauom/dev/pyccel/pyccel/codegen/python_wrapper.py", line 135, in create_shared_library
    wrapper_compiler.compile_module(wrapper_compile_obj,
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 305, in compile_module
    self.run_command(cmd, verbose)
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 429, in run_command
    raise RuntimeError(err_msg)
RuntimeError: Failed to build module
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c: In function ‘ret_pi_wrapper’:
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:30:10: error: lvalue required as left operand of assignment
   30 |     M_PI = ret_pi();
      |          ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:31:33: error: lvalue required as unary ‘&’ operand
   31 |     pi_tmp = Double_to_PyDouble(&M_PI);
      |                                 ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:20:12: warning: unused variable ‘pi’ [-Wunused-variable]
   20 |     double pi;
      |            ^~

@EmilyBourne
Copy link
Member

@EmilyBourne
i don't know if the issue below is a know issue.
the code below gives to different errors when using pyccel vs epyccel

def ret_pi():
    from math import pi
    return pi

pyccel error:

|fatal [syntax]: epyccel.py [29,11]| Pyccel has encountered syntax that has not been implemented yet. Please create an issue at https://github.com/pyccel/pyccel/issues and provide a small example of your problem. Do not forget to specify your target language (.join)

i used this code to run it with epyccel:

from numpy import pi
from pyccel.epyccel import epyccel
import numpy as np

def ret_pi():
    from math import pi
    return pi


def test_pi(language):
    f = ret_pi
    pf = epyccel(f, language=language)
    assert np.equal(f(), pf() )

test_pi('c')

epyccel error:

ERROR at shared library generation stage
Traceback (most recent call last):
  File "/home/bauom/dev/sandbox/test.py", line 15, in <module>
    test_pi('c')
  File "/home/bauom/dev/sandbox/test.py", line 12, in test_pi
    pf = epyccel(f, language=language)
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 333, in epyccel
    mod, fun = epyccel_seq( python_function_or_module, **kwargs )
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 168, in epyccel_seq
    execute_pyccel(pymod_filename,
  File "/home/bauom/dev/pyccel/pyccel/codegen/pipeline.py", line 386, in execute_pyccel
    generated_filepath = create_shared_library(codegen,
  File "/home/bauom/dev/pyccel/pyccel/codegen/python_wrapper.py", line 135, in create_shared_library
    wrapper_compiler.compile_module(wrapper_compile_obj,
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 305, in compile_module
    self.run_command(cmd, verbose)
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 429, in run_command
    raise RuntimeError(err_msg)
RuntimeError: Failed to build module
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c: In function ‘ret_pi_wrapper’:
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:30:10: error: lvalue required as left operand of assignment
   30 |     M_PI = ret_pi();
      |          ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:31:33: error: lvalue required as unary ‘&’ operand
   31 |     pi_tmp = Double_to_PyDouble(&M_PI);
      |                                 ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:20:12: warning: unused variable ‘pi’ [-Wunused-variable]
   20 |     double pi;
      |            ^~

There is no difference between pyccel and epyccel, you are trying to call pyccel on the file containing the epyccel command, therefore you are trying to pyccelise epyccel.py. If you just translate the function then you shouldn't have a problem.

I'm not sure about the second half though, it looks like you named a variable pi, but I don't see that in your code

@bauom
Copy link
Contributor Author

bauom commented Dec 29, 2022

@EmilyBourne
i don't know if the issue below is a know issue.
the code below gives to different errors when using pyccel vs epyccel

def ret_pi():
    from math import pi
    return pi

pyccel error:

|fatal [syntax]: epyccel.py [29,11]| Pyccel has encountered syntax that has not been implemented yet. Please create an issue at https://github.com/pyccel/pyccel/issues and provide a small example of your problem. Do not forget to specify your target language (.join)

i used this code to run it with epyccel:

from numpy import pi
from pyccel.epyccel import epyccel
import numpy as np

def ret_pi():
    from math import pi
    return pi


def test_pi(language):
    f = ret_pi
    pf = epyccel(f, language=language)
    assert np.equal(f(), pf() )

test_pi('c')

epyccel error:

ERROR at shared library generation stage
Traceback (most recent call last):
  File "/home/bauom/dev/sandbox/test.py", line 15, in <module>
    test_pi('c')
  File "/home/bauom/dev/sandbox/test.py", line 12, in test_pi
    pf = epyccel(f, language=language)
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 333, in epyccel
    mod, fun = epyccel_seq( python_function_or_module, **kwargs )
  File "/home/bauom/dev/pyccel/pyccel/epyccel.py", line 168, in epyccel_seq
    execute_pyccel(pymod_filename,
  File "/home/bauom/dev/pyccel/pyccel/codegen/pipeline.py", line 386, in execute_pyccel
    generated_filepath = create_shared_library(codegen,
  File "/home/bauom/dev/pyccel/pyccel/codegen/python_wrapper.py", line 135, in create_shared_library
    wrapper_compiler.compile_module(wrapper_compile_obj,
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 305, in compile_module
    self.run_command(cmd, verbose)
  File "/home/bauom/dev/pyccel/pyccel/codegen/compiling/compilers.py", line 429, in run_command
    raise RuntimeError(err_msg)
RuntimeError: Failed to build module
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c: In function ‘ret_pi_wrapper’:
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:30:10: error: lvalue required as left operand of assignment
   30 |     M_PI = ret_pi();
      |          ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:31:33: error: lvalue required as unary ‘&’ operand
   31 |     pi_tmp = Double_to_PyDouble(&M_PI);
      |                                 ^
/home/bauom/dev/sandbox/__epyccel__/__pyccel__/mod_l2hcaikn18un_l2hcaikn18un_wrapper.c:20:12: warning: unused variable ‘pi’ [-Wunused-variable]
   20 |     double pi;
      |            ^~

There is no difference between pyccel and epyccel, you are trying to call pyccel on the file containing the epyccel command, therefore you are trying to pyccelise epyccel.py. If you just translate the function then you shouldn't have a problem.

I'm not sure about the second half though, it looks like you named a variable pi, but I don't see that in your code

those are two file different
For pyccel i am just pyccelising the function ret_pi() the file only contains

def ret_pi():
    from math import pi
    return pi

I think there is a problem when we try to return a constant value that is an import but i am not sure if these are known issues.

@EmilyBourne
Copy link
Member

This is not a known problem. It is really weird!! We definitely need an issue for this

@bauom
Copy link
Contributor Author

bauom commented Dec 29, 2022

This is not a known problem. It is really weird!! We definitely need an issue for this

I will create an issue for this not sure if these are 2 issues different or the same problem that cause different effects.

@EmilyBourne
Copy link
Member

This is not a known problem. It is really weird!! We definitely need an issue for this

I will create an issue for this not sure if these are 2 issues different or the same problem that cause different effects.

I'm looking into it. It looks like the error is caused by the results of the FunctionDef at the syntactic stage

@EmilyBourne EmilyBourne reopened this Jul 28, 2023
@pyccel-bot
Copy link

pyccel-bot bot commented Jul 28, 2023

Hello! Welcome to Pyccel! Thank you very much for your contribution ❤️.

I am the GitHub bot. I will help guide you through the different stages necessary to validate a review in Pyccel. If you haven't yet seen our developer docs make sure you check them out here. Amongst other things they describe the review process that we have just started. You can also get in touch with our other developers on our Pyccel Discord Server.

To begin with I will give you a short checklist to make sure your pull request is complete. Please tick items off when you have completed them or determined that they are not necessary for this pull request. If you want me to run any specific tests to check out corner cases that you can't easily check on your computer, you can request this using the command /bot run X. Use the command /bot show tests to see a full list of the tests I can run. Once you have finished preparing your pull request and are ready to request reviews just take your PR out of draft, or let me know with the command /bot mark as ready. I will then run the full suite of tests to check that everything is as neat as you think before asking other contributors for reviews. You can get a full list of commands that I understand using /bot commands.

Here is your checklist:

  • Update AUTHORS file
  • Write a clear PR description
  • Add tests to check your code works as expected
  • Update documentation if necessary
  • Update Changelog
  • Ensure any relevant issues are linked
  • Ensure new tests are passing

@EmilyBourne
Copy link
Member

@bauom Yearly reminder about the existence of this PR ;)

@EmilyBourne
Copy link
Member

@bauom This is now blocking #1807 . Do you want me to finish it?

Copy link

@pyccel-bot pyccel-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job ! Your PR is using all the code it added/changed.

@pyccel-bot
Copy link

pyccel-bot bot commented May 3, 2024

Hey @pyccel/pyccel-dev ! @bauom has just created this great new pull request! Check it out and let me know what you think!

@pyccel-bot pyccel-bot bot requested a review from a team May 3, 2024 05:10
Copy link

@smazouz42 smazouz42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Looks good to merge

@EmilyBourne EmilyBourne marked this pull request as draft May 12, 2024 16:38
@EmilyBourne EmilyBourne marked this pull request as ready for review May 12, 2024 16:38
Copy link

@pyccel-bot pyccel-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job ! Your PR is using all the code it added/changed.

@pyccel-bot
Copy link

pyccel-bot bot commented May 12, 2024

Hey @yguclu, @EmilyBourne, this PR is looking pretty good. @bauom and @smazouz42 think it is ready to merge. Could you add your expertise to confirm that this follows all the coding conventions and fits in Pyccel's future plans? Thanks 😄

@pyccel-bot pyccel-bot bot added the Ready_for_review Received at least one approval. Requires review from senior developer label May 12, 2024
@pyccel-bot pyccel-bot bot requested review from EmilyBourne and yguclu May 12, 2024 16:58
Copy link
Member

@EmilyBourne EmilyBourne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with this PR as is. Some of the work will be superceded in #1811 so it is not critical if it is not perfect.
However I finished cleaning it up so it is still missing a senior review.

@pyccel-bot pyccel-bot bot added Ready_to_merge Approved by senior developer. Ready for final approval and merge and removed Ready_for_review Received at least one approval. Requires review from senior developer labels May 12, 2024
Copy link
Member

@yguclu yguclu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I just have one question.

pyccel/codegen/printing/fcode.py Show resolved Hide resolved
@github-actions github-actions bot marked this pull request as draft May 13, 2024 14:19
@pyccel-bot pyccel-bot bot removed the Ready_to_merge Approved by senior developer. Ready for final approval and merge label May 13, 2024
@pyccel-bot
Copy link

pyccel-bot bot commented May 13, 2024

@bauom, @yguclu has a few questions/comments about your code. Can you go through and see if you agree with them. If not go ahead and explain why. Once you've adressed all the comments let me know with /bot mark as ready and we will see if we can get approval.

@EmilyBourne EmilyBourne marked this pull request as ready for review May 13, 2024 15:07
Copy link

@pyccel-bot pyccel-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job ! Your PR is using all the code it added/changed.

@pyccel-bot pyccel-bot bot added the Ready_to_merge Approved by senior developer. Ready for final approval and merge label May 13, 2024
@EmilyBourne EmilyBourne merged commit d64be7f into devel May 14, 2024
14 checks passed
@EmilyBourne EmilyBourne deleted the devel-1047 branch May 14, 2024 06:51
EmilyBourne added a commit to pyccel/pyccel-cuda that referenced this pull request May 14, 2024
Print unknown constants using their values. This fixes pyccel#1047 but may be
reverted in pyccel#1811 to prefer declaring constants with names. However this
PR also adds support for `NaN` in C and an associated test. It also
removes the duplicate `_print_Constant` function.

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready_to_merge Approved by senior developer. Ready for final approval and merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print value of unknown constant
4 participants