iccmr-quantum / OSC-Qasm

A simple OSC Python interface for executing Qasm code.
MIT License
11 stars 1 forks source link

Feature Request - OSC-Qasm Plugins #47

Open Itaborala opened 2 years ago

Itaborala commented 2 years ago

Here's an idea: OSC-Qasm is a bridge connecting max/pd/sc and python. Imagine I have a python script that takes a qasm circuit and does something different or more complex, maybe a pre or post-processing algorithm, circuit optimization, or an interesting statevector visualization/simulation - any separate python application that could use a qasm file.

Could we send the circuit to a new custom function through OSC-Qasm? If so, what is the best approach?

Some broad ideas to make this happen:

callback.map("/Custom", custom)


-  Files and called functions could have the same name

A second (or complementary) approach would be to use `os.system()` to run terminal commands and call new scripts and apps

Another strong consequence for the future is that this could *modularize* OSC-Qasm, allowing for better scaling and portability of the project, when considering quantum hardware from other companies and other quantum programming languages (helloo OSC-Qasm3!). Separate files would contain different functions for different applications/execution modes.

What do you think?

**TODO:**
- [ ] #50
- [ ] #49
- [ ] create first plugin: statevector holographic visualization with [QPi](https://github.com/zouppa/qpi)
Itaborala commented 2 years ago

Some great progress was made to make this feature possible. this commit instide this branch shows a simple example. I tested with Pd and in --headless mode, just send an osc message like so: /Custom testfile testfunc. The module testfile.py was imported and the function testfile.testfunc was called!

omarcostahamido commented 2 years ago

So, from OSC-Qasm server's perspective I'd ask myself: if the qasm code still needs to be changed before sending it to the machines, then why don't you only send me the FINAL version of the qasm code instead? From an OSC-Qasm cIient perspective though, looking at some of the simpler ones we have right now, I can understand that some additional massaging could be useful. 👉 That is to say that I am not yet sure of the immediate application of this: could you share a concrete example?

Are you suggesting transforming qasm into other type of instructions for other backends? That would also imply changing the portion of the code that is responsible for actually sending the job so... it might be a little bit more involved. Is that the idea? And, thinking back to end user: do you want them to have python in order to be able to do that?

Itaborala commented 2 years ago

Fear points, indeed. I agree with both arguments. From OSC-Qasm Server, there's no reason to manipulate the circuit. OSC-Qasm Client, however, could benefit from better circuit optimization/error mitigation (which can actually be interesting future features). But that's not the application that I have in mind.

Here's my concrete application idea: I have a circuit that is being constantly updated for QSphere visualizations (QAC Toolkit), and sometimes, I 'bang' the circuit into OSC-Qasm for counts. However, we came across this very interesting repo called QPi for 3D Qsphere visuals using Raspi. It was implemented in python and the main function receives a QuantumCircuit() object and does the rest of the work. So, in this case it would be more than just having a 'stavevector_simulator' option. if I have a dedicated raspi machine to receive Qasm data with OSC and run the jobs, wouldn't it make sense for me to import the Qpi function inside OSC-Qasm as well? Or at least a way to 'forward' the circuit to other scripts?

This means I want to send Qasm through OSC for visualization, not for jobs.

omarcostahamido commented 1 year ago

As discussed today, via qasmoverlatitudes, we'll make this the meta issue for allowing Plugins to be added to OSC-Qasm.

The idea of allowing Plugins to be added to OSC-Qasm might as well mean that it'll be a new major version. But it would need a good documentation to instruct users on how to build their own plugins. And give some thought into how to articulate it with the GUI version. Another question to be asked is: should we ship OSC-Qasm with some plugins already or make that an optional (additional repository) thing to download?

omarcostahamido commented 1 year ago

it might be good to start with a simple plugin example. Can you describe a couple toy examples like: