Skip to content

Commit

Permalink
Rename runtime-simple to sample-program (Qiskit#52)
Browse files Browse the repository at this point in the history
* rename simple program to sample

* fix import
  • Loading branch information
jyu00 authored Jun 4, 2021
1 parent ae6707b commit 69b3703
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
34 changes: 17 additions & 17 deletions 00_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@
" Description: The aligned quantum kernel matrix evaluated with the optimized kernel parameters on the training data.\n",
" Type: numpy.ndarray\n",
"==================================================\n",
"runtime-simple:\n",
" Name: runtime-simple\n",
" Description: Simple runtime program used for testing.\n",
"sample-program:\n",
" Name: sample-program\n",
" Description: A sample runtime program.\n",
" Version: 1\n",
" Creation date: 2021-05-05T23:30:21Z\n",
" Creation date: 2021-06-04T14:11:19Z\n",
" Max execution time: 300\n",
" Input parameters:\n",
" - iterations:\n",
Expand Down Expand Up @@ -311,7 +311,7 @@
"id": "7090db0f",
"metadata": {},
"source": [
"To print the metadata of the program `runtime-simple`:"
"To print the metadata of the program `sample-program`:"
]
},
{
Expand All @@ -324,11 +324,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"runtime-simple:\n",
" Name: runtime-simple\n",
" Description: Simple runtime program used for testing.\n",
"sample-program:\n",
" Name: sample-program\n",
" Description: A sample runtime program.\n",
" Version: 1\n",
" Creation date: 2021-05-05T23:30:21Z\n",
" Creation date: 2021-06-04T14:11:19Z\n",
" Max execution time: 300\n",
" Input parameters:\n",
" - iterations:\n",
Expand All @@ -350,7 +350,7 @@
}
],
"source": [
"program = provider.runtime.program('runtime-simple')\n",
"program = provider.runtime.program('sample-program')\n",
"print(program)"
]
},
Expand All @@ -359,7 +359,7 @@
"id": "dc4339b3",
"metadata": {},
"source": [
"As you can see from above, the program `runtime-simple` is a simple program that has only 1 input parameter `iterations`, which indicates how many iterations to run. For each iteration it generates and runs a random 5-qubit circuit and returns the counts as well as the iteration number as the interim results. When the program finishes, it returns the sentence `All done!`. This program can only run for 300 seconds (5 minutes), and requires a backend that has at least 5 qubits."
"As you can see from above, the program `sample-program` is a simple program that has only 1 input parameter `iterations`, which indicates how many iterations to run. For each iteration it generates and runs a random 5-qubit circuit and returns the counts as well as the iteration number as the interim results. When the program finishes, it returns the sentence `All done!`. This program can only run for 300 seconds (5 minutes), and requires a backend that has at least 5 qubits."
]
},
{
Expand Down Expand Up @@ -391,7 +391,7 @@
"source": [
"Before we run a quantum program, we may want to define a callback function that would process interim results, which are intermediate data provided by a program while its still running. \n",
"\n",
"As we saw earlier, the metadata of `runtime-simple` says that its interim results are the iteration number and the counts of the randomly generated circuit. Here we define a simple callback function that just prints these interim results:"
"As we saw earlier, the metadata of `sample-program` says that its interim results are the iteration number and the counts of the randomly generated circuit. Here we define a simple callback function that just prints these interim results:"
]
},
{
Expand All @@ -410,7 +410,7 @@
"id": "e2a98178",
"metadata": {},
"source": [
"The following example runs the `runtime-simple` program with 3 iterations on `ibmq_montreal` and waits for its result. You can also use a different backend that supports Qiskit Runtime:"
"The following example runs the `sample-program` program with 3 iterations on `ibmq_montreal` and waits for its result. You can also use a different backend that supports Qiskit Runtime:"
]
},
{
Expand All @@ -437,7 +437,7 @@
" 'iterations': 3\n",
"}\n",
"options = {'backend_name': backend.name()}\n",
"job = provider.runtime.run(program_id=\"runtime-simple\",\n",
"job = provider.runtime.run(program_id=\"sample-program\",\n",
" options=options,\n",
" inputs=program_inputs,\n",
" callback=interim_result_callback\n",
Expand Down Expand Up @@ -489,7 +489,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Job c2ajo0m0lb0ph8orsprg is an execution instance of runtime program runtime-simple.\n",
"Job c2ajo0m0lb0ph8orsprg is an execution instance of runtime program sample-program.\n",
"This job ran on backend ibmq_montreal and had input parameters {'iterations': 3}\n"
]
}
Expand Down Expand Up @@ -524,7 +524,7 @@
}
],
"source": [
"retrieved_jobs = provider.runtime.jobs(limit=2)\n",
"retrieved_jobs = provider.runtime.jobs(limit=1)\n",
"for rjob in retrieved_jobs:\n",
" print(rjob.job_id())"
]
Expand Down Expand Up @@ -564,7 +564,7 @@
{
"data": {
"text/html": [
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>None</td></tr><tr><td>Terra</td><td>0.17.1</td></tr><tr><td>Aer</td><td>0.8.2</td></tr><tr><td>Ignis</td><td>None</td></tr><tr><td>Aqua</td><td>None</td></tr><tr><td>IBM Q Provider</td><td>0.13.0</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.9.1 (default, Feb 5 2021, 11:23:59) \n",
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>None</td></tr><tr><td>Terra</td><td>0.17.1</td></tr><tr><td>Aer</td><td>0.8.2</td></tr><tr><td>Ignis</td><td>None</td></tr><tr><td>Aqua</td><td>None</td></tr><tr><td>IBM Q Provider</td><td>0.13.1</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.9.1 (default, Feb 5 2021, 11:23:59) \n",
"[Clang 12.0.0 (clang-1200.0.32.28)]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>8</td></tr><tr><td>Memory (Gb)</td><td>16.0</td></tr><tr><td colspan='2'>Fri May 07 09:22:18 2021 EDT</td></tr></table>"
],
"text/plain": [
Expand Down
47 changes: 29 additions & 18 deletions 02_uploading_program.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"id": "2d6c91ec",
"metadata": {},
"source": [
"There are several runtime programs in the `programs` directory in this repository. `runtime_simple.py` is one of them. It is a simple runtime program that submits random circuits for user-specified iterations:"
"There are several runtime programs in the `programs` directory in this repository. `sample_program.py` is one of them. It is a sample runtime program that submits random circuits for user-specified iterations:"
]
},
{
Expand All @@ -106,7 +106,7 @@
"metadata": {},
"outputs": [],
"source": [
"\"\"\"A simple runtime program that submits random circuits for user-specified iterations.\"\"\"\n",
"\"\"\"A sample runtime program that submits random circuits for user-specified iterations.\"\"\"\n",
"\n",
"import random\n",
"\n",
Expand Down Expand Up @@ -377,7 +377,7 @@
"id": "d229d7cf",
"metadata": {},
"source": [
"The following example tests the `runtime-simple` program we saw earlier. It uses the `qasm_simulator` from Qiskit Aer as the test backend. It serializes and unserializes input data using `RuntimeEncoder` and `RuntimeDecoder`, which are the default en/decoders used by runtime."
"The following example tests the `sample-program` program we saw earlier. It uses the `qasm_simulator` from Qiskit Aer as the test backend. It serializes and unserializes input data using `RuntimeEncoder` and `RuntimeDecoder`, which are the default en/decoders used by runtime."
]
},
{
Expand All @@ -398,7 +398,10 @@
}
],
"source": [
"from qiskit_runtime.runtime_simple import runtime_simple\n",
"import sys\n",
"sys.path.insert(0, '..') # Add qiskit_runtime directory to the path\n",
"\n",
"from qiskit_runtime.sample_program import sample_program\n",
"from qiskit import Aer\n",
"from qiskit.providers.ibmq.runtime.utils import RuntimeEncoder, RuntimeDecoder\n",
"from qiskit.providers.ibmq.runtime import UserMessenger\n",
Expand All @@ -410,7 +413,7 @@
"serialized_inputs = json.dumps(inputs, cls=RuntimeEncoder)\n",
"unserialized_inputs = json.loads(serialized_inputs, cls=RuntimeDecoder)\n",
"\n",
"runtime_simple.main(backend, user_messenger, **unserialized_inputs)"
"sample_program.main(backend, user_messenger, **unserialized_inputs)"
]
},
{
Expand Down Expand Up @@ -445,7 +448,7 @@
"id": "39e87075",
"metadata": {},
"source": [
"Below shows the metadata JSON file of the `runtime-simple` program as an example:"
"Below shows the metadata JSON file of the `sample-program` program as an example:"
]
},
{
Expand All @@ -459,13 +462,13 @@
"output_type": "stream",
"text": [
"{\n",
" \"name\": \"runtime-simple\",\n",
" \"description\": \"Simple runtime program used for testing.\",\n",
" \"name\": \"sample-program\",\n",
" \"description\": \"A sample runtime program.\",\n",
" \"max_execution_time\": 300,\n",
" \"version\": 1.0,\n",
" \"version\": \"1.0\",\n",
" \"backend_requirements\": {\"min_num_qubits\": 5},\n",
" \"parameters\": [\n",
" {\"name\": \"iterations\", \"description\": \"Number of iterations to run. Each iteration generates a runs a random circuit.\", \"type\": \"int\", \"required\": true}\n",
" {\"name\": \"iterations\", \"description\": \"Number of iterations to run. Each iteration generates and runs a random circuit.\", \"type\": \"int\", \"required\": true}\n",
" ],\n",
" \"return_values\": [\n",
" {\"name\": \"-\", \"description\": \"A string that says 'All done!'.\", \"type\": \"string\"}\n",
Expand All @@ -482,9 +485,9 @@
"source": [
"import os\n",
"\n",
"runtime_simple_json = os.path.join(os.getcwd(), \"../qiskit_runtime/runtime_simple/runtime_simple.json\")\n",
"sample_program_json = os.path.join(os.getcwd(), \"../qiskit_runtime/sample_program/sample_program.json\")\n",
"\n",
"with open(runtime_simple_json, 'r') as file:\n",
"with open(sample_program_json, 'r') as file:\n",
" data = file.read()\n",
"\n",
"print(data)"
Expand All @@ -511,28 +514,36 @@
"id": "dfea7bc0",
"metadata": {},
"source": [
"You can use the [`IBMRuntimeService.upload_program()`](https://qiskit.org/documentation/stubs/qiskit.providers.ibmq.runtime.IBMRuntimeService.html#qiskit.providers.ibmq.runtime.IBMRuntimeService.upload_program) method to upload your program. In the example below, the program data lives in the file `runtime-simple.py`, and its metadata, as described above, is in `runtime-simple.json`. "
"You can use the [`IBMRuntimeService.upload_program()`](https://qiskit.org/documentation/stubs/qiskit.providers.ibmq.runtime.IBMRuntimeService.html#qiskit.providers.ibmq.runtime.IBMRuntimeService.upload_program) method to upload your program. In the example below, the program data lives in the file `sample_program.py`, and its metadata, as described above, is in `sample_program.json`. "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "6f11e0e0",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sample-program\n"
]
}
],
"source": [
"import os\n",
"from qiskit import IBMQ\n",
"\n",
"IBMQ.load_account()\n",
"provider = IBMQ.get_provider(project='qiskit-runtime') # Substitute with your provider.\n",
"\n",
"runtime_simple_data = os.path.join(os.getcwd(), \"../qiskit_runtime/runtime_simple/runtime_simple.py\")\n",
"runtime_simple_json = os.path.join(os.getcwd(), \"../qiskit_runtime/runtime_simple/runtime_simple.json\")\n",
"sample_program_data = os.path.join(os.getcwd(), \"../qiskit_runtime/sample_program/sample_program.py\")\n",
"sample_program_json = os.path.join(os.getcwd(), \"../qiskit_runtime/sample_program/sample_program.json\")\n",
" \n",
"program_id = provider.runtime.upload_program(\n",
" data=runtime_simple_data,\n",
" metadata=runtime_simple_json\n",
" data=sample_program_data,\n",
" metadata=sample_program_json\n",
")\n",
"print(program_id)"
]
Expand Down
4 changes: 2 additions & 2 deletions API_direct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"Qiskit Runtime Programs:\n",
"- circuit-runner: A runtime program that takes one or more circuits, compiles them, executes them, and optionally applies measurement error mitigation. \n",
"- quantum-kernel-alignment: Quantum kernel alignment algorithm that learns, on a given dataset, a quantum kernel maximizing the SVM classification margin. \n",
"- runtime-simple: Simple runtime program used for testing. \n",
"- sample-program: A sample runtime program. \n",
"- vqe: Variational Quantum Eigensolver (VQE) to find the minimal eigenvalue of a Hamiltonian. \n"
]
}
Expand Down Expand Up @@ -185,7 +185,7 @@
}
],
"source": [
"Runtime_program = \"runtime-simple\"\n",
"Runtime_program = \"sample-program\"\n",
"\n",
"program_input = {\"iterations\":2} \n",
"\n",
Expand Down

0 comments on commit 69b3703

Please sign in to comment.