0

I am working on a simple program using Qiskit in python in which the programs are using evolutionarily algorithms to search for a desired circuit. I need to compare the generated circuits with desired one but I don't know how? I know that there is no truth table for quantum circuits. But for example I need to check if a circuit is working true as an adder or not. How to do this in Qiskit?

AMZ
  • 123
  • 2

1 Answers1

0

I believe the trick will be to compare the resulting state vectors. Start with your desired circuit, simulate it, and read out the state vector. Then try your auto-generated circuit, run it as well, and read out that state vector. If the parts of the state vector that represent the result match - bingo, your generated circuit is working (always advisable to test it on all possible inputs).

For example, if you want to add 3 + 5 in a $n$ qubit representation, the circuit likely does something like representing the inputs with (for example) two registers with 5 qubits each (with an additional qubit each to account for carry in the result), eg.: $$ a = |000011\rangle \\ b = |000101\rangle $$ The adder circuit must also reserve an $n+1$-register for the result (the $+1$ is again required to account for a potential carry). If you read out the result register and look for the sub-state with the highest probability, you can check whether the result has been computed correctly as: $$ {\tt result} = |001000\rangle $$

This post shows how to get the state vector from Qiskit. I'm not sure whether you are doing addition in the Fourier domain but to simulate a classic adder, I put a trivial implementation (not using Qiskit) of a 1-bit full adder here.

rhundt
  • 988
  • 4
  • 12
  • can you help me with a ternary adder circuit in qiskit to use as desired circuit? – AMZ Dec 31 '22 at 19:51
  • Something like a = b + c + d? What bit width? Using quantum gates to implement a classical full adder cascade? OR in the Fourier domain? Both would be easy for me in my code base but I'm not very proficient with Qiskit. – rhundt Jan 01 '23 at 01:10
  • See code in https://github.com/Qiskit/qiskit-terra/pull/5700 – Yael Ben-Haim Jan 01 '23 at 06:25