<jupyter_start><jupyter_text>Small Circuit with Single Gate ExampleThis is a small example I wrote that showcases the a three-input quantum gate taking advantage of out-of-order inputs. This requires that the simulator automatically put in correct SWAP gates where the inputs are out of order.<jupyter_code>from jqiskit.api import QuantumCircuit
from jqiskit.backend import _format_binary
import numpy as np

def format_vec_as_binary(vec: np.ndarray) -> str:
    """Small helper function to grab the bits out of flattened state."""
    idx = np.where(vec == 1.0)[0][0]
    return _format_binary(idx, int(np.log2(len(vec)))).replace("", " ")[1:]


# Build a simple three bit quantum circuit.
n_qubits = 4
qc = QuantumCircuit(n_qubits)

# Here, we add a swap gate that swaps bits 0 and 3, conditioned on the
# qubit in position 1. Note that in this circuit, bit 2 should never change.
c = 1
p = 3
q = 0
qc.cswap(c, p, q)

print('Logic Table for the CSWAP function.')
print('')
print('The control bit is designated by the \'c\' ')
print('The two bits that might be swapped are \'p\' and \'q\'.')
print('')
print('in      | out')
print('q c   p | q c   p')
print('0 1 2 3 | 0 1 2 3')
print('-----------------')
for idx in range(2**n_qubits):
    state = np.zeros((2**n_qubits,))
    state[idx] = 1
    before = format_vec_as_binary(state)
    after = format_vec_as_binary(qc.measure(initial_state=state)[1])
    
    # Highlight the differences.
    arrow = '<------' if before != after else ''
    print(before + '| ' + after + arrow)<jupyter_output>Logic Table for the CSWAP function.

The control bit is designated by the 'c' 
The two bits that might be swapped are 'p' and 'q'.

in      | out
q c   p | q c   p
0 1 2 3 | 0 1 2 3
-----------------
0 0 0 0 | 0 0 0 0 
0 0 0 1 | 0 0 0 1 
0 0 1 0 | 0 0 1 0 
0 0 1 1 | 0 0 1 1 
0 1 0 0 | 0 1 0 0 
0 1 0 1 | 1 1 0 0 <------
0 1 1 0 | 0 1 1 0 
0 1 1 1 | 1 1 1 0 <------
1 0 0 0 | 1 0 0 0 
1 0 0 1 | 1 0 0 1 
1 0 1 0 | 1 0 1 0 
1 0 1 1 | 1 0 1 1 
1 1 0 0 | 0 1 0 1 <------
1 1 0 1 | 1 1 0 1 
1 1 1 0 | 0 1 1 1 <------
1 1 1 1 | 1 1 1 1
{'fraction_non_alphanumeric': 0.1333654309099663, 'fraction_numerical': 0.07799711121810303, 'mean_word_length': 2.522033898305085, 'pattern_counts': {'":': 0, '<': 9, '<?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': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '655726', 'license': 'MIT', 'n_tokens_mistral': 902, 'n_tokens_neox': 746, 'n_words': 359, 'path': 'notebooks/GateExample.ipynb', 'repo_name': 'juicedatom/jqiskit', 'size': '2077'}