Are you looking for an open-source framework for programming quantum computers and build a nice GUI for them? Try Cirq library for Python. And for the GUI part, you can run it seamlessly with Python4Delphi (P4D). P4D is a free and simple tool that allows you to run Python scripts as well as create new Python modules and types in Delphi.
Cirq is a Python library for writing, manipulating, and optimizing quantum circuits and running them against quantum computers and simulators.
Cirq is a Python software library for writing, manipulating, and optimizing quantum circuits, and then running them on quantum computers and quantum simulators. Cirq provides useful abstractions for dealing with today’s noisy intermediate-scale quantum computers, where details of the hardware are vital to achieving state-of-the-art results.
Table of Contents
This post will guide you on how to get started into programming quantum computers using Python’s Cirq library and then display it in the Delphi Windows GUI app using Python for Delphi.
First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
Hello Qubit: A hello world with Cirq:
# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
# Create a circuit
circuit = cirq.Circuit(
cirq.X(qubit)**0.5, # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
# Simulate the circuit several times.
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=20)
The result in our P4D supported GUI:
2. Things to Keep in Mind
- Before coding your circuit, it’s important to have a visual representation of what it will look like and where all the gates are applied
- There are always different ways to do the same thing but more simplified. Optimize your circuit and code for good practice, especially for our current fragile quantum computers.
- It’s helpful to print out your circuits as you build them to fix any errors right away.
Congratulations, now you have learned how to get started into programming quantum computers using Python’s Cirq library and then display it in the Delphi Windows GUI app using Python for Delphi.
Check out the Cirq library for Python and use it in your projects: https://pypi.org/project/cirq/ and
Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi