-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduced functionality for equivalence checking of parametrized circuits with QCEC. This PR is related to cda-tum/mqt-core#199 and cda-tum/zx#15 Signed-off-by: Lukas Burgholzer <[email protected]> Co-authored-by: Lukas Burgholzer <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lukas Burgholzer <[email protected]>
- Loading branch information
1 parent
7ee46bc
commit 844731f
Showing
22 changed files
with
2,596 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[submodule "extern/qfr"] | ||
path = extern/qfr | ||
url = https://github.com/cda-tum/qfr.git | ||
path = extern/qfr | ||
url = https://github.com/cda-tum/qfr.git | ||
branch = main | ||
shallow = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "77a131e6", | ||
"metadata": {}, | ||
"source": [ | ||
"# Verifying Parameterized Quantum Circuits\n", | ||
"\n", | ||
"## Variational Quantum Algorithms\n", | ||
"\n", | ||
"Variational quantum algorithms are a family of mixed quantum-classical algorithms that try to achieve a quantum advantage via low-depth circuits. This is achieved by offloading a substantial amount of computational work to a classical processor. The quantum circuits employed by variational quantum algorithms involve *parameterized gates* which depend on some a-priori uninstantiated variable.\n", | ||
"\n", | ||
"Variational quantum algorithms try to optimize the circuit's parameters in each iteration with the classical post-processor while the quantum circuit is used to compute the cost function that is being optimized. Because recompiling the quantum circuit in each of these iterations is a costly procedure, the circuit is usually compiled in *paramterized* form in which the parameters tuned by the classical optimization routine are not bound to specific values.\n", | ||
"\n", | ||
"As is the case with parameter-free circuits, errors can be made during the compilation process. Therefore verifying the correctness of compilations of parameterized quantum circuits is an important task for near-term quantum computing.\n", | ||
"\n", | ||
"\n", | ||
"## Equivalence Checking of Parameterized Quantum Circuits\n", | ||
"\n", | ||
"Having unbound parameters in a quantum circuits brings new challenges to the task of quantum circuit verification as many data structures have difficulty supporting symbolic computations directly. However, *ZX-diagrams* are an exceptions to this as most rewrite rules used for equivalence checking with the the *ZX-calculus* only involve summation of parameters. \n", | ||
"The ZX-calculus equivalence checker in QCEC cannot be used to prove non-equivalence of quantum circuits. To still show non-equivalence of parameterized quantum circuits QCEC uses a scheme of repeatedly instantiating a circuits parameters in such a way as to make the check as simple as possible while still guaranteeing that either equivalence or non-equivalence can be proven.\n", | ||
"The resulting *equivalence checking flow* looks as follows\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"## Using QCEC to Verify Parameterized Quantum Circuits\n", | ||
"\n", | ||
"Consider the following quantum circuit" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "977071d9", | ||
"metadata": {}, | ||
"source": [ | ||
"## Using QCEC to Verify Parameterized Quantum Circuits\n", | ||
"\n", | ||
"Consider the following quantum circuit" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "03b73b17", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qiskit import QuantumCircuit\n", | ||
"from qiskit.circuit import Parameter\n", | ||
"\n", | ||
"alpha = Parameter('alpha')\n", | ||
"beta = Parameter('beta')\n", | ||
"\n", | ||
"qc_lhs = QuantumCircuit(2)\n", | ||
"qc_lhs.rz(alpha, 1)\n", | ||
"qc_lhs.cx(0, 1)\n", | ||
"qc_lhs.rz(beta, 1)\n", | ||
"qc_lhs.cx(0, 1)\n", | ||
"qc_lhs.draw(output='mpl')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3b85338e", | ||
"metadata": {}, | ||
"source": [ | ||
"A well known commutation rule for the $R_Z$ gate, states that this circuit is equivalent to the following one" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "36df44b7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"qc_rhs = QuantumCircuit(2)\n", | ||
"qc_rhs.cx(0, 1)\n", | ||
"qc_rhs.rz(beta, 1)\n", | ||
"qc_rhs.cx(0, 1)\n", | ||
"qc_rhs.rz(alpha, 1)\n", | ||
"qc_rhs.draw(output='mpl')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8cae4862", | ||
"metadata": {}, | ||
"source": [ | ||
"This equality can be proved with QCEC by using the `verify` method just as with any regular circuit" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "da9fa188", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mqt import qcec\n", | ||
"\n", | ||
"qcec.verify(qc_lhs, qc_rhs)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "59d13843", | ||
"metadata": {}, | ||
"source": [ | ||
"QCEC also manages to show non-equivalence of parameterized quantum circuits. \n", | ||
"It is easy to erroneously exchange the parameters in the above commutation rule." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "02f203af", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"qc_rhs_err = QuantumCircuit(2)\n", | ||
"qc_rhs_err.cx(0, 1)\n", | ||
"qc_rhs_err.rz(alpha, 1)\n", | ||
"qc_rhs_err.cx(0, 1)\n", | ||
"qc_rhs_err.rz(beta, 1)\n", | ||
"qc_rhs_err.draw(output='mpl')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b64736b0", | ||
"metadata": {}, | ||
"source": [ | ||
"QCEC will tell us that this is incorrect" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7e771154", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"qcec.verify(qc_lhs, qc_rhs_err)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c9d9d3aa", | ||
"metadata": {}, | ||
"source": [ | ||
"Check out the [reference documentation](library/VerifyCompilation.rst#mqt.qcec.verify_compilation) documentation for more information." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "98d4cd4d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "general", | ||
"language": "python", | ||
"name": "general" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.