I have a python program which solves a large integer programming problem. I use Pyomo to model and Gurobi for solving. I have silenced gurobi, as it is rather chatty and pollutes the terminal output a bit. However, I would still like to show the user, that stuff is going on. How do you do that? All the progress-bar applications I have found obviously needs a "end time"/last iteration to function. I don't need a fancy progress bar. Just something that shows that program is still runing.
To illustrate my needs I have something like the following
print('Reading data')
readDataQuickly(...)
print('Data read. Now model will be created')
createModelQuickly(...)
print('Model created. Now solving starts')
veryTimeConsumingFunctionIDontControl(...) # <- Show stuff is going on here
print('Thanks for your patience')
I am using Python 3.10 if it matters
I have tried different kinds of process bars which works great, if I am the one who implemented the time consuming part, as I can add the progress indicator in e.g. loops. However, here I do not have access to the code of the solver, and hence, I cannot show progress from "outside".
[
Very simple to use this, you need to integrate inside your function to show the progress bar.
Related
I am currently trying to make EV-FlowNet work on my computer. EV-FlowNet is an open-source neural network for event-based optical flow estimation (full code here: https://github.com/daniilidis-group/EV-FlowNet). It is based on tensorflow but
unfortunately, I have no experience with this library so I have a hard time figuring out why things are not working. I have downloaded the trained network, the input data and the ground truth and have positioned them in the folders listed in the README file. I am trying to run 'test.py' and it runs without errors. However, it never enters into the main loop in which the results are visualized.
The condition for the main loop is this:
while not coord.should_stop():
coord is defined like this:
coord = tf.train.Coordinator()
and the threads are defined like this:
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
I have tried googling it but all I could find was that the threads stop if any of them call coord.request_stop(). Since I can't find anything in the code that would make them stop, I am don't understand why coord.should_stop() is true from the very beginning. I know this questions is quite vague but since I have no experience with tensorflow I am not sure what other information might be required. This is why I have included the link to the entire code. Thanks in advance!
`
I am quite new to python (using python 3.10 interpreter) and I am creating a turtle traffic game where if the turtle object (player) gets to a certain y coordinate (towards the top of the screen) it triggers a method for the object. I've been stuck on figuring out why my condition is not being met (please see some screenshots below). I want the code to trigger the print statement ("reached") when the ycor() of the turtle object is > 100. I can't seem to pinpoint where I'm going wrong. Any help is greatly appreciated.
Screenshot of my code and the game screen
The only problem with your if statement is where it is located. Currently it's at top level, among a bunch of other code that you expect to only run once. Like that other code, the test is being run once, right at the start of the program. Since (presumably) the turtle starts below the finish line, you're not ever going to see it print the message.
You can fix the problem by moving the if statement into the code that moves the turtle, probably part of the Player class. That code runs each time the turtle moves, so it will repeat the test each time too.
I'm making a small game where you have to guess if the answer is cp1 or cp2 and I want to give the user some sort of hint. One way of doing that I think is by flashing the answer for a nano or milisecond to user, i.e. a new window would open with a : . Any ideas as to how to do this?
[...] flashing the answer for a nano or millisecond to user [....] in a new window [...]
A millisecond is too short (both for the human player -read about the persistence of vision- and for the Python interpreter); your screen is probably refreshed at 60Hz. Consider flashing for at least one tenth of a second (and probably more than that, you'll need to experiment, and you might make the flashing delay or period configurable). How to do that depends upon the widget toolkit you are using.
If using something above GTK, you'll need to find the Python binding to g_timeout_add, see also this.
If you use something above libSDL (e.g. pygame_sdl2), you need something related to its timers.
There are many other widgets or graphical frameworks usable from Python, and you need to choose one (look also into PyQt). Each of them has its own way to deal with timing, delays, windows, graphical display of text inside a window, etc...
If your system is Linux, see also time(7) for a general overview of time related things. Event loops (like those in graphics libraries) are built above a multiplexing system call such as poll(2) (or the old select, etc...).
You need to spend several days in reading more, choosing your graphical toolkit, before coding a single line of code of your game (which might need more code than what you imagine now).
I think the closest you can easily get to this affect is to just print to the console, but don't print the new-line (\n), just the carriage return (\r). This way you can write over the text after a couple of milliseconds. We do need to know the length of the thing we are printing so that we can be sure to completely override it with the next print.
The code for this would look something like:
import time
ms = 100
s = 'cp1'
print(s, end='\r')
time.sleep(ms / 1000)
print(' ' * len(s))
I'm assuming this can't be done easily but atm I've written for loops in python that take in multiple files from a folder and runs them against an executable to convert them into a readable format. Problem is, the number of files will be different almost every time I run the script. The whole process takes a while so a progress bar would be nice. I've been trying tqdm, progress, etc. modules, but they all seem to work based on a fixed number of iterations, which doesn't work for me.
Basically, is there any possible way to easily implement a progress bar which either calculates progress based on how long the process will take to perform the conversions, or based on how many there are to convert?
Though having said this, for one part of the code, instead of taking in files, it was easier to run a powershell script in cmd through python to keep it part of the same code. This script iterates through many many files and outputs 1 file. Again, is there a way to monitor the progress of this in python, even though in python the code is just running something in cmd?
Try PyProg! PyProg is an open-source library for Python to create super customizable progress indicators & bars.
It is currently at version 1.0.2; it is hosted on Github and available on PyPI (Links down below). It is compatible with Python 3 and 2.
I actually made PyProg because I needed a simple but super customizable progress bar library. And I made it super flexible as well, so you can use set_total(<total>) to set the total number of files you need to convert and use set_stat(<status>) to set the current progress, and it will calculate the percentage for you!
You can easily install it with: pip install pyprog. Some examples of using it is on the Github page for this project.
PyProg Github: https://github.com/Bill13579/pyprog
PyPI: https://pypi.python.org/pypi/pyprog/
I am new to processing, i found it by searching for "draw with coding" , and i tried it, seems every time i modify the code, i have to stop and render again to get the final result
Is there any way to get updated graph without re-rendering? that can be much more convenient for creating simple figures.
if not, is there any alternative to processing that can draw a graph with coding?
I've used Tikz in Latex, but that is just for Latex, I want something that can let me draw a figure by coding, I've suffered enough though using software like coreldraw, it lacks the fundamental elegance of coding..
thanks alot!
Please have a look at the FluidForms libraries.
easy to setup
documentation and video tutorials
as long as you don't run into exceptions, live code comfortably
if you prefix public variables with param you also get sliders for free :)
Do check out the video tutorials, especially this one:
Also, if using Python isn't a problem I recommend having a look at:
NodeBox
Field
Python is a brilliant scripting language - which makes prototyping/'live coding' easy(although it can be compiled and it also plays nicely with c/c++) and is easy to pick up and a joy to use.
In Processing, you must re-run your program to see the changes (graphically), unless you write code to receive input from the user to dynamically adjust what you are drawing. For creating user interfaces there's for example the controlP5 library (http://www.sojamo.de/libraries/controlP5/).
It doesn't support "live coding" (at least that I know of).
You must re-run the code to see the new result.
If Live coding is what you're looking for, check out Fluxus (http://www.pawfal.org/fluxus/) or Impromptu (http://en.wikipedia.org/wiki/Impromptu_(programming_environment)