1. tket-demo
  2. tket-compile.py
1import strangeworks
2#import strangeworks.qiskit to use formatted result data and access visualizations
3import strangeworks.qiskit
4import qiskit
5
6from pytket import Circuit, Qubit
7from pytket.qasm import circuit_to_qasm, circuit_from_qasm
8from pytket.predicates import CompilationUnit
9from pytket.passes import DecomposeMultiQubitsIBM
10
11
12# Here is my pytket circuit
13c = Circuit(3)
14c.CRz(0.5, 0, 1)
15c.T(2)
16c.CSWAP(2, 0, 1)
17c.measure_all()
18
19# Let's show those gates
20print(c.get_commands())
21
22
23# But we need that in qasm!
24# No problem, tket's got you!
25
26pass1 = DecomposeMultiQubitsIBM()
27cu = CompilationUnit(c)
28pass1.apply(cu)
29circ1 = cu.circuit
30
31# We can even write that to a file
32
33qasmfile = 'c2.qasm'
34circuit_to_qasm(circ1, qasmfile)
35
36
37# Going to use qiskit now to draw our circuit and run a simulation
38
39qc2 = qiskit.QuantumCircuit.from_qasm_file(qasmfile)
40
41
42# Don't forget to use the strangeworks backend for access to visualizations
43qiskit_backend = strangeworks.qiskit.get_backend("qasm_simulator")
44job = qiskit.execute([qc2], qiskit_backend, shots=100)