Experimental
Helpers outside of the stable API. They may change or be removed in any release.
Computes measurement probabilities for a given state.
Uses joint decomposition [0, n] where: - compiled_scalar_graphs[0]: normalization (0 outputs plugged) - compiled_scalar_graphs[1]: full joint probability (all outputs plugged)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit | Circuit | The quantum circuit to compile. | required |
sample_detectors | bool | If True, compute detector/observable probabilities. | False |
strategy | SamplingStrategy | Stabilizer rank decomposition strategy ("cat5", "bss", "cutting"); "active_statevector" cannot compute probabilities. | 'cat5' |
seed | int | None | Random seed. If None, a random seed is generated. Results are only deterministic for a fixed batch size, the same versions of Tsim and its dependencies (such as NumPy and JAX) and the same backend (CPU or GPU). | None |
Source code in src/tsim/sampler.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
__repr__
__repr__() -> str
Return a string representation with compilation statistics.
Source code in src/tsim/sampler.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
probability_of
probability_of(
state: ndarray, *, batch_size: int
) -> np.ndarray
Compute probabilities for a batch of error samples given a measurement state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | ndarray | The measurement outcome state to compute probability for. | required |
batch_size | int | Number of error samples to use for estimation. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Array of probabilities P(state | error_sample) for each error sample. |
Source code in src/tsim/sampler.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | |
Transversal encoder for the [[7,1,3]] Steane code.
Source code in src/tsim/utils/encoder.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
diagram
diagram(**kwargs)
Return a timeline-svg diagram of the encoded circuit.
Source code in src/tsim/utils/encoder.py
167 168 169 | |
encode_transversally
encode_transversally(program_text: str) -> None
Encode a program transversally by replacing physicalgates with transversal gates.
Transform a program on m qubits into a program on n * m qubits (consisting of n code blocks).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_text | str | The program to encode transversally. | required |
Source code in src/tsim/utils/encoder.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
encoding_flow_generators
encoding_flow_generators()
Return the Pauli flow generators for the encoding circuit.
Source code in src/tsim/utils/encoder.py
171 172 173 174 | |
initialize
initialize(
program_text: str,
encoding_program_text: str | None = None,
) -> None
Initialize state preparation and apply encoding circuit.
Apply the state preparation program for k qubits, then apply an encoding circuit to encode the state into n qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_text | str | The state preparation program for k qubits. Generally, this should be a simple program that prepares each of the k qubits in a single-qubit state. | required |
encoding_program_text | optional | An encoding circuit for a single logical qubit. This should encode a single logical qubit at input | None |
Source code in src/tsim/utils/encoder.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Transversal encoder for the [[17,1,5]] 2D color code.
Source code in src/tsim/utils/encoder.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
diagram
diagram(**kwargs)
Return a timeline-svg diagram of the encoded circuit.
Source code in src/tsim/utils/encoder.py
167 168 169 | |
encode_transversally
encode_transversally(program_text: str) -> None
Encode a program transversally by replacing physicalgates with transversal gates.
Transform a program on m qubits into a program on n * m qubits (consisting of n code blocks).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_text | str | The program to encode transversally. | required |
Source code in src/tsim/utils/encoder.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
encoding_flow_generators
encoding_flow_generators()
Return the Pauli flow generators for the encoding circuit.
Source code in src/tsim/utils/encoder.py
171 172 173 174 | |
initialize
initialize(
program_text: str,
encoding_program_text: str | None = None,
) -> None
Initialize state preparation and apply encoding circuit.
Apply the state preparation program for k qubits, then apply an encoding circuit to encode the state into n qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_text | str | The state preparation program for k qubits. Generally, this should be a simple program that prepares each of the k qubits in a single-qubit state. | required |
encoding_program_text | optional | An encoding circuit for a single logical qubit. This should encode a single logical qubit at input | None |
Source code in src/tsim/utils/encoder.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |