From 45138921be805a361ad604c728ba8584fa4113aa Mon Sep 17 00:00:00 2001 From: Seneca Meeks Date: Tue, 5 Mar 2024 12:09:21 -0800 Subject: [PATCH] Update start notebook to use `get_engine` instead of `get_qcs_objects_for_notebook` (#6483) * Created using Colaboratory * Created using Colaboratory * authenticate user * if`get_engine` errors default to virtual engine * lint --- docs/tutorials/google/start.ipynb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/tutorials/google/start.ipynb b/docs/tutorials/google/start.ipynb index e7e278f9edf..a817d8bfcd9 100644 --- a/docs/tutorials/google/start.ipynb +++ b/docs/tutorials/google/start.ipynb @@ -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" ] }, { @@ -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/" } @@ -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"