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

Command-Line Arguments Not Recognized by PETSc.Options/uw.options #232

Closed
gthyagi opened this issue Aug 23, 2024 · 7 comments
Closed

Command-Line Arguments Not Recognized by PETSc.Options/uw.options #232

gthyagi opened this issue Aug 23, 2024 · 7 comments

Comments

@gthyagi
Copy link
Contributor

gthyagi commented Aug 23, 2024

I'm encountering an issue where the command-line arguments passed to the script are not being recognized by PETSc.Options. Specifically, when running the script with python3 Example.py --case case4, the provided argument is not recognized. This is not getting updated

options = PETSc.Options() 
case = options.getString('case', default='case1') # uw.options.getString('case', default='case1')
@bknight1
Copy link
Member

Had the same issue (#210) just remove the PETSc import. UW handles the options now, no need to import PETSc

@gthyagi
Copy link
Contributor Author

gthyagi commented Aug 23, 2024

I initially tried using uw.options, but it didn't work. I then switched to using PETSc.Options, but that didn't resolve the issue either.

@bknight1
Copy link
Member

This should work:

import underworld3 as uw

res  = uw.options.getInt("res")

print(f'res = {res}', flush=True)

from the command line:

python3 test.py -uw_res 5

should print 'res = 5' in terminal.

You may be missing the -uw_ prefix?

@bknight1
Copy link
Member

bknight1 commented Aug 23, 2024

You have to remove/not import from petsc4py import PETSc otherwise it won't work

@bknight1
Copy link
Member

I'd also remove the default value, so it produces an error and stops the script from running

@gthyagi
Copy link
Contributor Author

gthyagi commented Aug 23, 2024

This should work:

import underworld3 as uw

res  = uw.options.getInt("res")

print(f'res = {res}', flush=True)

from the command line:

python3 test.py -uw_res 5

should print 'res = 5' in terminal.

You may be missing the -uw_ prefix?

Thanks @bknight1. This method works, but I'm planning to create a single .py file that can run both as a notebook and on NCI. If I can't set a default value, I may need to create two separate .py files.

@gthyagi
Copy link
Contributor Author

gthyagi commented Aug 23, 2024

You may be missing the -uw_ prefix?
yeah, you are correct. Adding -uw_ fixes the issue.
Also, I did set default value and ran in parallel on mac. It worked. Hopefully it works without any error on NCI too.
Thanks.

@gthyagi gthyagi closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants