<jupyter_start><jupyter_text>Two-Qubit Characterization SequencesExamples of two-qubit sequences, including CR gates<jupyter_code>from QGL import *<jupyter_output><empty_output><jupyter_text>See Auspex [example notebooks](https://github.com/BBN-Q/Auspex/tree/develop/doc/examples) on how to configure a channel library.For the examples in this notebook, we will the channel library generated by running `ex1_QGL_basics.ipynb` in this same directory.<jupyter_code>cl = ChannelLibrary("example")
q1 = cl["q1"]

# Repeat similar configuration for q2
q2 = cl.new_qubit("q2")
aps2_3 = cl.new_APS2("BBNAPS3", address="192.168.5.103") 
aps2_4 = cl.new_APS2("BBNAPS4", address="192.168.5.104")
dig_2  = cl.new_X6("X6_2", address=0)
cl.set_control(q2, aps2_3)
cl.set_measure(q2, aps2_4, dig_2.ch(1))<jupyter_output><empty_output><jupyter_text>One can define simultaneous operations on qubits using the `*` operator (indicating a tensor product), see  [ex1_QGL_basics](./ex1_QGL_basics.ipynb).  Below is an example of QGL basic sequence for two qubits. * The first argument (a tuple) selects the driven qubits* The optional argument `measChans` selects which qubits to measure (default = all driven)* The optional argument `add_cals` adds reference segments corresponding to the computational states at the end of the sequence, used to normalize the readout signals<jupyter_code>RabiPoints = 101;
plot_pulse_files(RabiAmp_NQubits((q1,q2),np.linspace(0,1,RabiPoints), measChans=(q1,q2), add_cals=True))<jupyter_output><empty_output><jupyter_text>Two-qubit gates To write a two-qubit gate in QGL, you must add to your channel library a logical channelrepresenting the coupling between qubits. In QGL terminology, this is known asan `Edge`, and is a *directed* edge in the connectivity graph of your device.QGL uses directed edges because certain two-qubit interactions have a preferredordering of the interaction. For instance, a cross resonance gate has apreferred sign of the qubit-qubit detuning. By storing directed edges, we canwrite two-qubit primitives that emit different pulses depending on whether the(control, target) pair is aligned or anti-aligned with the underlyinginteraction Hamiltonian.The following examples declares that q1 and q2 are connected, and defines an edge connecting from q1 to q2:<jupyter_code>e = cl.new_edge(q1, q2)<jupyter_output><empty_output><jupyter_text>We can now include `CNOT` gates in our sequences. In this example you can see the use of the two-qubit primitive `CNOT`.The exact sequence will depend on the (source,target) order you selected in creating the q1-q2 `Edge` and on the chosen `cnot_implementation`. You can select adifferent default `CNOT` implementation by modifying the [cnot_implementation](https://github.com/BBN-Q/QGL/blob/3dce4ec0996ee010f8a80f3a64e585b1f7b9f7d3/QGL/config.pyL34) keyin your local QGL's `config.py` file.  In order to actually compile a CNOT, there needs to be a physical channel and generator associated with the edge, i.e.:<jupyter_code># Most calls required label and address. Let's define 
# an AWG for control pulse generation 
aps2_5 = cl.new_APS2("BBNAPS5", address="192.168.5.106") 
cl.set_control(e, aps2_5)
seqs = [[Id(q1), CNOT(q1, q2)]] # use the default CNOT_simple implementation, where the CNOT is represented as an X pulse
mf = compile_to_hardware(seqs,'CNOT_simple')  
plot_pulse_files(mf)<jupyter_output><empty_output><jupyter_text>You can also explicitly call `CNOT_CR` to use the CR decomposition, independently of the global configuration.<jupyter_code>seqs = [[Id(q1), CNOT_CR(q1, q2)]] # use the CNOT_CR implementation, where the CNOT is decomposed 
# into a sequence of single-qubit gates and a ZX90, as is appropriate for a cross-resonance interaction.
mf = compile_to_hardware(seqs,'CNOT_CR')  
plot_pulse_files(mf)<jupyter_output><empty_output><jupyter_text>Inverting the order of the `CNOT_CR` input will also produce a CNOT using the same directed edge (q1->q2), but with added single-qubit gates to invert the CNOT control and target.<jupyter_code>seqs = [[Id(q1), CNOT_CR(q2, q1)]] # use the CNOT_CR implementation, where the CNOT is decomposed 
# into a sequence of single-qubit gates and a ZX90, as is appropriate for a cross-resonance interaction.
mf = compile_to_hardware(seqs,'CNOT_CR_inv')  
plot_pulse_files(mf)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08674643350207087, 'fraction_numerical': 0.02807179015186378, 'mean_word_length': 6.22093023255814, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '30058', 'license': 'Apache-2.0', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1389, 'n_words': 478, 'path': 'doc/ex3_two-qubit_sequences.ipynb', 'repo_name': 'gribeill/QGL', 'size': '4346'}