From c447e61957c576463f729e2280a0179e79f47c2a Mon Sep 17 00:00:00 2001 From: mbeisel Date: Fri, 12 Jan 2024 15:30:12 +0100 Subject: [PATCH] enable qiskit object export als legacy feature --- app/model/circuit_response.py | 9 ++++++++- app/services/algorithms/knapsack_qaoa_algorithm.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/model/circuit_response.py b/app/model/circuit_response.py index ed80c26..6335478 100644 --- a/app/model/circuit_response.py +++ b/app/model/circuit_response.py @@ -1,3 +1,7 @@ +import codecs +import pickle + + from datetime import datetime import marshmallow as ma from app.model.encoding_request import ( @@ -20,7 +24,10 @@ def export_circuit(circuit, input): - if ( + # THIS OPTION MAY LEAD TO INCOMPATIBLE EXPORT WITH DIFFERENT QISKIT VERSIONS AND IS NOT RECOMMENDED + if input.circuit_format == "qiskit": + codecs.encode(pickle.dumps(circuit), "base64").decode(), + elif ( hasattr(input, "parameterized") and input.parameterized ) or input.circuit_format == "openqasm3": return qiskit.qasm3.dumps(circuit) diff --git a/app/services/algorithms/knapsack_qaoa_algorithm.py b/app/services/algorithms/knapsack_qaoa_algorithm.py index 6268d91..2fa35f2 100644 --- a/app/services/algorithms/knapsack_qaoa_algorithm.py +++ b/app/services/algorithms/knapsack_qaoa_algorithm.py @@ -39,4 +39,5 @@ def create_circuit(cls, values, weights, max_weights, p, betas, gammas): qaoa = QAOA(reps=p) qaoa_qc = qaoa.construct_circuit(angles, operator)[0] qaoa_qc = qaoa_qc.decompose(reps=100) + qaoa_qc.measure_all() return qaoa_qc