Skip to content

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

@ValentinS4t1qbit

Description

@ValentinS4t1qbit

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:

  • upload a gif in the docs folder on the repo
  • alongside a simple text or rst file describing how you did it (don't worry about the README file, leave it alone). Mention the tools / website / techniques and the text used.

Here is what we want to see in that gif:

  • a sequence of code snippets (provided below) gradually typed on screen, accompanied with the output
  • try to keep the size of the text consistent across snippets.

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)

Metadata

Metadata

Labels

documentationImprovements or additions to documentationgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions