question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot print Circuit ascii diagram

See original GitHub issue

Hi,

I created a basic circuit and tried to print it to console. It hit me with the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-5: ordinal not
in range(128)

My code is as follows:

import cirq

# Build a model using Circuits
circuit = cirq.Circuit()

# Create Qubits
(q0, q1) = cirq.LineQubit.range(2)

# Add Qubits to Circuit model using logic gates
circuit.append([cirq.H(q0), cirq.CNOT(q0, q1)])

# Measure the final values of the Qubits
circuit.append([cirq.measure(q0), cirq.measure(q1)])

# Visualising the Circuit
print (circuit)

Can someone tell me how I can fix this and visualise my circuit? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Strilanccommented, Mar 3, 2019

This is likely a problem with your python environment’s configuration, e.g. the default text encoding is not set to UTF8.

Are you on a windows machine? Are you using python 2 or python 3? If you try print(circuit.to_text_diagram(use_unicode_characters=False)) does that work as a workaround?

0reactions
sloveyscommented, Jun 28, 2019

We could have a global switch to set it, like an equivalent of np.printoptions, but I dislike that kind of configuration because it’s so easy for code in one file to break code in a file somewhere else.

That’s why you set global switches in a if __name__ == "__main__": block to prevented from changing setting if that file is later imported. But ya, it would be so much easier if standards where… standard.

Edit: I’ve updated python from 3.5 to 3.7 and that fixed the problem for me. I heard updating to 3.6 also works but I haven’t checked myself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASCII circuit diagrams | Electronics Forums
I've looked at a few of these, posted in this group, and I'm competely unable to understand any of it. Is there some...
Read more >
In C++, how to print ASCII art to the console?
command line interface - In C++, how to print ASCII art to the console? - Stack Overflow. Stack Overflow for Teams – Start...
Read more >
ASCIIFlow
Infinite ASCII diagrams, save to Google Drive, resize, freeform draw, and export straight to text/html.
Read more >
Your Turn: Print ASCII Chart
Open the terminal. Verify that it prints all the printable characters, starting from space (which actually won't visibly display) to ~.
Read more >
ASCII-Art : 5 Steps (with Pictures)
1. Choose any image from the internet or from your desktop. It should have no background and not too much little parts. Comic-figures...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found