0

So I'm following the steps that are described in this web page:

https://qiskit.org/textbook/ch-applications/satisfiability-grover.html

to solve other SAT problems using qiskit... everything was going as described, until I reach this part:

    backend = Aer.get_backend('aer_simulator')
    quantum_instance = QuantumInstance(backend, shots=1024)

    problem = AmplificationProblem(oracle=oracle, is_good_state=v.is_correct)

    grover = Grover(quantum_instance=quantum_instance)
    result = grover.amplify(problem)
    result.top_measurement

I encounter this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/wg/_ml06fx93y16vp67ddnck18c0000gn/T/ipykernel_96293/2289216011.py in <module>

     10 grover = Grover(quantum_instance=quantum_instance)
-->  11 result = grover.amplify(problem)
     12 result.top_measurement

~/opt/anaconda3/envs/QC/lib/python3.9/site-packages/qiskit/algorithms/amplitude_amplifiers/grover.py in amplify(self, amplification_problem)

    247 
    248             all_circuit_results.append(circuit_results)
--> 249             oracle_evaluation=amplification_problem.is_good_state(top_measurement)
    250             if oracle_evaluation is True:
    251                 break  # we found a solution

/var/folders/wg/_ml06fx93y16vp67ddnck18c0000gn/T/ipykernel_96293/3999473027.py in is_correct(self, guess)

     33                     lit_eval = not guess[int(literal)-1]
     34                 else:
---> 35                     lit_eval = guess[int(literal)-1]
     36                 clause_eval |= lit_eval
     37             if clause_eval is False:

ValueError: invalid literal for int() with base 10: ''

I'm assuming that there was a mistranslation issue somewhere, where the boolean is being interpreted as an int. If anyone know a solution or recognizes something that I messed up, I'd highly appreciate the feedback. Thank you!

  • From what I can the Verifier is_correct method has a bug. It does this "for line in self.dimacs.split('\n'):" but since the DIMACS file ends in \n the split ends up with a trailing empty entry which it goes on to interpret and fails as you observe. If you change that to not include the last character, i.e the trailing \n by slicing it off say, as follows, "for line in self.dimacs[:-1].split('\n'):" then it works. – Steve Wood May 12 '22 at 20:37
  • @SteveWood Thanks a lot... that actually did it. I know that I'm really late, but better late than never. Please post this as an answer so that I could close this question. – Ahmad Bennakhi Oct 07 '22 at 14:27

0 Answers0