예제 #1
0
def test_plot_state_histogram_result():
    qubits = cirq.LineQubit.range(4)
    c = cirq.Circuit(
        cirq.X.on_each(*qubits[1:]),
        cirq.measure(*qubits),  # One multi-qubit measurement
    )
    r = cirq.sample(c, repetitions=5)
    expected_values = [0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0]
    _, (ax1, ax2) = plt.subplots(1, 2)
    state_histogram.plot_state_histogram(r, ax1)
    state_histogram.plot_state_histogram(expected_values, ax2)
    for r1, r2 in zip(ax1.get_children(), ax2.get_children()):
        if isinstance(r1, mpl.patches.Rectangle) and isinstance(r2, mpl.patches.Rectangle):
            assert str(r1) == str(r2)
예제 #2
0
def test_plot_state_histogram_collection():
    qubits = cirq.LineQubit.range(4)
    c = cirq.Circuit(
        cirq.X.on_each(*qubits[1:]),
        cirq.measure(*qubits),  # One multi-qubit measurement
    )
    r = cirq.sample(c, repetitions=5)
    _, (ax1, ax2) = plt.subplots(1, 2)
    state_histogram.plot_state_histogram(r.histogram(key='0,1,2,3'), ax1)
    expected_values = [5]
    tick_label = ['7']
    state_histogram.plot_state_histogram(expected_values, ax2, tick_label=tick_label, xlabel=None)
    for r1, r2 in zip(ax1.get_children(), ax2.get_children()):
        if isinstance(r1, mpl.patches.Rectangle) and isinstance(r2, mpl.patches.Rectangle):
            assert str(r1) == str(r2)