2
$\begingroup$

Here's the code I'm working on:

!pip install pylatexenc
!pip install pillow

qc = QuantumCircuit(2)
qc.x(0)
qc.cz(0,1)
qc.x(0)
qc.draw('latex')

However there's an error:

FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex': 'pdflatex'

What should I do to make it work? Thanks!!

$\endgroup$
2
  • $\begingroup$ Did you try to restart the kernel once the installations were done? Usually in Jupiter Notebook it does the trick :) $\endgroup$
    – Lena
    Jan 14 at 8:53
  • $\begingroup$ @ Thanks for the comment! Yes I did:) $\endgroup$
    – ZR-
    Jan 14 at 20:20
2
$\begingroup$

It seems like you forgot to install a $\LaTeX$ processor.

To solve the issue, install any $\LaTeX$ distribution. Below are the two main ones that can be installed both on Windows and Linux:

$\endgroup$
1
$\begingroup$

If you want to output the circuit in latex format, you can set the output = 'latex' within the draw function of Qiskit.

For instance, suppose I want to plot the following circuit in latex:

           ░       ░      
q_0: ──■───░───■───░───■──
     ┌─┴─┐ ░ ┌─┴─┐ ░ ┌─┴─┐
q_1: ┤ X ├─░─┤ X ├─░─┤ X ├
     └───┘ ░ └───┘ ░ └───┘
c: 2/═════════════════════

I can do it as follows:

from qiskit import QuantumCircuit,QuantumRegister
import matplotlib.pyplot as plt
qreg_q = QuantumRegister(2, 'q')
creg_c = ClassicalRegister(2, 'c')
circ = QuantumCircuit(qreg_q, creg_c)
circ.cx(0,1)
circ.barrier(range(2))
circ.cx(0,1)
circ.barrier(range(2))
circ.cx(0,1)
circ.draw( style={'name': 'bw'}, output = 'latex', plot_barriers= True, initial_state = True, scale = 1)

The output would be:

enter image description here


You can look into this documentation here for more detail.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.