Recording Experimental Results

Circuits are provided as Circuit objects.

A circuit object contains a results property into which experimental results should be input once the circuit is performed (or simulated). This property is initially an empty dictionary. Once data have been collected, it is a mapping between bitstrings and the number of shots that resulted in that bitstring. Bitstrings that were not observed should not be entered. For instance, if a 2-qubit device performs 50 shots of a given circuit object, then circuit.results might have the value

circuit.results
>>> {'00': 47, '01': 2, '10': 1}

In this example, the qubits were measured as being in the \(|00\rangle\) state 47 times, in the \(|01\rangle\) state two times, and in the \(|10\rangle\) state once.

Note

Each bitstring must have a length equal to n_qubits. The order of bitstrings coincides with targets.

Setting Results

Results can be entered simply by setting the results property to a new dictionary, or updating the existing dictionary using increment_state().

Example

The following is a functional example showing how to populate and modify the results of a Circuit object.

#
# Recording results example.
# Copyright 2019 Quantum Benchmark Inc.
#

import trueq as tq

# Initialize a 3-qubit circuit.
circuit = tq.Circuit(tq.Cycle({(0, 1): tq.Gate.cz, (2,): tq.Gate.x}))
circuit.measure_all()

# Set the results of the circuit and print.
circuit.results = {"011": 5, "101": 15}
print(circuit.results)

# Increment the '111' result and print the updated results.
circuit.results["111"] = 10
print(circuit.results)

The output of the above example is:

Results({'011': 5, '101': 15})
Results({'011': 5, '101': 15, '111': 10})