<jupyter_start><jupyter_text>Threerra Example First, we import the necessary packages for the correct execution of our module.<jupyter_code>import threerra # Load threerra

import numpy as np
from qiskit.tools.visualization import plot_histogram
from qiskit.tools.monitor import job_monitor
# Load IMB Quantum credentials
from qiskit import IBMQ
IBMQ.load_account()<jupyter_output><empty_output><jupyter_text>It's important to choose a backend that's compatible with Qiskit Pulse, or else the Threerra Module won't be able to be executed. In this case, we use the open-access 1 qubit "ibmq_armonk" Quantum Processor, which is available for free.<jupyter_code># Choose device
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
backend = provider.get_backend('ibmq_armonk')<jupyter_output><empty_output><jupyter_text>Testing different gates and drawing the pulse schedule The first step is to create a quantum circuit with a given backend. This class have a series of pulses already implemented acting on both $01$ and $12$ subspaces, like $X$ gates, rotation gates $R_x(\theta)$, and more (read Documentation for more details). For the rotation gates, the user needs to also specify a given angle. To better visualize what's beeing applied, the function draw() shows the whole pulse schedule in detail.<jupyter_code># Test QuantumCircuit3
qc = threerra.QuantumCircuit3(backend)                     # Initialize the quantum circuit
qc.rx_01(np.pi/2)                                          # Apply rx gate with angle np.pi/2 in the subspace 01
qc.x_01()                                                  # Apply x gate in the subspace 01
qc.x_12()                                                  # Apply x gate in the subspace 12
qc.rz(np.pi)                                               # Apply rz gate with angle np.pi
qc.rx_12(np.pi/2)                                          # Apply rx gate with angle np.pi/2 in the subspace 12
qc.draw()<jupyter_output><empty_output><jupyter_text>Test calibrations Before we make a real experiment, it's important to calibrate the $0\rightarrow1$, $1\rightarrow2$ frequencies, and also the $0\rightarrow1$, $1\rightarrow2$ $\pi$ pulse amplitudes, using the following functions:<jupyter_code># Calibrate the 0 --> 1 frequency using a frecuency sweep.


#qc.calibrate_freq_01()
# Calibrate the 0 --> 1 \pi pulse with a Rabi experiment


#qc.calibrate_pi_amp_01()
# Calibrate the 1 --> 2 frequency using a frecuency sweep and the sideband method.


#qc.calibrate_freq_12()
# Calibrate the 1 --> 2 \pi pulse with a Rabi experiment and the sideband method.


#qc.calibrate_pi_amp_12()<jupyter_output>Calibrating pi_amp_12...
Job Status: job has successfully run
pi_amp_12 updated from 0.2797548240848574 to 0.3284615055672541.<jupyter_text>Test Measurement  In the following examples, we will test the measurement function, and compare our results with the expected theoretical values. After the calibrations are ready, we import the functions necessary to recover the experiments data and both of our discriminators, the nearest centroid (default configuration) and LDA (Linear Discriminant Analysis) discriminator.<jupyter_code>from threerra.tools import get_counts

from threerra.discriminators.nearest_discriminator import discriminator as nst_disc
from threerra.discriminators.LDA_discriminator import discriminator as lda_disc<jupyter_output><empty_output><jupyter_text>The following circuit takes a $|0\rangle$ state and returns a $|2\rangle$ state after applying the gates $X_{01}$ and $X_{12}$. We then apply a measurement pulse to retrieve the data when we execute the circuit.<jupyter_code>qc2 = threerra.QuantumCircuit3(backend)
qc2.x_01()
qc2.x_12()
qc2.measure()
qc2.draw()<jupyter_output><empty_output><jupyter_text>Next, we execute the circuit. The job_monitor function tells us the status of the job.<jupyter_code>job2 = qc2.run()
job_monitor(job2)<jupyter_output>Job Status: job has successfully run<jupyter_text>After the job is done, we get the job's data using the result() function, and apply the get_counts() function with both of our discriminators, to get the number of counts per state.<jupyter_code>result2 = job2.result()
counts_nst2 = get_counts(result2, discriminator=nst_disc)
counts_lda2 = get_counts(result2, discriminator=lda_disc)
state2_teo = {'0': 0, '1': 0, '2': 1024}<jupyter_output><empty_output><jupyter_text>Finally, we compare the results using both discriminators with the theoretical value with a histogram plot.<jupyter_code>comparision2 = [counts_nst2, counts_lda2, state2_teo]
plot_histogram(comparision2, legend=['Near','LDA', 'Theoric'])<jupyter_output><empty_output><jupyter_text>Finally, we intend to obtain a superposition $\frac{1}{\sqrt{2}}\left(|1\rangle + |2\rangle\right)$. To achieve this, we construct ourselves a Hadamard gate $H_{12}$ that acts onto the $12$ subspace. This gate is constructed as follows:<jupyter_code>qc12 = threerra.QuantumCircuit3(backend)
qc12.x_01()
qc12.x_12()
qc12.ry_12(np.pi/2.0)
qc12.measure()
qc12.draw()
job12 = qc12.run()
job_monitor(job12)
result12 = job12.result()
counts_lda12 = get_counts(result12, discriminator=lda_disc)
counts_nst12 = get_counts(result12, discriminator=nst_disc)

state12_teo = {'0': 0, '1': 512, '2': 512}
comparision12 = [counts_nst12, counts_lda12, state12_teo]
plot_histogram(comparision12, legend=['Near','LDA', 'Theoric'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08747697974217311, 'fraction_numerical': 0.036464088397790057, 'mean_word_length': 4.698845750262329, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '666576', 'license': 'Apache-2.0', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1654, 'n_words': 559, 'path': 'Example_notebooks/01 Example_Discriminator Tests.ipynb', 'repo_name': 'jgidi/threerra', 'size': '5430'}