neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
56 stars 14 forks source link

warning: pointer is missing a nullability type specifier #50

Closed cpieringer closed 1 year ago

cpieringer commented 1 year ago

Hi,

I ran a simple test using an example code from (https://computationalmindset.com/en/mathematics/solving-delay-differential-equations-in-python-using-numerical-methods.html). I got the results, however, I also got a set of warnings related to the type of pointers. I did not find any posts or issues about these warnings. I ran the example on MacOS, jitcdde version = 1.8.1 on a virtual environment with python38.

I know they are only warnings, but maybe there is something wrong with my setup.

Best, Christian

In file included from /var/folders/nz/2ft4b1c53sd0cwgd_4rfpqqr0000gn/T/jitcxde_7sb1fvpt/jitced_4.c:2:
In file included from /Users/me/.pyenv/versions/3.8.9/include/python3.8/Python.h:25:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        unsigned char   *_base;
                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: note: insert '_Nullable' if the pointer may be null
        unsigned char   *_base;
                        ^
                          _Nullable 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: note: insert '_Nonnull' if the pointer should never be null
        unsigned char   *_base;
                        ^
                          _Nonnull 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:138:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:138:32: note: insert '_Nullable' if the pointer may be null
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
                                           _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:138:32: note: insert '_Nonnull' if the pointer should never be null
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
                                           _Nonnull
...
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
                                                    _Nonnull
219 warnings generated.
Wrzlprmft commented 1 year ago

This looks like a problem with one of the standard libraries. Something similar was reported on SO. Can you try to compile the helloworld.c from that question and see whether it generates similar warnings?

cpieringer commented 1 year ago

Hi @Wrzlprmft, I did not receive any warning when I compiled or ran the example. I am using macOS Monterry. Do you have any suggestions about the warnings?

Wrzlprmft commented 1 year ago

Well, I still don’t see how JiTC*DE has anything to do with it or how I could possibly address this. Not being able to reproduce the problem doesn’t make it any easier.

You can probably deactivate the warnings with the following, but that’s only painting over the symptoms.

from jitcxde_common import DEFAULT_COMPILE_ARGS
[…]
DDE.compile_C( extra_compile_args = DEFAULT_COMPILE_ARGS + ["-Wno-nullability-completeness"] )
cpieringer commented 1 year ago

Hi, I am using this simple code below to test. I included the lines you suggested. However, I still get the warnings.

import numpy as np
import matplotlib.pyplot as plt
from jitcdde import jitcdde, y, t
from jitcxde_common import DEFAULT_COMPILE_ARGS

def delay(y, t):
    return np.abs(0.1 * t * y(0, 0.1 * t))

equation = [y(0, t - delay(y, t))]

dde = jitcdde(equation, max_delay=1000)
dde.compile_C( extra_compile_args = DEFAULT_COMPILE_ARGS + ["-Wno-nullability-completeness"] )

def initial_history_func_exp_pt(t):
    return [np.exp(t)]

plt.rcParams['font.size'] = 8
fig, axs = plt.subplots(1, 1)
fig.tight_layout(rect=[0, 0, 1, 0.95], pad=3.0)
fig.suptitle("$y'(t)=y(t-delay(y, t))$ solved by jitcdde")

ts = np.linspace(0, 30, 10000)

dde.past_from_function(initial_history_func_exp_pt)
ys = []
for t in ts:
    ys.append(dde.integrate(t))
axs.plot(ts, ys, color='red', linewidth=1)
axs.set_title('$ihf(t)=e^t$')

plt.show()

This is the warning:

In file included from /var/folders/nz/2ft4b1c53sd0cwgd_4rfpqqr0000gn/T/jitcxde_imepq0gu/jitced.c:2:
In file included from /Users/me/.pyenv/versions/3.8.9/include/python3.8/Python.h:121:
In file included from /Users/me/.pyenv/versions/3.8.9/include/python3.8/genobject.h:11:
In file included from /Users/me/.pyenv/versions/3.8.9/include/python3.8/pystate.h:10:
In file included from /Users/me/.pyenv/versions/3.8.9/include/python3.8/pythread.h:120:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:328:6: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
#if !_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT
     ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:197:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
        defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:328:6: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:197:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
        defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:537:6: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
#if !_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT
     ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:197:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
        defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:537:6: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/pthread.h:197:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
        defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
                                        ^
4 warnings generated.
/Users/me/.pyenv/versions/3.8.9/envs/ml38/lib/python3.8/site-packages/chspy/_chspy.py:11: RuntimeWarning: invalid value encountered in double_scalars
  return np.linalg.norm(x-y)/np.linalg.norm(np.mean((x,y)))
/Users/me/.pyenv/versions/3.8.9/envs/ml38/lib/python3.8/site-packages/jitcdde/_jitcdde.py:795: UserWarning: You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.
  warn("You did not explicitly handle initial discontinuities. Proceed only if you know what you are doing. This is only fine if you somehow chose your initial past such that the derivative of the last anchor complies with the DDE. In this case, you can set the attribute `initial_discontinuities_handled` to `True` to suppress this warning. See https://jitcdde.rtfd.io/#discontinuities for details.")
/Users/me/.pyenv/versions/3.8.9/envs/ml38/lib/python3.8/site-packages/jitcdde/_jitcdde.py:792: UserWarning: The target time is smaller than the current time. No integration step will happen. The returned state will be extrapolated from the interpolating Hermite polynomial for the last integration step. You may see this because you try to integrate backwards in time, in which case you did something wrong. You may see this just because your sampling step is small, in which case there is no need to worry.
  warn("The target time is smaller than the current time. No integration step will happen. The returned state will be extrapolated from the interpolating Hermite polynomial for the last integration step. You may see this because you try to integrate backwards in time, in which case you did something wrong. You may see this just because your sampling step is small, in which case there is no need to worry.")

Best

Wrzlprmft commented 1 year ago

Well, at least the warnings targeted are gone. You can add another flag to remove the remaining ones (see below).

However, searching for the new warning yields this SO question, which suggests that this is a problem with your compiler or standard libraries, which could be fixed by updating them.

That being said, here is a version of your minimal example that should run without warnings:

import numpy as np
from jitcdde import jitcdde, y, t
from jitcxde_common import DEFAULT_COMPILE_ARGS

def delay(y, t):
    return np.abs(0.1 * t * y(0, 0.1 * t))

equation = [y(0, t - delay(y, t))]

dde = jitcdde(equation, max_delay=500)
dde.compile_C( extra_compile_args = DEFAULT_COMPILE_ARGS + ["-Wno-nullability-completeness","-Wno-expansion-to-defined"] )

def initial_history_func_exp_pt(t):
    return [np.exp(t)]

ts = np.linspace(0.1, 30, 10)

dde.past_from_function(initial_history_func_exp_pt)
dde.adjust_diff()
ys = []
for t in ts:
    ys.append(dde.integrate(t))
cpieringer commented 1 year ago

Thank you @Wrzlprmft 👍🏼. That filter all the warning messages.