z3py on MacOSX: cannot get a model - z3

I am seeing a strange problem with z3py on Mac, was wondering if anyone has seen this before:
$ cat bug.py
from z3 import *
x = Int('x')
s = Solver()
s.add(x > 5)
print(s.check())
print(s.model())
$ python bug.py
sat
[x = ]
The value of x is missing from the model. I tried both master and unstable branches with the same result. However, z3 itself does give the correct model if run on a similar .smt2 file. My configuration is Mac OSX 10.6.8, Python 2.7.4.

The problem is very specific for my setup, but maybe someone will run into it as well: the root cause is that a wrong version of libgomp was picked up by the dynamic loader -- i.e. the versions used to compile and to run do not match.
Here is a more severe manifestation of this issue:
$ python
Python 2.7.4 (default, May 9 2013, 18:51:46)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from z3 import *
>>> IntVal(1)
>>>
The numeric value is not printed, i.e. the correct output is
>>> IntVal(1)
1
>>>
Setting DYLD_LIBRARY_PATH to point to the correct version of the library fixes the issue.

I don't see any problems with Z3 4.1 and Python 2.7.2 on my Mac OSX 10.8.3. I wonder if it's some sort of terminal issue that eats the characters for whatever reason. What do you see if you redirect the output to a file? (i.e., try "python bug.py > out". Does the contents of the file "out" look OK?)

Related

How to set up Raspberry Pi Buster and Intel NCS2 and OpenVINO with OpenCV trackers

Is there a definitive set of instructions to implement OpenCV trackers with OpenVINO and the now-obsolete NCS2 on a RPi 4b - Buster?
My understanding that the last OpenVINO to support the NCS2 was v2020.3.
I attempted to cross-compile using:
https://github.com/opencv/opencv/wiki/Intel-OpenVINO-backend#raspbian-buster
After installing opencv/opencv-contrib 4.5.5 from source:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.5'
>>> tracker = cv2.TrackerCSRT_create()
>>>
However, in a test.py script I have:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
I get the error relating to DNN_TARGET_MYRIAD:
cv2.error: OpenCV(4.5.5) /home/pi/opencv/modules/dnn/src/dnn.cpp:1414: error: (-215:Assertion failed) preferableBackend != DNN_BACKEND_OPENCV || preferableTarget == DNN_TARGET_CPU || preferableTarget == DNN_TARGET_OPENCL || preferableTarget == DNN_TARGET_OPENCL_FP16 in function 'setUpNet'
I then used this to install OpenVINO:
https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_raspbian.html
but using this version of OpenVINO (as the last to support the NCS2):
https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.3/l_openvino_toolkit_runtime...
I exported the paths to the new post cross-compiled opencv_install directory:
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python2.7/dist-packages/:$PYTHONPATH
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python3.7/site-packages/:$PYTHONPATH
$ export LD_LIBRARY_PATH=/home/pi/Desktop/opencv_install/lib/:$LD_LIBRARY_PATH
I set up the NCS2 with no errors :
$ sudo usermod -a -G users "$(whoami)"
$ sh /opt/intel/openvino_2020.3/install_dependencies/install_NCS_udev_rules.sh
then:
$ source /opt/intel/openvino_2020.3/bin/setupvars.sh
and then checked:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.3.0-openvino-2020.3.0'
>>> tracker = cv2.TrackerCSRT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute 'TrackerCSRT_create'
>>>
If I open a new terminal and $ source /opt/intel/openvino_2020.3/bin/setupvars.sh
then run a test.py script:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
...
I get a segmentation fault error.
So far I have not edited any of the setup scripts.
Thanks for any help! I'd like to put this NCS2 to work.
Generally, if you are able to run some OpenVINO demo with NCS2 after following this installation guide, then you should be able to use that OpenCV functionality (ensured that you had installed the correct OpenCV).
It's recommended to use the recent OpenVINO and OpenCV version.
As indicated in this OpenVINO System Requirements, the current recommended OpenCV version is 4.5.

glob module is refereed from system package instead of python venv

While trying to import glob in a python venv environment, it is referring to the system package and not the virtual environment even though pandas module is referring to the virtual environment.
I am using python 3.8 and I created a virtual environment using python venv :
cd trial_3
python3 -m venv trial_3_env
On trying to use glob module (which i haven't yet installed in the environment), I can see that it is not throwing any error, but using the glob module from the system packages.
Please find the screenshot showing the same below:
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ pip freeze
numpy==1.23.4
pyspark==3.3.0
python-dateutil==2.8.2
pytz==2022.6
six==1.16.0
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import glob
>>> glob.__file__
'/usr/lib/python3.8/glob.py'
>>>
I tried checking this behavior with pandas module, but they are working as expected and throw error while importing when I have not preinstalled them in my system.
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>>
Could someone let me know the cause of globs behavior ? and if such scenario can occur for other modules as well.
Thanks in advance!
#ChrisD and #sinoroc answers helped me. standard libraries of venv python interpreter are referenced from the system python interpreter path itself and venv folder doesn't have any python standard libraries stored inside.

vscode dev container python interactive (`tkagg`) plots

Expected Behavior (local environment: fresh MacOS 12.4 installation)
With no environment updates except $ pip3 install matplotlib, I can successfully run this simple plot from the Matplotlib documentation:
Example Code:
# testplot.py
import matplotlib.pyplot as plt
import numpy as np
# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")
plt.show()
Actual Output (saved to a .png after window opens):
Run $ python3 testplot.py in the terminal:
Observed Behavior (vscode python 3.8 dev container)
Disclaimer: This post does not address notebook-based plots (which work fine but are not always preferred)
However, when I run this in my dev container, I get the following error:
testplot.py:16: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
First Attempted Solution:
Following this previously posted solution, I specified the backend (export MPLBACKEND=TKAgg) before running the interpreter, but the error persists.
Second Attempted Solution:
Following the comments, I added the following lines to the script:
import matplotlib
matplotlib.use('tkagg')
In the v3.8 dev container, this addition changes the error to:
Traceback (most recent call last):
File "testplot.py", line 5, in <module>
matplotlib.use('tkagg')
File "/usr/local/python/lib/python3.8/site-packages/matplotlib/__init__.py", line 1144, in use
plt.switch_backend(name)
File "/usr/local/python/lib/python3.8/site-packages/matplotlib/pyplot.py", line 296, in switch_backend
raise ImportError(
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
Note: adding these two lines broke the local script as well. The point of the local example was to show that it plots stuff without installing anything except matplotlib.

Keras running in Docker very slow and crashes - ValueError: Feature my_feature is not in features dictionary

I can run Keras neural net locally on my W10 laptop fine
But same code running in Docker is extremely slow and always crashes with error:
ValueError: Feature my_feature is not in features dictionary.
The feature not found is always the target feature
There are version differences between laptop and container but I'm not convinced this has bearing
Laptop
Windows 10 Enterprise 64bit
Intel Core i7-7820HQ # 2.90GHz
16GB RAM
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
λ pip list | grep tensorflow
tensorflow 2.0.0
tensorflow-estimator 2.0.1
λ pip list | grep pandas
pandas 0.23.3
pandas-ml 0.6.1
λ pip list | grep numpy
numpy 1.17.4
Docker
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Python 3.6.10 (default, Apr 23 2020, 15:40:23)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
root#modelbuilder:~# pip list | grep tensorflow
tensorflow 2.3.0
tensorflow-estimator 2.3.0
root#modelbuilder:~# pip list | grep pandas
pandas 0.24.0
pandas-ml 0.6.1
root#modelbuilder:~# pip list | grep numpy
numpy 1.19.2
Verified what was mentioned here: ValueError: Feature not in features dictionary
Target is not being fed into feature columns, features correspond etc, and this would also fail locally.
Any help will be much appreciated
Figured this out.
Crash issue:
In error created feature column for target, so removed the target from features for columns
Slow Docker:
Was running model.fit() over and over (many times)

How to get CMake find_file to accept UNIX-style paths on MSYS2?

I'm using CMake 3.4.1, on Windows 10, with MSYS2 (everything up-to-date as of Dec. 25 2015).
When I use CMake's find_file command, it won't work unless the path is in Windows-style. This is a problem for me, because I'm trying to use findwxWidgets.cmake, which fails because of this.
For example:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
find_file(version_h version.h PATHS /mingw64/include/wx-3.0/wx)
message(STATUS "version_h: ${version_h}")
Running cmake spits out:
-- version_h: version_h-NOTFOUND
But it's clearly in there:
>>> file /mingw64/include/wx-3.0/wx/version.h
/mingw64/include/wx-3.0/wx/version.h: C source, ASCII text
I'm wondering if this is a bug, or if there's some obscure flag I have to set to get this to work. How do I get CMake's find_file to find files with UNIX-style paths?
MinGW-w64 cmake can't understand MSYS2 paths. You might propose a path transformation test program to the CMake developers, but that's fairly gross and I'd hope the would reject that. Instead these things must be solved case-by-case. wx-config, being a shell script, is providing an MSYS2 path.
This is a bug in the currently release MSYS2 wxWidgets packages that will be fixed in the next release. To work around it, find the line in /mingw64/bin/wx-config or /mingw32/bin/wx-config:
prefix=${input_option_prefix-${this_prefix:-/mingw64}}
(or /mingw32 of course) and add after it:
if [ "x${MSYSTEM}" = "xMINGW32" ] || [ "x${MSYSTEM}" = "xMINGW64" ]; then
prefix=$(cygpath -m ${prefix})
fi
Be careful to remove it at upgrade time though.

Resources