Path: blob/main/notebooks/ch-demos/widgets-index.ipynb
3855 views
Widgets Demonstration
As well as providing working code that readers can experiment with, the textbook also provides a number of widgets to help explain specific concepts. This page contains a selection of these as an index. Run each cell to interact with the widget.
NOTE: You will need to enable interactivity by pressing 'Try' in the bottom left corner of a code cell, or by viewing this page in the IBM Quantum Experience.
Interactive Code
The most important interactive element of the textbook is the ability to change and experiment with the code. This is possible directly on the textbook webpage, but readers can also view the textbook as Jupyter notebooks where they are able to add more cells and save their changes. Interactive Python code also allows for widgets through ipywidgets, and the rest of this page is dedicated to demonstrating some of the widgets provided by the Qiskit Textbook.
Gate Demo
This widget shows the effects of a number of gates on a qubit, illustrated through the bloch sphere. It is used a lot in Single Qubit Gates.
Binary Demonstration
This simple widget allows the reader to interact with a binary number. It is found in The Atoms of Computation.
Scalable Circuit Widget
When working with circuits such as those in the Quantum Fourier Transform Chapter, it's often useful to see how these scale to different numbers of qubits. If our function takes a circuit (QuantumCircuit) and a number of qubits (int) as positional inputs, we can see how it scales using the widget below. Try changing the code inside these functions and re-run the cell.
Bernstein-Vazirani Widget
Through this widget, the reader can follow the mathematics through an instance of the Bernstein-Vazirani algorithm. Press the buttons to apply the different steps of the algorithm. The first argument sets the number of qubits, and the second sets the hidden binary string, then re-run the cell. You can also reveal the contents of the oracle by setting hide_oracle=False and re-running the cell.
Deutsch-Joza Widget
Similarly to the Bernstein-Vazirani widget, through the Deutsch-Joza widget the reader can follow the mathematics through an instance of the Deutsch-Joza algorithm. Press the buttons to apply the different steps of the algorithm. case can be "balanced" or "constant", and size can be "small" or "large". Re-run the cell for a randomly selected oracle. You can also reveal the contents of the oracle by setting hide_oracle=False and re-running the cell.