This may be an issue with mypy and not Nagini, but I discovered an issue when attempting to verify the following minimal Numpy program:
import numpy as np
from nagini_contracts.contracts import *
def matmult(A : np.matrix, B : np.matrix) -> np.matrix:
Requires(A.size == B.size)
Ensures(Result().size == A.size)
return A * B
The following KeyError is produced in Nagini
Traceback (most recent call last):
File "/home/josh/.pyenv/versions/3.8.18/bin/nagini", line 8, in <module>
sys.exit(main())
File "/home/josh/.pyenv/versions/3.8.18/lib/python3.8/site-packages/nagini_translation/main.py", line 352, in main
translate_and_verify(args.python_file, jvm, args, arp=args.arp, base_dir=args.base_dir)
File "/home/josh/.pyenv/versions/3.8.18/lib/python3.8/site-packages/nagini_translation/main.py", line 359, in translate_and_verify
modules, prog = translate(python_file, jvm, selected=selected, sif=args.sif, base_dir=base_dir,
File "/home/josh/.pyenv/versions/3.8.18/lib/python3.8/site-packages/nagini_translation/main.py", line 110, in translate
type_correct = types.check(path, base_dir)
File "/home/josh/.pyenv/versions/3.8.18/lib/python3.8/site-packages/nagini_translation/lib/typeinfo.py", line 339, in check
for dep_name in res_strict.graph[name].dep_line_map:
KeyError: 'numpy.core._multiarray_umath'
Notes
- I was unable to reproduce this with other libraries, such as
pillow (because of insufficient type annotations)
- This happens on any numpy program I attempt to verify
numpy.core._multiarray_umath is not a type but rather a module within numpy.
- I've tried this with several versions of numpy, with no difference
My thoughts (as an outsider to your project)
Digging around in your source code, it is evident that res_strict is built by mypy, and name (the variable causing the KeyError) is produced using each of all elements in relevant_files which is directly defined from [next(iter(res_strict.graph))]. This causes the KeyError to be especially confusing, as these are all supposed to be keys from res_strict.graph. Spitballing, it could be related to #37 but honestly it seems like an issue with mypy's Dict (since that's the type of res_strict.graph as you can see here).
This may be an issue with
mypyand not Nagini, but I discovered an issue when attempting to verify the following minimal Numpy program:The following
KeyErroris produced in NaginiNotes
pillow(because of insufficient type annotations)numpy.core._multiarray_umathis not a type but rather a module within numpy.My thoughts (as an outsider to your project)
Digging around in your source code, it is evident that
res_strictis built bymypy, andname(the variable causing the KeyError) is produced using each of all elements inrelevant_fileswhich is directly defined from[next(iter(res_strict.graph))]. This causes the KeyError to be especially confusing, as these are all supposed to be keys fromres_strict.graph. Spitballing, it could be related to #37 but honestly it seems like an issue with mypy'sDict(since that's the type ofres_strict.graphas you can see here).