1
$\begingroup$

Here's part of the code I'm working on:

all_circuits = []
for _ in range(100):
    all_circuits.extend([quanc_z,quanc_x,quanc_y])
all_circuits = transpile(all_circuits, backend=backend)
MExperiments = job_manager.run(all_circuits, backend=backend, shots = 1024)
results = meas_filter.apply(MExperiments.results())
memory_z = results.get_memory()
memory_x = results.get_memory() 
memory_y = results.get_memory()   # Question

I have a list of quantum circuits all_circuits composed of the repeating circuit sequence quanc_z(,x,y) and I'm trying to run them using qiskit job_manager. I applied the readout error mitigation to the results and I want to get the memories of each quantum circuit in all_circuits, and combine the memories with the same label z,x,y on their associated circuits. I wonder is there a way I can get the memory for each circuit that I submitted in a bundle using job manager? Thanks for the help!!

$\endgroup$

1 Answer 1

3
$\begingroup$

Yes, but it has more to do with extracting data from the result and not so much with job manager.

Method 1, use the circuit index. If your circuits are always in the z, x, y order, then you can do something like

memory_z = []
memory_x = []
memory_y = []

for i in range(len(all_circuits)):
    mem = results.get_memory(i)
    if i % 3 == 0:
        memory_z.append(mem) # or however you want to combine them
    elif i % 3 == 1:
        memory_x.append(mem)
    else:
        memory_y.append(mem)

Method 2, assign metadata to each circuit and use that to differentiate individual result data, something like

quanc_z.metadata = {"tag": "z"}
quanc_x.metadata = {"tag": "x"}
quanc_y.metadata = {"tag": "y"}

combined = results.combine_results()
for i, r in enumerate(combined.results):
    if r.header.metadata["tag"] == "z":
        memory_z.append(results.get_memory(i))
    ...  # repeat for the other 2

2 additional things to note:

  1. You need a lower measurement level or memory=True in your job_manager.run() to get memory data. See the get_memory doc for more details.

  2. Measurement correction fitters in qiskit-ignis, if that's what you're using, usually takes a Result object as an input. Job manager, on the other hand, returns a ManagedResults object. But you can use the combine_results() method to convert a ManagedResults to a Result:

managed_result = job_manager.run(...).results()
result_to_fitter = managed_result.combine_results()

This combine_results() was needed in method 2 above because ManagedResults doesn't have the results attributes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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