<jupyter_start><jupyter_text>Hello Many Worlds - Creating Bell States and Cat States on IonQ Quantum Computer  SetupFirst, get an API key from IonQ. This will be used by the IonQ provider inside Qiskit to submit circuits to the IonQ platform.After securing an API key, install the qiskit-ionq provider at https://github.com/Qiskit-Partners/qiskit-ionq/ (Optional) Extra DependenciesSome examples use additional Python dependencies; please make sure to `pip install` them as needed.Dependencies:* `matplotlib`: To run `qiskit.visualization.plot_histogram`.**NOTE**: The provider expects an API key to be supplied via the `token` keyword argument to its constructor. If no token is directly provided, the provider will check for one in the `QISKIT_IONQ_API_TOKEN` environment variable.Now that the Python package has been installed, you can import and instantiate the provider:<jupyter_code>#import Aer here, before calling qiskit_ionq_provider
from qiskit import Aer

from qiskit_ionq import IonQProvider 

#Call provider and set token value
provider = IonQProvider(token='My token')<jupyter_output>/home/sjohri/.local/lib/python3.6/site-packages/qiskit/__init__.py:67: DeprecationWarning: Using Qiskit with Python 3.6 is deprecated as of the 0.17.0 release. Support for running Qiskit with Python 3.6 will be removed in a future release.
  "future release.", DeprecationWarning)<jupyter_text>The `provider` instance can now be used to create and submit circuits to IonQ. Backend TypesThe IonQ provider supports two backend types:* `ionq_simulator`: IonQ's simulator backend.* `ionq_qpu`: IonQ's QPU backend.To view all current backend types, use the `.backends` property on the provider instance:<jupyter_code>provider.backends()<jupyter_output><empty_output><jupyter_text>Example - Bell StateFor our first example, let's prepare a standard Bell state using Qiskit.<jupyter_code>from qiskit import QuantumCircuit

# Create a bell state circuit.
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

# Show the circuit:
qc.draw()<jupyter_output><empty_output><jupyter_text>Now run the circuit using IonQ's simulator backend:<jupyter_code>from qiskit.providers.jobstatus import JobStatus

# Get an IonQ simulator backend to run circuits on:
backend = provider.get_backend("ionq_simulator")

# Then run the circuit:
job = backend.run(qc, shots=1000)

#save job_id
job_id_bell = job.job_id()

# Fetch the result:
result = job.result()<jupyter_output><empty_output><jupyter_text>Last but not least, use Qiskit's built-in tools to render the results as a histogram:<jupyter_code>from qiskit.visualization import plot_histogram

plot_histogram(result.get_counts())
# Next get an IonQ hardware backend to run circuits on:
qpu_backend = provider.get_backend("ionq_qpu")

# Then run the circuit:
qpu_job_bell = qpu_backend.run(qc)

#Store job id
job_id_bell = qpu_job_bell.job_id()<jupyter_output><empty_output><jupyter_text>The job will queue, and results will arrive once it's executed!<jupyter_code>#Check if job is done
if qpu_job_bell.status() is JobStatus.DONE:
    
    print("Job status is DONE")
    
    # Fetch the result:
    qpu_result_bell = qpu_job_bell.result()
   
else:
    print("Job status is ", qpu_job_bell.status() )
#If Job is finished, plot and validate results:
plot_histogram(qpu_result_bell.get_counts())<jupyter_output><empty_output><jupyter_text>Job HistoryProvider backends can also be used to retrieve previously run jobs:<jupyter_code># Retrieve a previously executed job:
old_job = backend.retrieve_job(job_id_bell)

# Then render the old job results:
old_result = old_job.result()
plot_histogram(old_result.get_counts())<jupyter_output><empty_output><jupyter_text>Example - Cat StateNext let's generalize this to several qubits, also called a `cat state`<jupyter_code>n=4
qc_cat = QuantumCircuit(n, n)
qc_cat.h(0)
for i in range(1,n):
    qc_cat.cx(0, i)

qc_cat.measure(range(n), range(n))

# Show the circuit:
qc_cat.draw()
#Run the circuit on the simulator and plot the results
job_cat = backend.run(qc_cat)

#save job_id
job_id_cat = job_cat.job_id()

# Fetch the result:
result_cat = job_cat.result()

plot_histogram(result_cat.get_counts())

# Then run the circuit on the hardware:
qpu_job_cat = qpu_backend.run(qc_cat)

# save job id
qpu_job_id_cat = qpu_job_cat.job_id()


#Check if job is done
if qpu_job_cat.status() is JobStatus.DONE:
    
    print("Job status is DONE")
    
    # Fetch the result:
    qpu_result_cat = qpu_job_cat.result()
   
else:
    print("Job status is ", qpu_job_cat.status() )
#If Job is finished, plot and validate results:
plot_histogram(qpu_result_cat.get_counts())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08822901089510789, 'fraction_numerical': 0.00619525742362743, 'mean_word_length': 5.669515669515669, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '600637', 'license': 'MIT', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1542, 'n_words': 488, 'path': 'bell_cat_states.ipynb', 'repo_name': 'ionq/skku', 'size': '4681'}