Skip to content

Commit

Permalink
Fix indentation in docs (#3974)
Browse files Browse the repository at this point in the history
Changes notebooks which used 2 or 3 spaces as indentation. Python and Cirq use 4 instead, thus the level of indentation is made consistent.

Fixes #3729.
  • Loading branch information
unaiic committed Apr 28, 2021
1 parent 6c99f0b commit d448a35
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 256 deletions.
12 changes: 6 additions & 6 deletions docs/transform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@
"source": [
"class RemoveMeasurements(cirq.PointOptimizer):\n",
" def optimization_at(self, circuit: cirq.Circuit, index: int, op: cirq.Operation):\n",
" if isinstance(op.gate, cirq.MeasurementGate):\n",
" return cirq.PointOptimizationSummary(clear_span=1,\n",
" new_operations=[],\n",
" clear_qubits=op.qubits)\n",
" else:\n",
" return None\n",
" if isinstance(op.gate, cirq.MeasurementGate):\n",
" return cirq.PointOptimizationSummary(clear_span=1,\n",
" new_operations=[],\n",
" clear_qubits=op.qubits)\n",
" else:\n",
" return None\n",
"\n",
"q=cirq.LineQubit(0)\n",
"c=cirq.Circuit(cirq.X(q), cirq.measure(q))\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@
"foxtail_circuit = cirq.Circuit(device=cirq_google.Foxtail)\n",
"foxtail_circuit.append(adjacent_op)\n",
"try:\n",
" # Not allowed, will throw exception\n",
" foxtail_circuit.append(nonadjacent_op)\n",
" # Not allowed, will throw exception\n",
" foxtail_circuit.append(nonadjacent_op)\n",
"except ValueError as e:\n",
" print('Not allowed. %s' % e)\n"
" print('Not allowed. %s' % e)\n"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/educators/chemistry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
"# Perform electronic structure calculations and\n",
"# obtain Hamiltonian as an InteractionOperator\n",
"hamiltonian = ofpyscf.generate_molecular_hamiltonian(\n",
" geometry, basis, multiplicity, charge)\n",
" geometry, basis, multiplicity, charge)\n",
"\n",
"# Convert to a FermionOperator\n",
"hamiltonian_ferm_op = of.get_fermion_operator(hamiltonian)\n",
Expand Down
56 changes: 28 additions & 28 deletions docs/tutorials/educators/intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3487,26 +3487,26 @@
"source": [
"#@title Expand to view the solution\n",
"class SquareDevice(cirq.Device):\n",
" \"\"\"A Square Grid Device.\n",
" \n",
" The device that only allows \n",
" \"\"\"A Square Grid Device.\n",
" \n",
" The device that only allows \n",
" 1) Grid Qubits from (0, 0) to (grid_size - 1, grid_size - 1)\n",
" 2) H, CZ and MeasurementGate gates.\n",
" \"\"\"\n",
" def __init__(self, grid_size):\n",
" self.qubits = []\n",
" for i in range(grid_size):\n",
" for j in range(grid_size):\n",
" self.qubits.append(cirq.GridQubit(i, j))\n",
" \"\"\"\n",
" def __init__(self, grid_size):\n",
" self.qubits = []\n",
" for i in range(grid_size):\n",
" for j in range(grid_size):\n",
" self.qubits.append(cirq.GridQubit(i, j))\n",
"\n",
" def validate_operation(self, operation: 'cirq.Operation') -> None:\n",
" if not isinstance(operation, cirq.GateOperation):\n",
" raise ValueError(f\"Unsupported operation {operation}\")\n",
" if not (operation.gate in [cirq.H, cirq.CZ] or isinstance(operation.gate, cirq.MeasurementGate)):\n",
" raise ValueError(f\"Unsupported gate {operation.gate}\")\n",
" for qubit in operation.qubits:\n",
" if qubit not in self.qubits:\n",
" raise ValueError(f\"Qubit {qubit} not on device\")"
" def validate_operation(self, operation: 'cirq.Operation') -> None:\n",
" if not isinstance(operation, cirq.GateOperation):\n",
" raise ValueError(f\"Unsupported operation {operation}\")\n",
" if not (operation.gate in [cirq.H, cirq.CZ] or isinstance(operation.gate, cirq.MeasurementGate)):\n",
" raise ValueError(f\"Unsupported gate {operation.gate}\")\n",
" for qubit in operation.qubits:\n",
" if qubit not in self.qubits:\n",
" raise ValueError(f\"Qubit {qubit} not on device\")"
]
},
{
Expand Down Expand Up @@ -3669,17 +3669,17 @@
" q0, = op.qubits\n",
" next_op = circuit.operation_at(q0, index + 1)\n",
" if isinstance(next_op, cirq.GateOperation) and next_op.gate == cirq.CX:\n",
" qubits = circuit.operation_at(q0, index + 1).qubits\n",
" if all(\n",
" circuit.operation_at(q, idx).gate == cirq.H\n",
" for idx in [index, index + 2]\n",
" for q in qubits\n",
" ):\n",
" return cirq.PointOptimizationSummary(\n",
" clear_span = 3,\n",
" clear_qubits = qubits,\n",
" new_operations = [cirq.CX(qubits[1], qubits[0])]\n",
" )\n",
" qubits = circuit.operation_at(q0, index + 1).qubits\n",
" if all(\n",
" circuit.operation_at(q, idx).gate == cirq.H\n",
" for idx in [index, index + 2]\n",
" for q in qubits\n",
" ):\n",
" return cirq.PointOptimizationSummary(\n",
" clear_span = 3,\n",
" clear_qubits = qubits,\n",
" new_operations = [cirq.CX(qubits[1], qubits[0])]\n",
" )\n",
" \n",
"opt = CXOptimizer()\n",
"circuit = cirq.Circuit(\n",
Expand Down
52 changes: 26 additions & 26 deletions docs/tutorials/google/colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,33 @@
" os.environ['GOOGLE_CLOUD_PROJECT'] = project_id\n",
"\n",
"def authenticate_user():\n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
"\n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
"\n",
"authenticate_user()\n",
"\n",
Expand Down
112 changes: 56 additions & 56 deletions docs/tutorials/google/reservations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,33 @@
],
"source": [
"def authenticate_user():\n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
"\n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
"\n",
"authenticate_user()"
]
Expand Down Expand Up @@ -214,37 +214,37 @@
"now = tz.localize(datetime.datetime.now())\n",
"\n",
"def date_string(timestamp):\n",
" if timestamp.seconds < 0:\n",
" return 'Beginning of time'\n",
" if timestamp.seconds > 4771848621:\n",
" return 'End of time'\n",
" time = datetime.datetime.fromtimestamp(timestamp.seconds).astimezone(tz)\n",
" return time.strftime('%Y-%m-%d %H:%M:%S')\n",
" if timestamp.seconds < 0:\n",
" return 'Beginning of time'\n",
" if timestamp.seconds > 4771848621:\n",
" return 'End of time'\n",
" time = datetime.datetime.fromtimestamp(timestamp.seconds).astimezone(tz)\n",
" return time.strftime('%Y-%m-%d %H:%M:%S')\n",
" \n",
"def delta(start, end):\n",
" if start.seconds < 0 or end.seconds > 5000000000:\n",
" return \"\"\n",
" return \"{} hrs\".format((end.seconds - start.seconds) / (60 * 60))\n",
" if start.seconds < 0 or end.seconds > 5000000000:\n",
" return \"\"\n",
" return \"{} hrs\".format((end.seconds - start.seconds) / (60 * 60))\n",
"\n",
"def time_slot_string(time_slot):\n",
" start = date_string(time_slot.start_time)\n",
" end = date_string(time_slot.end_time)\n",
" slot_type = cirq_google.engine.client.quantum_v1alpha1.types.QuantumTimeSlot.TimeSlotType.Name(time_slot.slot_type)\n",
" slot_string = \"{} to {} ({}) - {}\".format(start, end, delta(time_slot.start_time, time_slot.end_time), slot_type)\n",
" if time_slot.HasField('reservation_config'):\n",
" return \"{} for {}\".format(slot_string, time_slot.reservation_config.project_id) \n",
" if time_slot.HasField('maintenance_config'):\n",
" return \"{} {} - {}\".format(slot_string, time_slot.maintenance_config.title, time_slot.maintenance_config.description) \n",
" return slot_string\n",
" start = date_string(time_slot.start_time)\n",
" end = date_string(time_slot.end_time)\n",
" slot_type = cirq_google.engine.client.quantum_v1alpha1.types.QuantumTimeSlot.TimeSlotType.Name(time_slot.slot_type)\n",
" slot_string = \"{} to {} ({}) - {}\".format(start, end, delta(time_slot.start_time, time_slot.end_time), slot_type)\n",
" if time_slot.HasField('reservation_config'):\n",
" return \"{} for {}\".format(slot_string, time_slot.reservation_config.project_id) \n",
" if time_slot.HasField('maintenance_config'):\n",
" return \"{} {} - {}\".format(slot_string, time_slot.maintenance_config.title, time_slot.maintenance_config.description) \n",
" return slot_string\n",
"\n",
"def reservation_string(reservation):\n",
" start = date_string(reservation.start_time)\n",
" end = date_string(reservation.end_time)\n",
" id = reservation.name.split('/reservations/')[1]\n",
" reservation_string = \"{} to {} ({}) - {}\".format(start, end, delta(reservation.start_time, reservation.end_time), id)\n",
" if len(reservation.whitelisted_users) > 0:\n",
" return \"{} {}\".format(reservation_string, reservation.whitelisted_users)\n",
" return reservation_string \n",
" start = date_string(reservation.start_time)\n",
" end = date_string(reservation.end_time)\n",
" id = reservation.name.split('/reservations/')[1]\n",
" reservation_string = \"{} to {} ({}) - {}\".format(start, end, delta(reservation.start_time, reservation.end_time), id)\n",
" if len(reservation.whitelisted_users) > 0:\n",
" return \"{} {}\".format(reservation_string, reservation.whitelisted_users)\n",
" return reservation_string \n",
"\n",
"print(\"============================\")\n",
"print(\"Runtime setup completed\")"
Expand Down Expand Up @@ -280,7 +280,7 @@
"#@title\n",
"schedule = processor.get_schedule()\n",
"for s in schedule:\n",
" print(time_slot_string(s))"
" print(time_slot_string(s))"
]
},
{
Expand Down Expand Up @@ -313,10 +313,10 @@
"schedule = processor.get_schedule()\n",
"unallocated = list(filter(lambda t: t.slot_type == enums.QuantumTimeSlot.TimeSlotType.UNALLOCATED, schedule))\n",
"for s in unallocated:\n",
" print(time_slot_string(s))\n",
" print(time_slot_string(s))\n",
"\n",
"if len(unallocated) == 0:\n",
" print(\"No available time slots\")"
" print(\"No available time slots\")"
]
},
{
Expand Down Expand Up @@ -349,9 +349,9 @@
"reservations = processor.list_reservations()\n",
"\n",
"for r in reservations:\n",
" print(reservation_string(r))\n",
" print(reservation_string(r))\n",
"else: \n",
" print(f\"No reservations for project {project_id}\")"
" print(f\"No reservations for project {project_id}\")"
]
},
{
Expand Down
54 changes: 27 additions & 27 deletions docs/tutorials/google/start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,33 @@
" os.environ['GOOGLE_CLOUD_PROJECT'] = project_id\n",
"\n",
"def authenticate_user():\n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
"\n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
" \"\"\"Runs the user through the Colab OAuth process.\n",
" \n",
" Checks for Google Application Default Credentials and runs interactive login \n",
" if the notebook is executed in Colab. In case the notebook is executed in Jupyter notebook\n",
" or other IPython runtimes, no interactive login is provided, it is assumed that the \n",
" `GOOGLE_APPLICATION_CREDENTIALS` env var is set or `gcloud auth application-default login`\n",
" was executed already.\n",
" \n",
" For more information on using Application Default Credentials see \n",
" https://cloud.google.com/docs/authentication/production\n",
" \"\"\"\n",
" in_colab = False\n",
" try:\n",
" from IPython import get_ipython\n",
" in_colab = 'google.colab' in str(get_ipython())\n",
" except: \n",
" # Notebook is not executed within IPython. Assuming external authentication.\n",
" return \n",
"\n",
" if in_colab: \n",
" from google.colab import auth \n",
" print(\"Getting OAuth2 credentials.\")\n",
" print(\"Press enter after entering the verification code.\")\n",
" auth.authenticate_user(clear_output=False)\n",
" print(\"Authentication complete.\")\n",
" else: \n",
" print(\"Notebook is not executed with Colab, assuming Application Default Credentials are setup.\") \n",
"\n",
"authenticate_user()\n",
"\n",
Expand Down

0 comments on commit d448a35

Please sign in to comment.