goodchemistryco / Tangelo

A python package for exploring end-to-end chemistry workflows on quantum computers and simulators.
https://goodchemistryco.github.io/Tangelo/
Other
99 stars 27 forks source link

Neat gif with simple Tangelo code snippets to show people how easy it is to use the software #389

Open ValentinS4t1qbit opened 1 month ago

ValentinS4t1qbit commented 1 month ago

A picture (or a gif !) is worth a thousand words. Wouldn't it be nice if people could just see in practice how Tangelo works on simple tasks without having to dig into documentation, tutorials, etc ? They'd just "get it" and be able to decide if that's relevant to them or not.

Well, a gif in our README would be pretty neat. To win this:

Here is what we want to see in that gif:

Snippets and their results:



Snippet 1

# Run circuits on your favorite simulators

from tangelo.linq import Gate, Circuit, get_backend

c = Circuit([Gate('H', 0), Gate('X', 1)])
sim = get_backend("qiskit")  # or "qulacs", "cirq" ...
bitstring_frequencies, statevector = sim.simulate(c, return_statevector=True)

print(f'{bitstring_frequencies=} \n{statevector=}')
Screenshot 2024-05-28 at 4 27 00 PM



Snippet 2

# Use all the projects in the quantum ecosystem !

from tangelo.linq import translate_circuit

c_qiskit = translate_circuit(c, target="qiskit")  # to or from "qiskit", "pennylane", "cirq", ...
c_qiskit.draw(output='mpl', style={'backgroundcolor': '#EEEEEE'}) # it's a qiskit object !

(this is not the actual output, just run the above code with qiskit and pylatexenc in your environment)

Screenshot 2024-05-28 at 4 30 09 PM



Snippet 3

# Compute ground state of a molecule with VQE
# Check out the computational resources needed

from tangelo import SecondQuantizedMolecule
from tangelo.algorithms import VQESolver

xyz_H2 = [("H", (0., 0., 0.)), ("H", (0., 0., 0.7414))]
mol = SecondQuantizedMolecule(xyz_H2, q=0, spin=0, basis="sto-3g")

vqe_options = {"molecule": mol}  # Plenty options for qubit mappings etc
vqe_solver = VQESolver(vqe_options)
vqe_solver.build()
opt_energy = vqe_solver.simulate()

print(opt_energy)
print(vqe_solver.get_resources())
Screenshot 2024-05-28 at 4 42 35 PM



Snippet 4

from tangelo.linq.qpu_connection import IBMConnection

conn = IBMConnection(ibm_quantum_token='your_ibm_token')
job_id = conn.job_submit('sampler', 'ibmq_qasm_simulator', n_shots=100, circuit)
job_res = conn.job_results(job_id)  # Your job on IBM Quantum eventually completes

(no output needed)