Skip to content

Commit

Permalink
Update start notebook to use get_engine instead of `get_qcs_objects…
Browse files Browse the repository at this point in the history
…_for_notebook` (#6483)

* Created using Colaboratory

* Created using Colaboratory

* authenticate user

* if`get_engine` errors default to virtual engine

* lint
  • Loading branch information
senecameeks authored Mar 5, 2024
1 parent 6dbac6b commit 4513892
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions docs/tutorials/google/start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,24 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YoqI9GrOPExP",
"cellView": "form"
"id": "YoqI9GrOPExP"
},
"outputs": [],
"source": [
"# The Google Cloud Project id to use.\n",
"project_id = \"\" #@param {type:\"string\"}\n",
"\n",
"from cirq_google.engine.qcs_notebook import get_qcs_objects_for_notebook\n",
"# For virtual engine instances, set 'virtual=True' below.\n",
"qcs_objects = get_qcs_objects_for_notebook(project_id)\n",
"from cirq_google.engine import get_engine\n",
"from cirq_google.engine.qcs_notebook import authenticate_user\n",
"\n",
"engine = qcs_objects.engine\n",
"if not qcs_objects.signed_in:\n",
" print(\"ERROR: Please setup project_id in this cell or set the `GOOGLE_CLOUD_PROJECT` env var to your project id.\")\n",
" print(\"Using noisy simulator instead.\")\n"
"authenticate_user()\n",
"try:\n",
" engine = get_engine(project_id)\n",
"except Exception:\n",
" from cirq_google.engine.qcs_notebook import get_qcs_objects_for_notebook\n",
" print(\"Unable to connect to a hardware engine. Using a virtual instance instead.\")\n",
" qcs_objects = get_qcs_objects_for_notebook(project_id, virtual=True)\n",
" engine = qcs_objects.engine"
]
},
{
Expand Down Expand Up @@ -175,11 +177,11 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 24,
"metadata": {
"cellView": "both",
"id": "EQoTYZIEPa9S",
"outputId": "43c72568-3bc8-4b44-871b-b9db19c9e672",
"outputId": "beb04676-8404-4831-8d40-3291ee2d6127",
"colab": {
"base_uri": "https://localhost:8080/"
}
Expand Down Expand Up @@ -275,7 +277,8 @@
{
"cell_type": "code",
"source": [
"processors = [p.processor_id for p in engine.list_processors() if p.health() == 'OK']"
"processors = [p.processor_id for p in engine.list_processors() if p.health() == 'OK']\n",
"print(f\"Available processors: {processors}\")"
],
"metadata": {
"id": "rvMeXrC1wnQi"
Expand Down

0 comments on commit 4513892

Please sign in to comment.