Theory, Tools, and Business Applications: An Indepth Look at Quantum Computing
Quantum computing is challenging the realities of technology, security, and industry as we know them. Here, we investigate the nuances of quantum mechanics and how to enter the world of quantum software development with tools such as Cirq and TensorFlow Quantum.
Quantum computing is challenging the realities of technology, security, and industry as we know them. Here, we investigate the nuances of quantum mechanics and how to enter the world of quantum software development with tools such as Cirq and TensorFlow Quantum.
Authors
Joao is an AI developer who holds a Quantum Excellence Certificate from IBM. He specializes in machine learning and deep learning and has partnered with Fortune 100 companies like Procter & Gamble and Hearst. Joao has more than 14 years of experience and holds a master’s degree in computer engineering from the University of Porto.
Previous Role
NLP EngineerPREVIOUSLY AT
Ghassan is a solutions architect and ML researcher with 28 years of experience, now focused on data engineering and OpenAI. He specializes in big data, but his expertise ranges from analytics to quantum computing. Ghassan has worked across industries like healthcare, finance, and transportation at companies including Morgan Stanley, Endeavor, and CN.
Previous Role
Senior Data EngineerPREVIOUSLY AT
Nephtali is a data scientist and quantum physicist. After earning a master’s degree in physics at the National University of Mexico, he was a Marie Curie doctoral researcher on quantum physics at the University of Nottingham. Nephtali has worked at companies like Kavak and WorldQuant and contributed to the quantum systems and devices group at the University of Sussex.
Previous Role
Quantitative EngineerChristopher Holloway
Christopher Holloway is Toptal’s Senior Editor for Technology. An awardwinning journalist with more than a decade of experience investigating how technology transforms sectors like retail, manufacturing, healthcare, and banking, he has held editorial positions at highly reputed media companies in Latin America, including AméricaEconomía, La Tercera, and Netmedia.
Expertise
A sufficiently powerful quantum computer holds the potential to break today’s encryption, making all electronic communication around the globe vulnerable to cyberattacks. Even though the transition from current noisy intermediatescale quantum (NISQ) computers—prone to errors and size constraints—to those capable of threatening current cryptographic standards is expected to take years or even decades, a recent surge in research, experimentation, and investment in quantum tech suggests the possibility is not as faroff as it once seemed.
Quantum computing has the potential to shape not only cryptography and cybersecurity, but major fields such as software optimization, chip design, and complex system modeling, among many others.
Though engineers today have access to quantum circuit libraries, quantum simulators, and even real quantum computers (via the cloud), the leap to quantum computing represents a distinct shift from traditional computing paradigms. In this article, Toptal quantum engineers aim to demystify the current state of quantum computing: why it matters, how it diverges from traditional computing, and the possibilities it unlocks. Additionally, they discuss practical resources such as Cirq and TensorFlow Quantum that enable handson experience with quantum computing.
The Power of Quantum Computing: Why Quantum Matters
Imagine a giant library filled with thousands of books. You know that the library contains the solution you need to a particular problem, but you don’t know in which book or in what combination of books you can find it. Each book represents a possible solution.
To find the solution, you could have a single scholar go through the books one by one, sentence by sentence, until they stumble upon it. But this process, unless they are extremely fortunate, will be impractically timeconsuming. The larger the library, the more complex the search will be.
Now imagine a scholar with the magical ability to check all the books simultaneously. They don’t have to go through the process sequentially, seeing instead a clear picture of the entire library and its contents at once. Naturally, they will reach the solution much faster than the nonmagical scholar.
Traditional computing operates like the first scholar. It excels at tasks that can be performed in a straightforward, sequential manner, but struggles as the problems become more complex and require the exploration of many possibilities simultaneously.
Quantum computing, on the other hand, provides several algorithms that allow for a faster processing of data compared to classical computers. In the context of our analogy, an example is Grover’s search algorithm, capable of locating a desired item within a large database significantly faster than classical computing can. It does so by using quantum properties such as superposition and interference, which we take a closer look at later in this article.
This allows a quadratic speedup over classical search algorithms for unstructured data, which is essentially as fast as quantum algorithms can theoretically get for this kind of problem. For structured search, in which additional information about the dataset is available, other quantum algorithms can outperform Grover’s. An example is Shor’s algorithm, which can factor large integers and solve discrete logarithm problems exponentially faster than classical algorithms.
Quantum Solutions for Quantum Problems
Quantum computing is well on its way to transforming a number of fields, and cryptography and cybersecurity are among those most likely to be disrupted by this technology. Algorithms like RSA encryption, the underpinning of much of today’s digital security, rely on the fact that factoring a sufficiently large number to break one of its instances using classical computers can take centuries. This kind of task, however, is a specialty of Shor’s algorithm; running on a sufficiently stable quantum computer, this algorithm has the theoretical ability to break these encryption schemes in mere hours or days.
The potential is so real that the National Institute of Standards and Technology (NIST) has been developing algorithms resistant to these attacks for years, integrating them into a postquantum cryptographic standard to keep information assets secure even after largescale quantum computers have been built. The World Economic Forum estimates that more than 20 billion digital devices will need to be replaced or updated in the next 10 to 20 years to allow for new forms of quantumresistant encrypted communication.
New communication methods and protocols are also being developed in order to secure systems further. Quantum key distribution (QKD), for example, relies on the foundations of quantum mechanics to allow two parties to create a shared secret key, enabling them to communicate securely, while ongoing research into quantum secure direct communication protocols aims to facilitate the direct and secure transmission of information.
Cybersecurity is not the only field that is bound to reap the benefits of quantumfirst approaches. Quantum computing also holds great potential in healthcare. Joao Diogo de Oliveira explains that its ability to simulate molecular interactions in unprecedented detail can accelerate drug discovery. “By leveraging quantum algorithms, we can explore vast chemical spaces more efficiently and predict molecular behaviors with higher accuracy. Quantum computers can perform complex simulations that enable more precise identification of potential drug candidates. This reduces the time and cost of early drug development stages. Additionally, quantumenhanced ML models can analyze large datasets to identify patterns that classical methods miss, improving drug efficacy and safety predictions. This integration has the potential to bring revolutionary treatments to market faster than ever,” he says.
Quantum algorithms like Grover’s and quantum annealing are also likely to have a major impact on optimization problems, thus helping to find more efficient solutions for largescale, complex logistics, finance, and scheduling challenges. But the impact of quantum computing is not limited to practical applications; it also extends to entire industries and scientific disciplines. Fields such as materials science, renewable energy research, climate modeling, and particle physics could all benefit from advances in quantum computing power.
Quantum Computing: History and Current State
The concept of quantum computing, once exclusive to the realm of theoretical physics, began to take tangible shape in the early 1980s, thanks to pioneers like Nobel Prize laureate Richard Feynman and Paul Dirac Prize winner David Deutsch who envisioned machines that would make use of quantum mechanics to reach previously unattainable processing power. By 1996, a team led by IBM physics researcher Isaac Chuang had developed the world’s first quantum computer, capable of handling just two quantum bits, or “qubits”—subatomic particles that are the quantum equivalent of the traditional bit, and the basic unit of quantum computing.
Chuang’s device manipulated individual atoms of hydrogen and chlorine within chloroform, making them function as a computer. Although the system remained stable for only a few nanoseconds and was limited to solving simple problems, this achievement confirmed that quantum technology was not just theoretical.
By the late 2010s, there were quantum processors that could operate on 50 to 72 qubits, and in 2023 IBM announced IBM Quantum Condor, a quantum processor of 1,000+ qubits, along with a smaller processor, the IBM Quantum Heron. Both can run or simulate parallel processes, with the smaller Heron being much less prone to errors and faster overall than Condor, bringing the practical applications of quantum computing much closer to reality.
These are pretty significant advancements in the field. However, it should be noted that the quantum computers we have today are still not powerful or stable enough to truly compete against classical computers to solve complex problems and process the significant amounts of data that would distinguish them from traditional machines. Today’s quantum computers are mostly used for research purposes. The quantum computer revolution is still a while away, but quantum operations can be simulated on classical computers, and developers can try their hand at quantum computing thanks to a number of tools available on the market.
The Fundamentals of Quantum Mechanics: Superposition, Entanglement, and Interference
Quantum computing is odd. The science powering its capabilities is counterintuitive because it differs significantly from the laws that govern our daytoday interactions with the world. Classical information processing operates on bits that are either off or on, representing two possible values, 0 or 1. All classical computations can be broken down into operations with these binary values.
But a quantum processor uses qubits. These fundamental units can exist in a state of quantum superposition, in which they are not either 0 or 1 but hold both possibilities at the same time. This is not just a third state but a continuum of probable states in which a qubit can embody every possible combination of 0 and 1 to varying degrees.
Nephtali GarridoGonzalez explains that the number of possible states a quantum computer can represent grows exponentially with each added qubit. “For example, two qubits can represent four states simultaneously, three can represent eight states, and so on, growing as 2^n, where n is the number of qubits. That is why, for some specific calculations, quantum computing is so compelling.”
Number of Qubits  Possible Independent States 
1  [0], [1] 
2 
[0, 0], [0, 1],
[1, 0], [1, 1]

3 
[0, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 1]
[1, 0, 0], [1, 1, 0], [1, 0, 1], [1, 1, 1]

A common way to represent qubits is the Bloch sphere. Picture the poles of this sphere as our classical 0 and 1. A classical bit must be at the north pole (0) or the south pole (1), but qubits in superposition can exist anywhere on the sphere’s surface, opening up an array of logical states much more numerous than the binarism used by classical computers.
Other tricks up the qubit’s sleeve push computational efficiency even further: The property of entanglement enables a qubit to instantly influence the state of another, no matter the distance between them. Entangled particles can be put at opposite extremes of the universe, and they would still act in unison.
Four states can be created from the maximal entanglement of two qubits. These states are known as Bell states, and they are the simplest example of quantum entanglement. Each state is linked to the other and completely correlated regardless of distance, making all states “maximally entangled.”
The four states can be mathematically represented as:
Φ⁺⟩ = (00⟩ + 11⟩) / √2 
Φ⁻⟩ = (00⟩  11⟩) / √2 
Ψ⁺⟩ = (01⟩ + 10⟩) / √2 
Ψ⁻⟩ = (01⟩  10⟩) / √2 
Here, 0⟩ and 1⟩ are the basic states of a qubit, and the symbols + and  indicate superpositions with equal probability but different phases between the components. The factor of 1/√2 is a normalization factor, which ensures that the total probability of finding the system in either state is 1.
We won’t go deep into the mathematics of Bell states, but their basic functionality can be presented as:
 For Φ⁺⟩ and Φ⁻⟩ Bell states: If you measure one qubit and find it in state 0⟩, you instantly know the other qubit is also in state 0⟩. If you measure and find the first qubit in state 1⟩, the other qubit will also be in state 1⟩.
 For Ψ⁺⟩ and Ψ⁻⟩ Bell states: If you measure one qubit and find it in state 0⟩, you instantly know the other qubit is in state 1⟩. If you measure and find the first qubit in state 1⟩, the other qubit will be in state 0⟩.
This unique property can be utilized for teleporting qubits’ states from one location to another, which is key in sharing private keys through QKD and in superdense coding—a communication protocol that enables the transmission of two classical bits by sending just one qubit. However, the property’s most common current application is in quantum error correction. Here, the correlation between entangled qubits aids in detecting and fixing errors without the need for direct measurement of the quantum information, thereby maintaining the integrity of its quantum state.
Interference is the third property that gives quantum computing its edge. Quantum states can be represented as wave functions due to the waveparticle duality that defines quantum mechanics. Just as quantum superposition allows qubits to exist in a state that embodies a continuum between 0 and 1, interference allows these superposed states to interact in ways that can be harnessed for computation.
Imagine two musical notes being played simultaneously. Depending on their frequencies (pitches), they can produce various effects. When the frequencies align in a harmonious way, the sound waves from each note combine to amplify the overall sound, producing a pleasant and rich tone. If the frequencies slightly mismatch, they can interfere destructively, creating a dissonant sound. Just as a complex piece of music involves multiple notes and harmonies interacting, a quantum system can be thought of as having multiple states or paths that interfere with one another.
“We’ve developed methods to ensure the wave amplitudes of the qubits that do not correspond to the answer we are looking for cancel out, while amplifying those corresponding to the desired outcome. This process results in a state where the probability of identifying the correct element is significantly high,” says GarridoGonzalez, whose work in quantum computing includes building a laser control system for quantum experiments at the University of Sussex. “The precision varies with your system’s capabilities. In theory, increasing the number of qubits enhances the accuracy of the outcome. However, this introduces other challenges, like quantum decoherence, which affects the stability of information in a quantum system once you measure it.”
In simpler terms, while quantum computers have the potential to solve problems quickly, they also require careful management to maintain their accuracy as the level of complexity—the number of qubits as well as the complexity of the query—increases.
Layers of the Quantum Computing Stack
The layers of the quantum computing stack, much like the classical stack, comprise several levels of abstraction, facilitating the transition from physical hardware to highlevel algorithmic solutions:
 Hardware: At the lowest level, quantum computing hardware refers to the physical devices that leverage quantum phenomena to perform calculations. These can range from smallscale quantum processors with a handful of qubits to more advanced systems with hundreds or thousands of qubits. Hardware may also involve technologies like superconducting qubits, trapped ions, topological qubits, or photonic circuits.
 Physical qubits: These are the core components of a quantum computer, representing the quantum version of classical bits. However, physical qubits are prone to errors and decoherence, leading to potential data corruption or loss.
 Quantum error correction: This layer focuses on identifying and fixing errors in quantum data caused by decoherence and noise in physical qubits. It usually requires spreading quantum information across several physical qubits and applying algorithms to correct detected errors and recover the intended quantum state.
 Logical qubits: Logical qubits offer a more stable and accurate way to store quantum information, achieved through quantum error correction and other strategies that minimize errors. An instruction set architecture outlines the operations that can be executed on these logical qubits, providing a framework for quantum computing tasks.
 Quantum intermediate representation (QIR): QIR serves as a bridge between quantum algorithms and physical hardware, allowing for the description of quantum circuits and algorithms in a compilerfriendly way and for adaptability to various quantum computing technologies.
 Quantum algorithms: These are specialized instructions or operations that leverage quantum theory—specifically phenomena like superposition, entanglement, and interference—to solve problems efficiently. Examples include Shor’s algorithm for integer factorization and the group isomorphism algorithm.
Getting Handson With Quantum Computing
To start using quantum software, it is important to have a solid grasp of quantum information. But engineers stepping into the quantum world do not need an indepth understanding of the physics behind quantum mechanics, says Ghassan Hallaq. “The fundamentals are linear algebra, the vector space, and complex numbers. Within a complex vector space, quantum states are defined as vectors, while matrices represent quantum operations. Linear algebra supplies the necessary tools for understanding these representations and operations. Complex numbers are also fundamental, as they are used to describe the probability amplitudes of quantum states,” Hallaq says.
To complement the fundamentals covered in this article, Hallaq recommends that newcomers to quantum development explore a free series of courses that IBM offers as extra preparation for using quantum software. For now, we discuss the available quantum software development kits (SDKs) for quantum computing, and then run through simple quantum development examples using Cirq and TensorFlow Quantum.
Available Kits for Software Development
Developers aiming to program and engage with quantum computers have access to various quantum software development kits and programming frameworks. These resources simplify the intricacies of quantum computing, allowing users to employ higherlevel programming languages and libraries to craft and run quantum circuits and algorithms.
Two prominent examples of easily available quantum SDKs are Cirq and TensorFlow Quantum (TFQ), both developed by Google. Cirq is an opensource library that allows developers to create, manipulate, and optimize quantum circuits. Both researchers and developers working on the fundamental aspects of quantum computing, such as quantum algorithm design, quantum circuit optimization, and lowlevel quantum hardware control, will find it exceptionally useful.
TFQ is a Python framework that takes a different approach, focusing on integrating quantum computing into machine learning models and workflows. It is built on top of TensorFlow, a staple in machine learning, and one of the most widely used libraries in the field. TFQ provides a set of tools and abstractions for constructing quantum circuits, simulating quantum computations, and integrating these quantum computations with classical machine learning components.
While both Cirq and TFQ can interface with real quantum computers through different back ends, Google does not offer public access to its quantum infrastructure at this time. If you want to test your circuits and algorithms in a real machine, a popular available solution is IBM’s Qiskit.
Qiskit aims to be approachable and easy to use, catering to users who may not have a deep background in quantum computing. It allows developers to write quantum programs using highlevel programming languages like Python, offering a broad range of features for circuit building, optimization, simulation, and visualization. IBM has built a robust ecosystem around Qiskit by partnering with businesses as well as research organizations and academic institutions. Other notable services include Microsoft’s Azure Quantum Development Kit and Amazon’s Braket, each offering unique features and capabilities.
Getting Started With Cirq
Cirq simplifies dealing with the technicalities of quantum hardware platforms, enabling developers to create quantum algorithms and circuits on Google hardware. Google has provided extensive resources to help those interested in quantum computing get up to speed rapidly.
Let’s take an initial look at code in a basic quantum algorithm. Our goal is to define and manipulate qubits through a sequence of quantum gates and operations. These manipulations happen within a quantum circuit, a structured pathway that guides the evolution of qubits from their initial states to a final measurement.
As mentioned earlier, qubits can exist in a state of superposition, embodying both 0 and 1 simultaneously. The first task in constructing our quantum circuit is to define these qubits. In Cirq, qubits are not just abstract entities; they can be named, arranged linearly, or positioned on a grid, mirroring potential layouts of physical quantum processors. This flexibility allows us to tailor a circuit’s structure to the needs of specific algorithms or hardware configurations.
There are three primary methods for defining qubits:

cirq.NamedQubit
: Qubits are labeled by an abstract name. 
cirq.LineQubit
: Qubits are labeled by a number in a linear array. 
cirq.GridQubit
: Qubits are labeled by two numbers in a rectangular grid.
This is an example of how to define qubits using these three methods:
# Naming qubits is a useful practice, especially when it comes to abstract algorithms and algorithms that are not yet mapped onto hardware.
q0 = cirq.NamedQubit('source')
q1 = cirq.NamedQubit('target')
# There are two ways to create line qubits:
# individually
q3 = cirq.LineQubit(3)
# or in a range.
# This, for example, will result in LineQubit(0), LineQubit(1), LineQubit(2).
q0, q1, q2 = cirq.LineQubit.range(3)
# Grid qubits can be referenced individually.
q4_5 = cirq.GridQubit(4, 5)
# Alternatively, they can be created in bulk in a square.
# This will create 16 qubits from (0,0) to (3,3).
qubits = cirq.GridQubit.square(4)
With our qubits defined, we then introduce quantum gates, the dynamic forces that change the state of qubits. Quantum gates are to qubits what operations are to classical bits. In Cirq, a gate is defined as an effect that can be applied to a collection of qubits, transforming them into operations. These operations are the actual events that occur in the circuit, such as flipping a qubit’s state or entangling two qubits together.
In the next example, we will define a circuit in which two common gates will act on a pair of qubits:

PauliX gate: Often referred to as the bitflip gate, it serves the same purpose as the classical NOT gate, flipping the state of a qubit;
0⟩
becomes1⟩
, and vice versa. 
Hadamard gate: The Hadamard gate creates superposition. It transforms the basis states
0⟩
and1⟩
into equal superpositions of both, enabling parallel computation over the superposed states.
After applying the gates, we will measure the results. Measuring is crucial for collapsing the quantum state into a classical state that shows us the impact of the quantum operations performed on the qubits. Without measurement, while the qubits may undergo various transformations, the outcome of these operations cannot be determined.
import cirq
# Define qubits.
q0, q1 = cirq.LineQubit.range(2)
# Define a gate.
X_gate = cirq.X # The PauliX gate
# Apply the gate to a qubit to create an operation.
x_op = X_gate(q0) # Apply the X gate to qubit q0
# Define another gate.
H_gate = cirq.H # The Hadamard gate
# Apply the gate to a qubit to create an operation.
h_op = H_gate(q0) # Apply the H gate to qubit q0
# Create a circuit and add operations.
circuit = cirq.Circuit()
circuit.append(x_op) # Add the X operation on q0
circuit.append(h_op) # Add the H operation on q0
circuit.append(cirq.measure(q0, q1)) # Measure both qubits
print("Circuit:")
print(circuit)
This printed output represents the sequence of operations in the circuit for each qubit:
Circuit:
0: ───X───H───M───
1: ───M───────
Here:
 0 and 1 indicate the line (or qubit) numbers.
 X represents the PauliX gate applied to qubit q0.
 H represents the Hadamard gate applied to qubit q0 immediately after the PauliX gate.
 M indicates a measurement operation. The measurement is shown on both qubits, indicating that the state of both qubits q0 and q1 will be measured at the end of the circuit execution.
Let us imagine that both qubits start in the state 0⟩. The PauliX gate flips q0 from 0⟩ to 1⟩. Then the Hadamard gate creates a superposition, transforming the state of q0 1⟩ into a superposition of 0⟩ and 1⟩ with equal probabilities but with a phase difference. When measuring, q0 can collapse to either 0⟩ or 1⟩. Since q1 has not been altered and remains in state 0⟩, the measurement outcomes for the two qubits could theoretically be either:
 [0,0] with 50% probability.
 [1,0] with 50% probability.
The actual printout from executing the circuit would not show these probabilities but instead one of the possible measurement outcomes, depending on the inherent randomness of quantum measurement in superposition states.
While this circuit is extremely basic, it demonstrates some fundamental quantum computing principles that serve as basic building blocks. For instance, one of the steps in Grover’s search algorithm involves applying a Hadamard gate to each qubit in the system, putting each individual qubit into a superposition of states.
Executing a Cirq Circuit
So far we’ve not run the circuit, but defined what it should do. To see actual results, we must involve a quantum simulator or a real quantum computer in the mix. Quantum simulators are software tools that emulate a quantum computer while still relying on classical computing resources. The simulator will execute the circuit a specified number of times and provide the measurement outcomes for each run, allowing you to analyze the probability distribution of the outcomes.
Cirq provides different simulators. For basic circuits, cirq.Simulator
is a good choice:
import cirq
# If 'circuit' is our quantum circuit
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1000)
print(result)
After executing our circuit (where one qubit had a Hadamard gate applied) and running it for 1,000 repetitions, you might see the following measurement output:
 [0,0]: 498 times
 [1,0]: 502 times
These results are in line with the expected theoretical probabilities.
Running the circuit in a real quantum computer will not be much different, but results might vary from those predicted by ideal simulators due to physical noise and errors still common in quantum processors. It will also be more expensive, and you need to be sure that your circuit is compatible with any hardware constraints such as the available qubit connections and supported gates.
Choosing between a simulator and a real quantum computer often depends on the stage of development and the objectives of your project, as well as the complexity of the circuit and the level of precision you require. Initial development, testing, and learning are efficiently conducted on simulators, while final validation, experiments demonstrating quantum advantage, and investigations into the effects of noise and quantum hardware characteristics necessitate the use of real quantum processors.
Exploring TensorFlow Quantum
To illustrate the capabilities of TFQ, let’s build upon the Cirq example and introduce two new quantum gates: the controlledNOT (CNOT) gate, which is crucial for creating entanglement between qubits, and the RY gate, a singlequbit gate that rotates a qubit around the yaxis of the Bloch sphere. By adjusting the rotation angle θ (theta), you can control the probabilities of measuring the qubit in the ∣0⟩ or ∣1⟩ state, enabling a wider and more complex range of quantum operations.
We initially define a quantum circuit that applies a Hadamard gate to the first qubit in order to create a superposition, then rotate it using an RY gate, demonstrating how classical data (in this case, the parameter for an RY gate) can be encoded into a quantum state. Finally, we use a CNOT gate to entangle it with the second qubit, creating a Bell state and showcasing the three main properties of quantum computing.
import tensorflow as tf
import tensorflow_quantum as tfq
import sympy
import cirq
# Define qubits.
q0, q1 = cirq.LineQubit.range(2)
# Define symbols for parameterized gate.
theta = sympy.Symbol('theta')
# Create a circuit.
circuit = cirq.Circuit(
cirq.H(q0), # Apply Hadamard gate to create superposition
cirq.CNOT(q0, q1), # Entangle q0 and q1
cirq.ry(theta)(q0) # Apply RY gate with a parameter theta
)
# Visualize the circuit.
SVGCircuit(circuit)
This is what our circuit looks like at this moment:
Circuit:
0: ───H───RY(θ)───@───M───
│
1: ──────────────X───M───
Here:
 0 and 1 indicate the line numbers corresponding to the first and second qubits, respectively.
 H stands for the Hadamard gate that is applied to the first qubit (q0). H puts q0 into a superposition state.
 RY(θ) indicates a rotation around the yaxis applied to q0, parameterized by θ (theta). This represents how to encode classical data into the quantum state using the rotation angle.
 @ and X together signify the CNOT gate, with q0 acting as the control qubit and q1 as the target qubit. This gate entangles q0 and q1.
 M indicates measurement operations on both qubits. Measuring the qubits collapses their quantum state to classical bits.
Now let’s incorporate this quantum circuit into a hybrid quantumclassical model that will process the classical data (theta) through the quantum circuit and then classify it using a classical neural network:
# Convert the circuit to a TensorFlow Quantum circuit.
q_data_encoding_circuit = tfq.convert_to_tensor([circuit])
# Define a classical neural network.
model = tf.keras.Sequential([
# Quantum layer: Encode data and apply quantum gates.
tfq.layers.ControlledPQC(circuit, operators=cirq.Z(q1), # Measure Z expectation values
control_values=tf.constant([[1.0]]), # Control values for theta
control_symbols=[theta]), # Symbols to control
# Classical dense layer for classification
tf.keras.layers.Dense(2, activation='softmax')
])
# Compile the model.
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Assuming x_train and y_train are prepared,
# where x_train is the array of theta values for the data samples
# and y_train is the corresponding labels (0 or 1).
model.fit(x_train, y_train, epochs=10, batch_size=32)
The ControlledPQC layer in TFQ allows for the use of parameterized quantum circuits in which classical data can control quantum operations, bridging the gap between classical and quantum computing. The benefits of this integration may not be evident at first sight, as this example merely scratches the surface of what’s possible with TFQ and hybrid models, so let’s theorize about a practical application.
In drug discovery, identifying molecules with the potential to bind to specific protein targets is a complex and computationally intensive task. The process involves analyzing vast databases of chemical compounds to predict their interactions with biological targets, which is crucial for identifying promising drug candidates. The highdimensional nature of molecular data and the complex, nonlinear interactions between molecules and biological targets make this task very challenging for classical machine learning models.
But by using an RY gate in a quantum circuit like the one above to encode classical molecular data (such as molecular fingerprints) into quantum states, we can map the highdimensional data into a state that reflects the molecule’s characteristics.
Then, by applying quantum operations to these encoded states, we can perform computations that explore the complexity of the molecular data. This step could involve using quantum interference to highlight patterns that are indicative of a molecule’s binding affinity to the target protein, for example.
The quantumprocessed data is then fed into a classical neural network, which classifies the molecules based on their predicted binding affinity. The quantum preprocessing step aims to enhance the feature set, making it easier for the classical neural network to identify promising drug candidates.
This approach could significantly speed up the initial screening process for drug candidates, allowing researchers to spend more time investigating the compounds that look most promising.
While we covered a simple example, TFQ provides a rich set of tools and abstractions for constructing more complex hybrid quantumclassical models, enabling developers to explore the potential of quantum computing for enhancing machine learning algorithms and models.
Reaching Quantum Supremacy
Quantum computing is in reach for any developer who wants to start learning and experimenting, but several challenges remain before we can fully harness the potential of this technology. Even with the powerful algorithms and techniques available, the hardware is not yet stable enough to reach “quantum supremacy,” the theoretical moment a quantum algorithm solves a problem that is unfeasible or would require an unfeasible amount of time to solve for the best known or possible classical algorithm for that task.
One of the most pressing issues is quantum hardware’s current error rates and limited coherence times. Qubits are extremely sensitive to external disturbances and decoherence, leading to errors and noise affecting quantum computations.
Researchers are diligently working on error correction strategies and approaches to achieve faulttolerant quantum computing. Additionally, there’s a concerted push toward developing materials and designs for quantum hardware to extend qubit coherence times and minimize error rates.
Despite these challenges, quantum computing is an incredibly promising prospect—and ongoing research and development efforts are pushing the boundaries of computing as we know it. Researchers are exploring the potential of quantum communication and quantum networking, which could enable secure and tamperproof communication channels and distributed quantum computing capabilities. Integrating quantum computing with emerging technologies like machine learning and artificial intelligence could lead to gamechanging breakthroughs. Likewise, hybrid quantumclassical models and quantumenhanced algorithms are expected to bring breakthroughs in fields like computer vision, natural language processing, and scientific simulations.
As the quantum revolution unfolds, businesses, researchers, and policymakers must stay informed and engaged with this rapidly evolving field. By embracing quantum computing and fostering a culture of innovation, organizations can position themselves to harness the transformative power of this technology and unlock new frontiers in product development and technological advancement.
Further Reading on the Toptal Blog:
Understanding the basics
What is quantum computing in simple terms?
Quantum computing is based on quantum theory. Its fundamental unit of data is the qubit. Unlike the bit of classical computing, which can be either 0 or 1, a qubit can exist in multiple states simultaneously. This allows quantum computers to process more data and solve more complex problems.
How does quantum computing work?
Quantum computing is a field of computing that leverages phenomena of quantum mechanics to solve complex problems. The basic unit of quantum computing is the qubit. While classical bits can only represent a 0 or a 1, qubits, due to a property called superposition, can exist in multiple states at once.
What is quantum hardware?
Quantum hardware refers to those physical components and structures used to support quantum computing processes. Quantum hardware relies on the fundamentals of quantum mechanics to process data. Components include quantum processors, superconducting qubits, trapped ions, photonic circuits, or topological qubits.
What is a quantum computing simulator?
A quantum computing simulator is a software tool that imitates the behavior of quantum computers while relying on traditional computers. During the development of a project, simulators allow for easier testing and debugging, which helps to cut costs. The use of real quantum processors is best left for later validation, after the research and testing phases.
What quantum computing simulators are used in Python?
Python is a popular option for quantum computing simulation. Cirq and Qiskit are two favorites among opensource Python libraries for handling quantum circuits. TensorFlow Quantum is another Python framework that lets developers integrate quantum simulations and algorithms into machine learning models.
Authors
Fortaleza  State of Ceará, Brazil
Member since October 20, 2022
About the author
Joao is an AI developer who holds a Quantum Excellence Certificate from IBM. He specializes in machine learning and deep learning and has partnered with Fortune 100 companies like Procter & Gamble and Hearst. Joao has more than 14 years of experience and holds a master’s degree in computer engineering from the University of Porto.
Previous Role
NLP EngineerPREVIOUSLY AT
Montreal, QC, Canada
Member since June 13, 2019
About the author
Ghassan is a solutions architect and ML researcher with 28 years of experience, now focused on data engineering and OpenAI. He specializes in big data, but his expertise ranges from analytics to quantum computing. Ghassan has worked across industries like healthcare, finance, and transportation at companies including Morgan Stanley, Endeavor, and CN.
Previous Role
Senior Data EngineerPREVIOUSLY AT
Mexico City, Mexico
Member since February 9, 2021
About the author
Nephtali is a data scientist and quantum physicist. After earning a master’s degree in physics at the National University of Mexico, he was a Marie Curie doctoral researcher on quantum physics at the University of Nottingham. Nephtali has worked at companies like Kavak and WorldQuant and contributed to the quantum systems and devices group at the University of Sussex.