<jupyter_start><jupyter_text>Hadamard and Measure<jupyter_code>from qiskit import *
%pylab inline
backend = BasicAer.get_backend('dm_simulator')
# Noise parameters
options = {}
options_noisy = {
    "thermal_factor": 0.,
    "decoherence_factor": .9,
    "depolarization_factor": 0.99,
    "bell_depolarization_factor": 0.99,
    "decay_factor": 0.99,
    "rotation_error": {'rx':[1., 0.], 'ry':[1., 0.], 'rz': [1., 0.]},
    "tsp_model_error": [1., 0.],
    "plot": False
    }
h1_qc = QuantumCircuit(1,1)
h1_qc.h(0)
h1_qc.measure(0,0,basis='Ensemble', add_param='Z')

run = execute(h1_qc,backend,**options)
result = run.result()
run_error = execute(h1_qc,backend,**options_noisy)
result_error = run_error.result()
# Final state (probabilities)
prob = result['results'][0]['data']['ensemble_probability']
prob_error = result_error['results'][0]['data']['ensemble_probability']

labels = prob.keys()
without_noise = prob.values()
with_noise = prob_error.values()

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, without_noise, width, label='Without Noise')
rects2 = ax.bar(x + width/2, with_noise, width, label='With Noise')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Probability')
ax.set_title('Ensemble Probabilities with Noise')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
plt.show()
num_qubits = 5
h1_qc = QuantumCircuit(num_qubits,1)
h1_qc.h(range(num_qubits))
h1_qc.measure(0,0,basis='Ensemble', add_param='Z')

run = execute(h1_qc,backend,**options)
result = run.result()
run_error = execute(h1_qc,backend,**options_noisy)
result_error = run_error.result()
# Final state (probabilities)
prob = result['results'][0]['data']['ensemble_probability']
prob_error = result_error['results'][0]['data']['ensemble_probability']

labels = prob.keys()
without_noise = prob.values()
with_noise = prob_error.values()

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, without_noise, width, label='Without Noise')
rects2 = ax.bar(x + width/2, with_noise, width, label='With Noise')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Probability')
ax.set_title('Ensemble Probabilities with Noise')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1627435064935065, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 6.022792022792022, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '237520', 'license': 'MIT', 'n_tokens_mistral': 975, 'n_tokens_neox': 921, 'n_words': 190, 'path': 'notebooks/dm-simulator-notebooks/hadamard.ipynb', 'repo_name': 'deadbeatfour/intro-qc-2021', 'size': '2464'}