Background: Quantum computing is a rapidly growing new programming paradigm that brings significant changes to the design and implementation of algorithms. Understanding quantum algorithms requires knowledge of physics and mathematics, which can be challenging for software developers. Aims: In this work, we provide a first analysis of how LLMs can support developers' understanding of quantum code. Method: We empirically analyse and compare the quality of explanations provided by three widely adopted LLMs (Gpt3.5, Llama2, and Tinyllama) using two different human-written prompt styles for seven state-of-the-art quantum algorithms. We also analyse how consistent LLM explanations are over multiple rounds and how LLMs can improve existing descriptions of quantum algorithms. Results: Llama2 provides the highest quality explanations from scratch, while Gpt3.5 emerged as the LLM best suited to improve existing explanations. In addition, we show that adding a small amount of context to the prompt significantly improves the quality of explanations. Finally, we observe how explanations are qualitatively and syntactically consistent over multiple rounds. Conclusions: This work highlights promising results, and opens challenges for future research in the field of LLMs for quantum code explanation. Future work includes refining the methods through prompt optimisation and parsing of quantum code explanations, as well as carrying out a systematic assessment of the quality of explanations.
翻译:背景:量子计算是一种快速发展的新型编程范式,为算法的设计与实现带来了重大变革。理解量子算法需要物理学和数学知识,这对软件开发人员而言可能具有挑战性。目标:在本工作中,我们首次分析了大型语言模型如何支持开发者理解量子代码。方法:我们通过实证分析,比较了三种广泛采用的大型语言模型(Gpt3.5、Llama2和Tinyllama)针对七种最先进的量子算法,使用两种不同的人工编写提示风格所提供的解释质量。我们还分析了大型语言模型的解释在多轮生成中的一致性,以及它们如何改进现有的量子算法描述。结果:Llama2 在从零生成时提供了最高质量的解释,而 Gpt3.5 则是最适合改进现有解释的大型语言模型。此外,我们发现向提示中添加少量上下文能显著提高解释的质量。最后,我们观察到解释在多次生成中在定性和句法上均保持一致性。结论:这项工作展示了有前景的结果,并为未来在大型语言模型用于量子代码解释领域的研究提出了挑战。未来的工作包括通过提示优化和量子代码解释的解析来改进方法,以及对解释质量进行系统性评估。