pytket#
pytket
is a python module for interfacing with tket, a quantum computing toolkit and optimising compiler developed by Quantinuum. We currently support circuits and device architectures from
numerous providers, allowing the
tket tools to be used in conjunction with projects on their platforms.
pytket
is available for Python 3.9, 3.10 and 3.11, on Linux, MacOS and
Windows. To install, run
pip install pytket
Note
On M1-based Macs running in native (arm64) mode, this command may fail
because of an issue installing scipy
. To fix this:
Install brew (if you haven’t already);
brew install openblas
;pip install -U pip wheel
;OPENBLAS="$(brew --prefix openblas)" pip install scipy
;pip install pytket
.
If you have issues installing pytket
please visit the installation troubleshooting page.
To use pytket
, you can simply import the appropriate modules into your python code or in an interactive Python notebook. We can build circuits directly using the pytket
interface by creating a blank circuit and adding gates in the order we want to apply them.
from pytket import Circuit
circ = Circuit(2,2) # define a circuit with 2 qubits and 2 bits
circ.H(0) # add a Hadamard gate to qubit 0
circ.Rz(0.25, 0) # add an Rz gate of angle 0.25*pi to qubit 0
circ.CX(1,0) # add a CX gate with control qubit 1 and target qubit 0
circ.measure_all() # measure qubits 0 and 1, recording the results in bits 0 and 1
Some of the extension modules define Backend
s, allowing the circuits to be run on simulators or real quantum hardware. For example, pytket-qiskit
grants access to the AerBackend
simulator which can sample from measurements.
from pytket.extensions.qiskit import AerBackend
backend = AerBackend() # connect to the backend
compiled_circ = backend.get_compiled_circuit(circ) # compile the circuit to satisfy the backend's requirements
handle = backend.process_circuit(compiled_circ, 100) # submit the job to run the circuit 100 times
counts = backend.get_result(handle).get_counts() # retrieve and summarise the results
print(counts)
This prints out a summary of readouts (the final values of the classical bits) and their frequencies.
{(0, 0): 49, (1, 0): 51}
See the Getting Started page for a basic tutorial on using
pytket
. To get more in depth on features, see the examples. See the pytket user manual for an extensive introduction to pytket
functionality and how to use it.
Extensions#
To use pytket in conjunction with other platforms you must download an
additional separate module for each. Each one of these adds either some new
methods to the pytket
package to convert between the circuit
representations, or some new backends to submit circuits to within pytket
.
Extensions are separate python packages can be installed using pip
. The installation command is pip install pytket-X
where X
is the name of the extension.
To install the pytket-quantinuum
package use the following command.
pip install pytket-quantinuum
The extensions supported by tket are described here.
How to cite#
If you wish to cite tket in any academic publications, we generally recommend citing our software overview paper for most cases.
If your work is on the topic of specific compilation tasks, it may be more appropriate to cite one of our other papers:
“On the qubit routing problem” for qubit placement (aka allocation, mapping) and routing (aka swap network insertion, connectivity solving).
“Phase Gadget Synthesis for Shallow Circuits” for representing exponentiated Pauli operators in the ZX calculus and their circuit decompositions.
“A Generic Compilation Strategy for the Unitary Coupled Cluster Ansatz” for sequencing of terms in Trotterisation and Pauli diagonalisation.
We are also keen for others to benchmark their compilation techniques against us. We recommend checking our benchmark repository for examples on how to run basic benchmarks with the latest version of pytket
. Please list the release version of pytket
with any benchmarks you give, and feel free to get in touch for any assistance needed in setting up fair and representative tests.
User Support#
If you have problems with the use of tket or you think that you have found a bug there are several ways to contact us:
We have a slack channel for community discussion and support. You can join by following this link
You can join the tket-users mailing list. If you have questions or ideas and wishes for new features you can send an email to the list and ask for help. You can also join the list to get the newest information and get in contact with other users of tket.
Write an email to tket-support@cambridgequantum.com and ask for help with your problem.
You can write a bug report on github with details of the problem and we will pick that up. You can also have a look on that page so see if your problem has already been reported by someone else.
We are really thankful for all help to fix bugs in tket. Usually you will get an answer from someone in the development team of tket soon.
LICENCE#
Licensed under the Apache 2 License.
More Documentation:
API Reference:
- pytket.backends
- pytket.circuit
- pytket.circuit.Circuit
- pytket.circuit.OpType
- pytket.circuit.logic_exp
- pytket.circuit.display
fresh_symbol()
Op
Command
UnitType
UnitID
Qubit
Bit
Node
QubitRegister
BitRegister
BasisOrder
CircBox
Unitary1qBox
Unitary2qBox
Unitary3qBox
ExpBox
PauliExpBox
ToffoliBox
QControlBox
CustomGateDef
CustomGate
Conditional
ClassicalExpBox
PhasePolyBox
ProjectorAssertionBox
StabiliserAssertionBox
WASMOp
MultiBitOp
SetBitsOp
ClassicalEvalOp
ClassicalOp
CopyBitsOp
RangePredicateOp
MultiplexorBox
MultiplexedRotationBox
MultiplexedU2Box
MultiplexedTensoredU2Box
StatePreparationBox
DiagonalBox
- pytket.pauli
- pytket.passes
BasePass
CNotSynthType
RepeatPass
RepeatUntilSatisfiedPass
RepeatWithMetricPass
SafetyMode
SequencePass
AASRouting()
CXMappingPass()
CliffordSimp()
CnXPairwiseDecomposition()
CommuteThroughMultis()
ComposePhasePolyBoxes()
ContextSimp()
CustomPass()
CustomRoutingPass()
DecomposeArbitrarilyControlledGates()
DecomposeBoxes()
DecomposeClassicalExp()
DecomposeMultiQubitsCX()
DecomposeSingleQubitsTK1()
DecomposeSwapsToCXs()
DecomposeSwapsToCircuit()
DecomposeTK2()
DefaultMappingPass()
DelayMeasures()
EulerAngleReduction()
FlattenRegisters()
FlattenRelabelRegistersPass()
FullMappingPass()
FullPeepholeOptimise()
GlobalisePhasedX()
GuidedPauliSimp()
KAKDecomposition()
NaivePlacementPass()
NormaliseTK2()
OptimisePhaseGadgets()
PauliSimp()
PauliSquash()
PeepholeOptimise2Q()
PlacementPass()
RebaseCustom()
RebaseTket()
RemoveBarriers()
RemoveDiscarded()
RemoveImplicitQubitPermutation()
RemoveRedundancies()
RenameQubitsPass()
RoundAngles()
RoutingPass()
SimplifyInitial()
SimplifyMeasured()
SquashCustom()
SquashRzPhasedX()
SquashTK1()
SynthesiseHQS()
SynthesiseOQC()
SynthesiseTK()
SynthesiseTket()
SynthesiseUMD()
ThreeQubitSquash()
ZXGraphlikeOptimisation()
ZZPhaseToRz()
- pytket.passes.script
- pytket.passes.auto_rebase
- pytket.predicates
CliffordCircuitPredicate
CommutableMeasuresPredicate
CompilationUnit
ConnectivityPredicate
DefaultRegisterPredicate
DirectednessPredicate
GateSetPredicate
MaxNClRegPredicate
MaxNQubitsPredicate
MaxTwoQubitGatesPredicate
NoBarriersPredicate
NoClassicalBitsPredicate
NoClassicalControlPredicate
NoFastFeedforwardPredicate
NoMidMeasurePredicate
NoSymbolsPredicate
NoWireSwapsPredicate
NormalisedTK2Predicate
PlacementPredicate
Predicate
UserDefinedPredicate
- pytket.partition
- pytket.qasm
- pytket.quipper
- pytket.architecture
- pytket.placement
- pytket.mapping
- pytket.tableau
- pytket.transform
- pytket.tailoring
- pytket.wasm
- pytket.zx
- pytket.utils
append_pauli_measurement()
compare_statevectors()
compare_unitaries()
counts_from_shot_table()
expectation_from_counts()
expectation_from_shots()
gen_term_sequence_circuit()
get_operator_expectation_value()
get_pauli_expectation_value()
permute_basis_indexing()
permute_qubits_in_statevector()
permute_rows_cols_in_unitary()
prepare_circuit()
probs_from_counts()
probs_from_state()
readout_counts()
OutcomeArray
QubitPauliOperator
Graph
- pytket.utils.distribution
- pytket.utils.spam
- pytket.utils.symbolic
- pytket.logging
- pytket.config