martes, 25 de marzo de 2025

The six most promising applications of quantum computing on April 2025

Quantum computing is steadily evolving from theoretical promise to practical applications—especially in areas where classical computing hits fundamental limitations. Here are some of the most promising applications today:

  1. Quantum Simulation One of the clearest paths to quantum advantage is the simulation of quantum systems themselves. Traditional computers struggle to accurately simulate systems with many interacting particles—a limitation that directly impacts fields like quantum chemistry and materials science. By mimicking the behavior of quantum particles, quantum computers can model chemical reactions, predict material properties, and accelerate drug discovery. This isn’t just a theoretical exercise; early experiments are already demonstrating how quantum simulators can provide insights into molecular dynamics and reaction mechanisms that are beyond the scope of classical methods.

  2. Optimization in Complex Systems Many real-world challenges—from logistics and supply chain management to financial portfolio optimization—are inherently combinatorial and often fall into the category of NP-hard problems. Quantum algorithms, such as the Quantum Approximate Optimization Algorithm (QAOA) and approaches harnessing quantum annealing, show promise in finding near-optimal solutions faster than traditional heuristic methods. Even in the current Noisy Intermediate-Scale Quantum (NISQ) era, hybrid quantum-classical strategies are being designed to tackle complex optimization tasks in industries where even marginal improvements can translate into significant cost savings and efficiency gains.

  3. Quantum Machine Learning (QML) Quantum machine learning represents an intriguing crossroad where quantum computing could potentially accelerate data processing and enhance pattern recognition techniques. By exploiting high-dimensional Hilbert spaces for encoding data, quantum algorithms might solve certain classes of linear algebra problems—integral to machine learning—more efficiently. While it’s still early days, research is underway to determine whether quantum-inspired approaches can complement or even outperform classical deep learning models, unlocking new capabilities in areas such as image recognition, natural language processing, and data clustering.

  4. Cryptography and Secure Communications Perhaps one of the most well-known implications of quantum computing is its impact on cryptography. While algorithms like Shor’s promise to break current public-key encryption by efficiently factoring large numbers, this threat is spurring the development of quantum-resistant cryptographic schemes. Beyond that, technologies such as Quantum Key Distribution (QKD) leverage the principles of quantum mechanics to create communication channels that are fundamentally secure against eavesdropping. Both the offensive applications (where quantum algorithms could disrupt existing encryption methods) and the defensive side (with quantum-secure communications) represent a dual-edged frontier being actively explored today.

  5. Quantum Sensing and Metrology Quantum sensors capitalize on phenomena like superposition and entanglement to measure physical quantities with extraordinary precision. These sensors have the potential to revolutionize fields requiring ultra-precise measurements—ranging from navigation systems and medical imaging to geological surveys and fundamental physics experiments. By beating classical limits on sensitivity and resolution, quantum sensing technologies might soon enable breakthroughs in fields where measurement accuracy is paramount.

  6. Fundamental Science and Many-Body Physics Beyond direct industrial applications, quantum computing offers a groundbreaking tool for probing the laws of nature. Whether simulating the behavior of superconductors, exploring phase transitions, or even delving into high-energy physics and quantum field theories, quantum processors are becoming invaluable for experiments that were once deemed theoretically intractable. These investigations not only deepen our understanding of the physical world but also pave the way for technologies yet to be imagined.

Each of these applications illustrates a different facet of quantum computing’s potential—whether it’s solving a long-standing scientific conundrum, optimizing a complex system, or reshaping digital security. In today’s rapidly advancing research landscape, quantum simulation and optimization as well as hybrid approaches bridging classical and quantum techniques are among the areas garnering substantial attention.

If you find the interplay between quantum simulation and real-world chemistry fascinating or are curious about how quantum optimization might transform industries like logistics and finance, there’s a wealth of deeper, interconnected topics to explore.

jueves, 20 de marzo de 2025

The Six Fundamental Concepts of Quantum Computing You Must Know


Nowadays, Quantum Computing is currently becoming of the most disruptive technologies due its potential to solve complex problems exponentially faster than classical computers, what makes it an increasingly important field. 

This note briefly introduces six key concepts that everyone interested about this technology should know:

  1. Qubit: In quantum computing, the qubit (or quantum bit) is the basic unit of information, serving a function similar to that of the bit in classical computing. However, unlike a classical bit, which can only be in one of two states: 0 or 1, a qubit can exist in a superposition of its two ground states, commonly denoted as |0⟩ and |1⟩. This superposition means that the qubit is, in a certain abstract sense, "between" the two ground states. Note that when a qubit is measured in the standard basis, the result is a classical bit.

  2. Superposition: In the context of quantum computing, superposition refers to the ability of a quantum system, such as a qubit, to exist in a linear combination of multiple states simultaneously until a measurement is made, at which point the system collapses to one of those states with a certain probability. This means that a quantum computer can process a vast amount of information in parallel, enabling much faster calculations for certain problems.

  3. Quantum Entanglement: This is a fundamental concept within the field of quantum information. Essentially, it describes the situation in which two or more quantum systems are correlated in a way that cannot be described by individual states, even when the systems are spatially separated. The properties of these entangled systems are intrinsically linked, such that the state of one instantaneously influences the state of the other, regardless of the distance between them. This property is key to the speed and security of quantum computing.

  4. Decoherence: Decoherence is the loss of a quantum state in a qubit. Environmental factors, such as radiation, can cause the quantum state of qubits to collapse. A major engineering challenge in building a quantum computer is designing the various features that attempt to delay the decoherence of the state, such as building special structures that shield the qubits from external fields.

  5. Quantum Gates: They are the fundamental building blocks of quantum circuits. Just as classical logic gates operate on bits, quantum gates act on qubits, allowing the execution of basic operations that manipulate those qubits, as well as the construction of quantum circuits that implement quantum algorithms. They are analogous to classical logic gates but operate under the principles of quantum mechanics. Unlike classical logic gates, quantum gates enable transformations of superposition states and entangle qubits to perform advanced computations. 

  6. Quantum Error Correction (QEC): Due to the fragile nature of quantum states, quantum systems are inherently fragile and susceptible to interactions with the environment, which can lead to errors that potentially compromise the viability of large-scale quantum computations. QEC algorithms are crucial for ensuring the reliability of large-scale quantum computation by mitigating the fragility of quantum states in the presence of noise and decoherence. This can be done by implementing redundancy in the encoding of quantum information and executing correction operations. QEC is a pivotal instrument that empowers scientists and engineers to construct precise and dependable quantum computers, ensuring more accurate and stable computations.

These six concepts are fundamental to understanding the power and challenges of quantum computing. As this technology advances, its impact increases significantly on fields such as cryptography, optimization, and artificial intelligence.

Suggested readings:

  1. What Is Quantum Computing? - IBM https://www.ibm.com/think/topics/quantum-computing

  2. Quantum Computing: Key Concepts, Developments, and Challenges - Argano https://argano.com/insights/articles/quantum-computing-key-concepts-developments-and-challenges.html

  3. Quantum Computing Basics: A Beginner's Guide - BlueQubit https://www.bluequbit.io/quantum-computing-basics

  4. Quantum Computing Technology: Understanding the Basics | NYIT https://online.nyit.edu/blog/quantum-computing-technology-understanding-the-basics

  5. What is Quantum Computing? - AWS https://aws.amazon.com/what-is/quantum-computing/

viernes, 31 de enero de 2025

A tale of programming: Why DeepSeek-R1 is so powerful?

A tale of programming: Why DeepSeek-R1 is so powerful? 

Introduction

On January 2025, DeepSeek R1 irrupted as a new Large Language Model (LLM), claiming that it had been developed by using substantially less resources: processing power, money, etc.; than comparable models available on the stage. And even more: it is open source, under MIT license.

I intensively use LLMs to get assistance researching and coding. Therefore, I usually download these models to execute them offline on my laptop, as a personal effort to reduce the environmental impact, considering the consumption of resources as power, water, etc.; so I did that again, and due to the processing power capabilities of the laptop, it was downloaded the minimal version of the model: DeepSeek-R1-Distill-Qwen-1.5B from Hugging Face.

After installing DeepSeek R1, I was favourably surprised by the differences about how the model generates answers to the prompts. See Figure 1 below.

Figure 1: How DeepSeek-R1 "thinks" before answers the prompt.

Therefore, I looked for additional references about this model, trying to understand why it has achieved this noticeable performance, considering the resources that were used; so I reviewed in detail how it was built, by reading the "DeepSeek-V3 Technical Report".

Key factors

In my opinion, there are four factors that explain why DeepSeek R1 has achieved this outstanding results: 

1. Research: Searching "DeepSeek" on arxiv.org shows about 77 papers published since september 2023. 

2. Focus: DeepSeek R1 works using less parameters than other models, incentivizing reasoning capabilities in its model. Read section 2. "Approach" on "DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning". 

3. Code optimization: The developers coded significant sections of DeepSeek-R1 by using Parallel Thread Execution (PTX) instead of programming by using the CUDA-toolkit. Notice that at the PTX level, the GPUs can be optimized as a Single Instruction Multiple Data (SIMD) computer; and even more: the GPUs can transfer data among them without the intervention of the CPU.

4. Data Compression: By using Vector Quantization (VQ) of the parameters, the volume of data transferred is significantly reduced. Note: I have personally used the VQ algorithm to compress echocardiographic video sequences.  You can review my GitHub repository  CompressionVQ. 

Conclusion

When it is mandatory to solve a problem, and there are not enough resources, your only alternative is to intensively use the best and most powerful computers available: human brains!

 





domingo, 27 de octubre de 2024

A Tale of Programming Languages - The impact of Quantum Computing

Quantum computers have been around for about forty years, but they are currently feasible to researchers and students. For example, IBM's Quantum Computing Technology ( https://www.ibm.com/quantum ), and MicroSoft's Azure Quantum Service ( https://quantum.microsoft.com/ ), provide access to them.

However, the easiest way to learn the new languages is by using simulators, and the aforementioned companies offer courses and training such as IBM's Qiskit ( https://www.ibm.com/quantum/qiskit ), and Azure's Katas ( https://quantum.microsoft.com/en-us/tools/quantum-katas ) for people interested in learning this different approach to computer programming.

Quantum programming languages are a new challenge; and the main reason to get involved should be the application, of course. Example: vehicle routing.

About this application it is recommended to read these papers:



lunes, 24 de junio de 2024

A tale of programming languages - Assembler in Critical Embedded Systems

Assembler, or assembly language, remains a vital tool in the world of embedded systems, particularly in environments where precision, efficiency, and reliability are of greatest importance. 

Two scenarios highlight its relevance: medical devices and industrial applications.

1. Medical Devices: Assembly language is crucial for several reasons:

  • Real-time performance: Ensures critical operations in devices like Electrocardiographic data collection and analysis should be executed within millisecond-level precision.
  • Resource optimization: Maximizes efficiency in power-constrained portable devices.
  • Deterministic behavior: Guarantees consistent and predictable operation, vital for patient safety.
  • Interrupt handling: Enables immediate response to critical patient events.
  • Direct hardware interaction: Allows precise control of specialized medical sensors and / or  actuators.

2. Industrial Applications: As example, an embedded system deployed in trucks working inside copper mines on 200x, featuring:

  1. Single Board Computer (SBC) with Cirrus EP9302 RISC processor
  2. 128 MB RAM
  3. Debian 2.4 OS
  4. GPS for location tracking
  5. Radio devices for communication in hostile environments

In this scenario, assembly language proved invaluable for:

  • Hardware-specific optimization: Tailoring code to the Cirrus EP9302 RISC architecture for maximum efficiency.
  • Resource management: Making the most of limited 128 MB RAM in a multitasking environment.
  • Real-time GPS processing: Ensuring accurate and timely location and trajectory data.
  • Robust communication: Optimizing radio device interfaces for reliable transmission in challenging mining conditions.
  • Environmental resilience: Implementing low-level routines to handle potential system instabilities caused by vibrations, dust, or electromagnetic interference.
Both scenarios demonstrate how assembly language provides:
  • Performance optimization: Crucial in resource-constrained environments, whether in a miniature medical implant or a rugged industrial computer.
  • Direct hardware control: Essential for interfacing with specialized equipment, from medical sensors to industrial-grade GPS and radio systems.
  • Reliability in critical operations: Ensuring consistent behavior in life-critical medical scenarios or harsh industrial environments.
  • Efficient interrupt handling: Vital for responsive systems, whether reacting to patient needs or rapidly changing mining conditions.
  • Size and power efficiency: Important in both portable medical devices and compact industrial systems with limited power sources.

Conclusion

While high-level languages dominate many areas of software development, assembly language continues to play a crucial role in embedded systems where direct hardware control, maximum efficiency, and reliability are non-negotiable. 

From life-saving medical devices to rugged industrial applications, assembly remains an indispensable tool in a programmer's arsenal, enabling solutions that push the boundaries of what's possible with limited resources in challenging environments.

viernes, 24 de mayo de 2024

A tale of programming languages Kotlin

 

A tale of programming languages: Kotlin


It was tested Gemini to generate the code from the picture Raices.PNG :

FINAL CODE

===========

/**

 * Solves a quadratic equation using the quadratic formula.

 *

 * @param a The coefficient of the x^2 term.

 * @param b The coefficient of the x term.

 * @param c The constant term.

 * @throws IllegalArgumentException if the coefficient 'a' is zero.

 * @return A pair containing the first and second roots of the equation, 

 *         or null for both if there are no real roots.

 */

fun solveQuadraticEquation(a: Double, b: Double, c: Double): Pair<Double?, Double?> {

    if (a == 0.0) {

        throw IllegalArgumentException("Coefficient 'a' cannot be zero.")

    }


    val invA = 1.0 / a // Precompute inverse of a for efficiency

    val halfInvA = invA / 2.0


    val discriminant = b * b - 4.0 * c * a

    if (discriminant < 0.0) {

        return Pair(null, null) // No real roots for negative discriminant

    }


    val sqrtDiscriminant = Math.sqrt(discriminant)

    val root1 = (-b + sqrtDiscriminant) * halfInvA

    val root2 = (-b - sqrtDiscriminant) * halfInvA

    return Pair(root1, root2)

}


// Unit Tests

class QuadraticEquationTest {


    @Test

    fun `should return distinct real roots for positive discriminant`() {

        val a = 1.0

        val b = -4.0

        val c = 4.0

        val expectedRoots = Pair(2.0, 0.0)

        val actualRoots = solveQuadraticEquation(a, b, c)

        assertEquals(expectedRoots, actualRoots)

    }


    @Test

    fun `should return equal real root for zero discriminant`() {

        val a = 1.0

        val b = -2.0

        val c = 1.0

        val expectedRoots = Pair(1.0, 1.0)

        val actualRoots = solveQuadraticEquation(a, b, c)

        assertEquals(expectedRoots, actualRoots)

    }


    @Test

    fun `should return null roots for negative discriminant`() {

        val a = 1.0

        val b = 2.0

        val c = 2.0

        val expectedRoots = Pair(null, null)

        val actualRoots = solveQuadraticEquation(a, b, c)

        assertEquals(expectedRoots, actualRoots)

    }


    @Test(expected = IllegalArgumentException::class)

    fun `should throw exception for zero coefficient a`() {

        solveQuadraticEquation(0.0, 1.0, 1.0)

    }


    @Test

    fun `should handle extremely large positive coefficients`() {

        val a = 1e20 // Very large positive a

        val b = 1e10

        val c = 1.0

        val expectedRoots = Pair(-5.0e-10, -2.0e-10) // Roots become very small

        val actualRoots = solveQuadraticEquation(a, b, c)

        assertEquals(expectedRoots.first!!.roundTo(10), actualRoots.first!!.roundTo(10))

        assertEquals(expectedRoots.second!!.roundTo(10), actualRoots.second!!.roundTo(10))

    }


    @Test

    fun `should handle extremely small positive coefficients`() {

        val a = 1e-20 // Very small positive a

        val b = 1.0

        val c = 1.0

        val expectedRoots = Pair(-1.0e+10, -1.0e+10) // Roots become very large

        val actualRoots = solveQuadraticEquation(a, b, c)

        assertEquals(expectedRoots.first!!.roundTo(10), actualRoots.first!!.roundTo(10))

        assertEquals(expectedRoots.second!!.roundTo(10), actualRoots.second!!.roundTo(10))

    }


    private fun Double.roundTo(decimals: Int): Double {

        val scale = Math.pow(10.0, decimals.toDouble())

        return Math.round(this * scale) / scale

    }

}

===========

Initial prompt:

You are an expert programming Kotlin. Can you write the best code in this language for the algorithm in the attached picture?

The image you sent shows a diagram for solving a quadratic equation using the quadratic formula.

This code defines a function solveQuadraticEquation that takes three arguments: a, b, and c, which are the coefficients of the quadratic equation ax^2 + bx + c = 0.

The function first calculates the discriminant, which is a quantity that determines the nature of the roots of the equation. The discriminant is calculated as b * b - 4 * a * c.

  • If the discriminant is greater than zero, then the roots are real and distinct. The code calculates the roots using the following formulas:

    • root1 = (-b + Math.sqrt(discriminant)) / (2 * a)
    • root2 = (-b - Math.sqrt(discriminant)) / (2 * a)
  • If the discriminant is equal to zero, then the roots are real and equal. The code calculates the root using the following formula:

    • root = -b / (2 * a)
  • If the discriminant is less than zero, then the roots are complex. The code returns null for both roots in this case.

The function returns a pair of doubles, where the first element is the first root and the second element is the second root. If the roots are complex, both elements of the pair will be null.

Second prompt

Write unit tests to ensure it handles all edge cases. Add type hints and documentation to the functions for better readability and maintainability.

Explanation:

  • We added comments to explain the function's purpose and parameters.
  • Type hints are added to function parameters and return types for better type safety.
  • A new class QuadraticEquationTest is created to hold the unit tests.
  • Three unit tests are written to cover different scenarios:
    • Positive discriminant (distinct real roots)
    • Zero discriminant (equal real root)
    • Negative discriminant (no real roots)
  • assertEquals function from a testing framework (like JUnit) is used to compare the expected and actual results.

This code ensures the function behaves correctly for various inputs and demonstrates good practices for writing maintainable and testable code.

Third prompt

Refactor the code to handle more edge cases or optimize performance. Add more detailed error handling and user-friendly messages in case of invalid inputs.

Explanation:

  • We removed the redundant check for discriminant == 0.0 as it's already handled by checking for negative discriminant.
  • We pre-compute the square root of the discriminant and store it in a variable sqrtDiscriminant to avoid redundant calculations within the formula. This is a minor optimization but can improve performance for complex calculations.
  • The main improvement is in the error handling. We now throw an IllegalArgumentException with a more user-friendly message if the coefficient 'a' is zero. This makes the code more robust and helps identify potential errors during development.

While this refactoring focuses on error handling and basic performance optimization, there might be further optimizations possible depending on the specific use case.

Fourth prompt

Optimize further by precomputing values or using more efficient mathematical functions if necessary. Add more complex unit tests, such as handling extremely large or small coefficients, to ensure robustness.

Explanation:

  • We precomputed the inverse of a and stored it in invA to avoid redundant division within the formula. This is a more significant optimization compared to precomputing the square root.
  • The unit tests are extended to cover:
    • Handling extremely large coefficients (e.g., 1e10)
    • Handling extremely small coefficients (e.g., 1e-10)

These additional tests ensure the code behaves correctly even with extreme values that might cause issues with floating-point precision.

Further Considerations:

  • For even more complex scenarios, you might explore alternative libraries like Apache Commons Math, which offer optimized implementations for mathematical functions.
  • Depending on the specific use case, additional logic for handling potential numerical instability issues might be necessary, especially when dealing with very large or small coefficients.