1
$\begingroup$

I want to use QAOAProgram from Qiskit in the following way:

from qiskit_optimization.runtime import QAOAProgram
from qiskit_optimization.converters import QuadraticProgramToQubo
from qiskit_optimization.applications.max_cut import Maxcut

max_cut_quadr_program = Maxcut(graph).to_quadratic_program()
pauli, f = max_cut_quadr_program.to_ising()

optimizer = {'name': 'SPSA',
             'maxiter': 50}
backend = provider.get_backend('ibmq_qasm_simulator')

runtime_qaoa = QAOAProgram(
                         callback=None,
                         optimizer=optimizer,
                         initial_point=None,
                         provider=provider,
                         backend=backend,
                         shots=8192,
                         measurement_error_mitigation=True)

runtime_result = runtime_qaoa.compute_minimum_eigenvalue(pauli)

But I got this error:


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-40-1f2a3143b054> in <module>()
     19                          measurement_error_mitigation=True)
     20 
---> 21 runtime_result = runtime_qaoa.compute_minimum_eigenvalue(pauli)

10 frames
/usr/local/lib/python3.7/dist-packages/qiskit_optimization/runtime/qaoa_program.py in compute_minimum_eigenvalue(self, operator, aux_operators)
    158             mixer_operator=self.mixer,
    159         )
--> 160         return super().compute_minimum_eigenvalue(operator, aux_operators)

/usr/local/lib/python3.7/dist-packages/qiskit_optimization/runtime/vqe_program.py in compute_minimum_eigenvalue(self, operator, aux_operators)
    272             inputs=inputs,
    273             options=options,
--> 274             callback=self._wrap_vqe_callback(),
    275         )
    276         # print job ID if something goes wrong

/usr/local/lib/python3.7/dist-packages/qiskit/providers/ibmq/runtime/ibm_runtime_service.py in run(self, program_id, options, inputs, callback, result_decoder)
    233 
    234         backend_name = options['backend_name']
--> 235         params_str = json.dumps(inputs, cls=RuntimeEncoder)
    236         result_decoder = result_decoder or ResultDecoder
    237         response = self._api_client.program_run(program_id=program_id,

/usr/lib/python3.7/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    236         check_circular=check_circular, allow_nan=allow_nan, indent=indent,
    237         separators=separators, default=default, sort_keys=sort_keys,
--> 238         **kw).encode(obj)
    239 
    240 

/usr/lib/python3.7/json/encoder.py in encode(self, o)
    197         # exceptions aren't as detailed.  The list call should be roughly
    198         # equivalent to the PySequence_Fast that ''.join() would do.
--> 199         chunks = self.iterencode(o, _one_shot=True)
    200         if not isinstance(chunks, (list, tuple)):
    201             chunks = list(chunks)

/usr/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
    255                 self.key_separator, self.item_separator, self.sort_keys,
    256                 self.skipkeys, _one_shot)
--> 257         return _iterencode(o, 0)
    258 
    259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

/usr/local/lib/python3.7/dist-packages/qiskit/providers/ibmq/runtime/utils.py in default(self, obj)
    127             value = _serialize_and_encode(
    128                 data=obj,
--> 129                 serializer=lambda buff, data: qpy_serialization.dump(data, buff)
    130             )
    131             return {'__type__': 'QuantumCircuit', '__value__': value}

/usr/local/lib/python3.7/dist-packages/qiskit/providers/ibmq/runtime/utils.py in _serialize_and_encode(data, serializer, compress, **kwargs)
     54     """
     55     buff = io.BytesIO()
---> 56     serializer(buff, data, **kwargs)
     57     buff.seek(0)
     58     serialized_data = buff.read()

/usr/local/lib/python3.7/dist-packages/qiskit/providers/ibmq/runtime/utils.py in <lambda>(buff, data)
    127             value = _serialize_and_encode(
    128                 data=obj,
--> 129                 serializer=lambda buff, data: qpy_serialization.dump(data, buff)
    130             )
    131             return {'__type__': 'QuantumCircuit', '__value__': value}

/usr/local/lib/python3.7/dist-packages/qiskit/circuit/qpy_serialization.py in dump(circuits, file_obj)
    853     file_obj.write(header)
    854     for circuit in circuits:
--> 855         _write_circuit(file_obj, circuit)
    856 
    857 

/usr/local/lib/python3.7/dist-packages/qiskit/circuit/qpy_serialization.py in _write_circuit(file_obj, circuit)
    871         num_instructions=num_instructions,
    872     )
--> 873     header = struct.pack(HEADER_PACK, *header_raw)
    874     file_obj.write(header)
    875     file_obj.write(circuit_name)

error: required argument is not a float

Qiskit verison: 0.28

What am I doing wrong?

My idea is that there is some issue with my ansatz or PauliSumOp is not correct, but maybe someone has a better explanation.

New contributor
grafix is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
5
  • $\begingroup$ Hello, I don't know why this doesn't work, but by downgrading to qiskit 0.27 I managed to get your code working. Maybe you could downgrade while the issue is solved? :) $\endgroup$ – Lena 2 days ago
  • 4
    $\begingroup$ Hi @grafix, thanks for posting this! But I’m voting to close this question because this is a technical Qiskit issue which should be posted as issue on GitHub, that gives your issue more visibility to the Qiskit team and we can cross-reference it more easily :) $\endgroup$ – Cryoris yesterday
  • $\begingroup$ @Lena, you are right - with qiskit 0.27 it's working. $\endgroup$ – grafix yesterday
  • 1
    $\begingroup$ All right, @Cryoris. I submitted an issue here. $\endgroup$ – grafix yesterday
  • $\begingroup$ A PR to fix it is up already: github.com/Qiskit/qiskit-terra/pull/6792 $\endgroup$ – Cryoris 23 hours ago
0
$\begingroup$

I submitted an issue on GitHub here.

New contributor
grafix is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.