1
$\begingroup$

Given an arbitrary TensorCircuit, is there a convient way to get a plot of the circuit?

$\endgroup$

2 Answers 2

2
$\begingroup$

Suppose c is the circuit object, c.tex() will return the latex string using quantikz package, and c.tex(standalone=True) returns the full latex document that can be compiled.

Besides, assuming qiskit is also installed, c.draw() can plot the circuit via first transforming the circuit into qiskit QuantumCircuit. And all options for qiskit can also be given in c.draw(**options)

$\endgroup$
1
$\begingroup$

@Simon's answer is absolutely correct. I just want to add a few details.

When TensorCircuit transforms the circuit into Qiskit's QuantumCircuit, non-unitary operations are transformed into generic unitaries. So, the circuit plot will not be accurate. As a workaround you can add a name of each non-unitary operation, and style them with custom colors as follows:

import tensorcircuit as tc
c = tc.Circuit(2)
c.H(0)
c.CNOT(0,1)
c.crx(1, 0, theta=0.2)

# Add a non-unitary operation:
c.thermalrelaxation(
    0,
    t1=300,
    t2=400,
    time=1000,
    method="ByChoi",
    excitedstatepopulation=0,
    name="Thermal Relaxation" # <== 
)

# Style non-unitary operations with custom colors
style = {
    'displaycolor': {
        'Thermal Relaxation': ['#ff7675', '#000000'],
    }
}

c.draw(output = 'mpl', style = style)

The result will look like:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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