-
Notifications
You must be signed in to change notification settings - Fork 310
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
Feat: Slack bot integration #427
Conversation
lol this is super cool! May need more massaging though, as dataset.sync() may disappear soon, and same goes for the hiddenupdatewidget ! We can definitely work a way to insert the slack class into the code base, I have the feeling that this should rather be a daemon-like process (such as monitoring) than a widget like thing :D Terrific contribution ! |
@giulioungaretti I wasn't aware that dataset.sync() would disappear, will it not be necessary later on? And I was initially also thinking of a subprocess, but with the current multiprocessing architecture I ran into problems with retrieving the latest plot. Also, I noticed some cool things you can do when the Slack bot is a widget instead of a subprocess. For instance, you can create a cell, fill it with a chunk of code, and then execute it. I'm using this to run measurements from Slack atm, although I'm not sure if this functionality should be part of the QCoDeS package |
@giulioungaretti I realized this code doesn't need widgets nor multiprocessing. Instantiating it in a different thread is sufficient. Would this PR be useful for qcodes? If so I can make the changes. What folder would now be a good location for the code? |
We can definitely add this! I would make an extra folder next to utils. |
The new version of slack is a thread, and so does not need a ipython widget. Furthermore, the active_loop and active_data_set functions have been added, since slack needs access to the active loop and data_set. active_loop() will point to the active loop. this is set when calling loop.run(set_active=True), where set_active is True by default. In some cases a measurement can itself consist of measurements. For instance, a complex parameter could perform an entire measurement. To avoid that the active_loop is overwritten, the kwarg set_active=False can be added.
@giulioungaretti I upgraded the Slack class, it now is a subclass of threading.Thread. The main advantage here is that it operates as a separate thread without depending on ipython widgets. Starting the Slack client is very easy, namely as such:
Since the Slack class needs access to the latest measurement and plot, I also added some functionality to BasePlot and loops.py. BasePlot now has the class attribute For loops I did something similar: I created ActiveLoop.active_loop. Using this, I added the two functions active_loop() and active_data_set(), which calls active_loop(). When running a loop with kwarg set_active=True (True by default), it will set ActiveLoop.active_loop to itself for the duration of the measurement. This also works with Measure. In the cases where you have a Loop in which a complex parameter itself creates a Loop or Measure, you can avoid overwriting active_loop by adding set_active = False. I noticed that active_loop and active_data_set are also useful in other ways. For instance, you can use the folder of the active dataset as a base folder, and any parameters that create Loops can create subfolders in the base dataset folder. I added the two functions to qcodes init, so they can be accessed easier. I finally also added slacker as an optional package in the setup |
looks good to me! @jenshnielsen @WilliamHPNielsen ? |
Looks good to me |
great will review the code and merge//ask for changes today ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nulinspiratie small comments, the ready to merge!
from qcodes import active_loop, active_data_set | ||
|
||
|
||
def convert_command(text): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this? Isn't there one extra def () ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, the try_convert_str is a function that's only called within convert_command, so I made it a subfunction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nulinspiratie shut, never mind I totally misread the code. Just catch the right Value error and then I can merge!
qcodes/utils/slack.py
Outdated
try: | ||
val = float(string) | ||
return val | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just catch: ValueError here :D
qcodes/utils/slack.py
Outdated
try: | ||
val = int(string) | ||
return val | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just catch: ValueError here :D
Author: Serwan Asaad <serwan.asaad@gmail.com> Feat: Slack bot integration (#427)
* Added slack bot * Added latest_dataset/latest_plot * refactor: moved slack.py to utils * feat: upgraded slack, added active_loop, active_data_set The new version of slack is a thread, and so does not need a ipython widget. Furthermore, the active_loop and active_data_set functions have been added, since slack needs access to the active loop and data_set. active_loop() will point to the active loop. this is set when calling loop.run(set_active=True), where set_active is True by default. In some cases a measurement can itself consist of measurements. For instance, a complex parameter could perform an entire measurement. To avoid that the active_loop is overwritten, the kwarg set_active=False can be added. * added slacker to extra packages * Removed .idea from PyCharm * fix: Added catching of ValueError
* Added slack bot * Added latest_dataset/latest_plot * refactor: moved slack.py to utils * feat: upgraded slack, added active_loop, active_data_set The new version of slack is a thread, and so does not need a ipython widget. Furthermore, the active_loop and active_data_set functions have been added, since slack needs access to the active loop and data_set. active_loop() will point to the active loop. this is set when calling loop.run(set_active=True), where set_active is True by default. In some cases a measurement can itself consist of measurements. For instance, a complex parameter could perform an entire measurement. To avoid that the active_loop is overwritten, the kwarg set_active=False can be added. * added slacker to extra packages * Removed .idea from PyCharm * fix: Added catching of ValueError
This pull request adds a QCoDeS slack bot that provides information about current measurements.
The user can communicate with the Slack bot via instant messaging (see image below).
The slack bot currently has the following functionality:
A few notes
Slack.update()
must be made, and so the Slack bot works best as a widget in multiprocessing.@giulioungaretti @AdriaanRol