Jupyter vs. Command Line
I am having trouble understanding the difference between interacting with the Quantum Computer via a Jupyter Notebook and a virtual environment from the command line. What is the difference between these two interfaces? When is it better to use one vs. the other? Any thoughts or suggestions would be greatly appreciated.
Thanks,
Brian
Comments
Hi Brian,
The Jupyter Notebook is a tool to learn about how the QPU works.
In short, you are running commands from the dwave libraries against the QPU via the Jupyter Hub server.
The Jupyter Hub has libraries pre-installed and the environment is pre-configured for you ahead of time.
If you set up an environment in the command line, you are doing the same thing as in the Jupyter Notebook, except the code is running on your machine locally.
In both cases you are sending commands to the QPU.
One additional note about the Jupyter Notebooks is that they do not save your data, but are created from an image when needed.
If you want to persist any information after closing the Jupyter Notebook, you should copy it to your local machine and save it there.
I hope this was helpful!
Please let me know if I missed anything or if anything was unclear.
Hi Brian,
An additional note, in general Jupyter Notebooks are a learning tool.
They have code mixed with instructional comments.
Jupyter Notebooks can also be run locally on your machine.
In our case, we have a server where we can let users run the Jupyter Notebooks.
I thought this distinction might be important down the line.
We also have Jupyter Notebooks available for download via GitHub, which you would run locally:
https://github.com/dwavesystems/qboost/blob/master/demo.ipynb
How do you send a script or problem to the QPU from the command line? I am in the Ocean Environment on my machine and I have the script.
Additionally, I installed Ocean-SDK. I just can't figure out how to run my code on the D-Wave Machine. Thanks agains, your help is sincerely appreciated.
Best,
Brian
Hi Brian,
Please remember to censor out your API token, as it gives access to your QPU time.
When you want to send instructions to the QPU, you need to write a script using the Ocean libraries.
The Ocean libraries will send the requests to the QPU.
To run the actual script will depend on how you are running Python.
In most IDEs you can right click the script file and choose "Run".
When you want to run a python script from command prompt/terminal, you just need to run the script by typing the following:
python my_script.py
Here is an example of a very simple script that sends the problem to the QPU:
from dwave.system.samplers import DWaveSampler
from dwave.system.composites import EmbeddingComposite
my_sampler = EmbeddingComposite(DWaveSampler())
Q = {}
for a in range(0,10):
for b in range(0,10):
Q[(a,b)] = 1
response = my_sampler.sample_qubo(Q, num_reads=1)
print(list(response.samples()))
This is the line that makes requests to the QPU:
response = my_sampler.sample_qubo(Q, num_reads=1)
Running the "dwave config create" command will configure your sampler and token, so you don't need to include them in your solver instantiation statement.
If you hadn't run that command, you could instantiate the solver like this:
DWaveSampler(endpoint=my_endpoint, token=my_token, solver=my_solver)
I am getting this error when I run dwave ping. The problem I cannot solve is: How do you run a program on the D-Wave QPU. I took the class a couple months ago and I have run code on the QPU before, but the setup is hard to memorize and I am having trouble understanding the organization of the information in Leap. Generally, I know:
1. Set up a virtual environment
The problem with this step is I am not sure if 'source activate ocean' works or if there is a different way of doing this.
2. Connect to D-Wave system
The problem I am having here is I do not understand the configuration process. I know there is an API token and a bunch of other information I need to include, but I don't remember what information I am supposed to include vs. what information I can skip.
3. Run code
The problem I am having here is I am not sure how to send code to the D-Wave system. And, I am not sure if the code needs to be in the virtual environment. For example, I am in the 'ocean' environment on my machine, but I copied the example you provided as a script on my desktop. But, when I run 'python QPU_Example.py' nothing happens.
Hi Brian,
You do need to be in the virtual environment when you install the libraries and run the code.
Try running the commands:
dwave config ls
dwave config inspect
The first command will show you where your configuration file is.
Sometimes there will be more than one file, which can be a bit tricky.
If this happens, you might want to delete the config files listed in that command and run the create command again.
The second command will show you what you have in your config file.
It should look something like this:
Configuration file: auto-detected
Profile: auto-detected
---
token = DWV-*************************************************
solver = DW_2000Q_2_1
endpoint = https://cloud.dwavesys.com/sapi
client = qpu
This file has all of the information that you will need to run your code.
In particular, you need to make sure your api token, solver, and endpoint all look correct.
If you plan to post the output from these commands, please remember to remove your personal information and api token before doing so.
If these credentials are correct, you should get a good response from the dwave ping command.
Once this file exists, whenever you construct a solver, the code will automatically grab your configuration from the config file for you.
So, all you have to do is create a new sampler in your code without any arguments like this:
sampler = DWaveSampler()
I hope this helped!
For whatever reason, I still cannot get this to work. I keep getting a response saying there is an error in my configuration file. Thanks anyway.
I got d-wave ping to work, but now it won't recognize the embedding composite. I guess what I don't understand is how to integrate all of the d-wave libraries remotely. Any advice would be appreciated.
Hi Brian,
EmbeddingComposite needs to be imported before using it.
To use the libraries that connect with the QPU, they need to be installed in your environment.
Once the libraries are installed, they need to be imported into your project.
Please sign in to leave a comment.