tensorcircuit.zx.stabilizertcircuit

Stabilizer+T Circuit class using ZX-calculus and JAX.

class tensorcircuit.zx.stabilizertcircuit.StabilizerTCircuit(nqubits: int, seed: int | None = None, strategy: Literal['cat5', 'bss', 'cutting'] = 'cat5')[source]

Bases: AbstractCircuit

__init__(nqubits: int, seed: int | None = None, strategy: Literal['cat5', 'bss', 'cutting'] = 'cat5')[source]

Initialize a StabilizerTCircuit.

Parameters:
  • nqubits (int) – Number of qubits in the circuit.

  • seed (Optional[int], optional) – Random seed for sampling, defaults to None.

  • strategy (DecompositionStrategy, optional) – Decomposition strategy for T gates, defaults to “cat5”.

amplitude(state: Array | Sequence[int] | str) Array[source]

Calculate the complex amplitude <state|psi> for a noiseless circuit. Fails if the circuit contains non-unitary operations or noise.

Parameters:

state (Union[jax.Array, Sequence[int], str]) – The target bitstring.

Returns:

The complex amplitude.

Return type:

jax.Array

append(c: AbstractCircuit, indices: List[int] | None = None) AbstractCircuit

append circuit c before

Example:

>>> c1 = tc.Circuit(2)
>>> c1.H(0)
>>> c1.H(1)
>>> c2 = tc.Circuit(2)
>>> c2.cnot(0, 1)
>>> c1.append(c2)
<tensorcircuit.circuit.Circuit object at 0x7f8402968970>
>>> c1.draw()
    ┌───┐
q_0:┤ H ├──■──
    ├───┤┌─┴─┐
q_1:┤ H ├┤ X ├
    └───┘└───┘
Parameters:
  • c (BaseCircuit) – The other circuit to be appended

  • indices (Optional[List[int]], optional) – the qubit indices to which c is appended on. Defaults to None, which means plain concatenation.

Returns:

The composed circuit

Return type:

BaseCircuit

append_from_qir(qir: List[Dict[str, Any]], allow_channel: bool = False) None

Apply the ciurict in form of quantum intermediate representation after the current cirucit.

Example:

>>> c = tc.Circuit(3)
>>> c.H(0)
>>> c.to_qir()
[{'gatef': h, 'gate': Gate(...), 'index': (0,), 'name': 'h', 'split': None, 'mpo': False}]
>>> c2 = tc.Circuit(3)
>>> c2.CNOT(0, 1)
>>> c2.to_qir()
[{'gatef': cnot, 'gate': Gate(...), 'index': (0, 1), 'name': 'cnot', 'split': None, 'mpo': False}]
>>> c.append_from_qir(c2.to_qir())
>>> c.to_qir()
[{'gatef': h, 'gate': Gate(...), 'index': (0,), 'name': 'h', 'split': None, 'mpo': False},
 {'gatef': cnot, 'gate': Gate(...), 'index': (0, 1), 'name': 'cnot', 'split': None, 'mpo': False}]
Parameters:
  • qir (List[Dict[str, Any]]) – The quantum intermediate representation.

  • allow_channel (bool, optional) – whether to allow channel in the qir, defaults to False

apply(gate: Any, *index: int, **kwargs: Any) None[source]
apply_general_gate(gate: Any, *index: int, name: str | None = None, split: Dict[str, Any] | None = None, mpo: bool = False, diagonal: bool = False, ir_dict: Dict[str, Any] | None = None) None[source]

An implementation of this method should also append gate directionary to self._qir

static apply_general_gate_delayed(gatef: Callable[[], Gate], name: str | None = None, mpo: bool = False) Callable[[...], None]
static apply_general_variable_gate_delayed(gatef: Callable[[...], Any], name: str | None = None, mpo: bool = False, diagonal: bool = False) Callable[[...], None]
barrier_instruction(*index: List[int]) None

add a barrier instruction flag, no effect on numerical simulation

Parameters:

index (List[int]) – the corresponding qubits

circuit_param: Dict[str, Any]
cnot(c: int, t: int) None[source]
cond_measure(index: int) Any

Measurement on z basis at index qubit based on quantum amplitude (not post-selection). The highlight is that this method can return the measured result as a int Tensor and thus maintained a jittable pipeline.

Example:

>>> c = tc.Circuit(2)
>>> c.H(0)
>>> r = c.cond_measurement(0)
>>> c.conditional_gate(r, [tc.gates.i(), tc.gates.x()], 1)
>>> c.expectation([tc.gates.z(), [0]]), c.expectation([tc.gates.z(), [1]])
# two possible outputs: (1, 1) or (-1, -1)

Note

In terms of DMCircuit, this method returns nothing and the density matrix after this method is kept in mixed state without knowing the measuremet resuslts

Parameters:

index (int) – the qubit for the z-basis measurement

Returns:

0 or 1 for z measurement on up and down freedom

Return type:

Tensor

cond_measurement(index: int) Any

Measurement on z basis at index qubit based on quantum amplitude (not post-selection). The highlight is that this method can return the measured result as a int Tensor and thus maintained a jittable pipeline.

Example:

>>> c = tc.Circuit(2)
>>> c.H(0)
>>> r = c.cond_measurement(0)
>>> c.conditional_gate(r, [tc.gates.i(), tc.gates.x()], 1)
>>> c.expectation([tc.gates.z(), [0]]), c.expectation([tc.gates.z(), [1]])
# two possible outputs: (1, 1) or (-1, -1)

Note

In terms of DMCircuit, this method returns nothing and the density matrix after this method is kept in mixed state without knowing the measuremet resuslts

Parameters:

index (int) – the qubit for the z-basis measurement

Returns:

0 or 1 for z measurement on up and down freedom

Return type:

Tensor

conditional_gate(which: Any, kraus: Sequence[Gate], *index: int) None

Apply which-th gate from kraus list, i.e. apply kraus[which]

Parameters:
  • which (Tensor) – Tensor of shape [] and dtype int

  • kraus (Sequence[Gate]) – A list of gate in the form of tc.gate or Tensor

  • index (int) – the qubit lines the gate applied on

copy() AbstractCircuit
cx(c: int, t: int) None[source]
cz(c: int, t: int) None[source]
depolarizing(q: int, px: float | None = None, py: float | None = None, pz: float | None = None) None[source]
depolarizing2(q1: int, q2: int, p: float) None[source]
depolarizing2_instruction(q1: int, q2: int, p: float) None[source]

add a 2-qubit depolarizing instruction flag, no effect on numerical simulation

depolarizing_instruction(q: int, px: float | None = None, py: float | None = None, pz: float | None = None) None[source]

add a depolarizing instruction flag, no effect on numerical simulation

detector_instruction(lookback_indices: list[int], coords: list[float] | None = None) None[source]

add a detector instruction flag, no effect on numerical simulation

Parameters:

lookback_indices (Sequence[int]) – the corresponding measurement record indices

diaggates = ['diagonal', 'rzm', 'cmz']
draw(**kws: Any) Any

Visualise the circuit. This method recevies the keywords as same as qiskit.circuit.QuantumCircuit.draw. More details can be found here: https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.draw.html. Interesting kws options include: ``idle_wires``(bool)

Example:

>>> c = tc.Circuit(3)
>>> c.H(1)
>>> c.X(2)
>>> c.CNOT(0, 1)
>>> c.draw(output='text')
q_0: ───────■──
     ┌───┐┌─┴─┐
q_1: ┤ H ├┤ X ├
     ├───┤└───┘
q_2: ┤ X ├─────
     └───┘
expectation(*ops: Tuple[Node, List[int]], reuse: bool = True, noise_conf: Any | None = None, nmc: int = 1000, status: Any | None = None, **kws: Any) Any
expectation_ps(x: Sequence[int] | None = None, y: Sequence[int] | None = None, z: Sequence[int] | None = None, ps: Sequence[int] | None = None, nmc: int = 1000, **kwargs: Any) Array[source]

Calculate the expectation value <psi|O|psi> for a Pauli string O. Supports noiseless and noisy circuits.

Parameters:
  • x (Optional[Sequence[int]]) – Qubit indices for X operators.

  • y (Optional[Sequence[int]]) – Qubit indices for Y operators.

  • z (Optional[Sequence[int]]) – Qubit indices for Z operators.

  • ps (Optional[Sequence[int]]) – Pauli string as a sequence of integers (0:I, 1:X, 2:Y, 3:Z).

  • nmc (int) – Number of Monte Carlo trajectories for noisy circuits.

Returns:

The expectation value.

Return type:

jax.Array

classmethod from_circuit(circuit: AbstractCircuit, strategy: Literal['cat5', 'bss', 'cutting'] = 'cat5') StabilizerTCircuit[source]

Create a StabilizerTCircuit from an existing TensorCircuit AbstractCircuit.

Parameters:
  • circuit (AbstractCircuit) – The source circuit to convert.

  • strategy (DecompositionStrategy, optional) – Decomposition strategy for T gates, defaults to “cat5”.

Returns:

A new StabilizerTCircuit instance.

Return type:

StabilizerTCircuit

classmethod from_cirq(qc: Any, n: int | None = None, inputs: List[float] | None = None, circuit_params: Dict[str, Any] | None = None) AbstractCircuit

Import Cirq Circuit object as a tc.Circuit object.

Example:

>>> import cirq
>>> c = cirq.Circuit()
>>> q = cirq.LineQubit.range(3)
>>> c.append(cirq.H(q[0]))
>>> c.append(cirq.CNOT(q[0], q[1]))
>>> tc_c = tc.Circuit.from_cirq(c)
Parameters:
  • qc (cirq.Circuit) – Cirq Circuit object

  • n (int) – The number of qubits for the circuit

  • inputs (Optional[List[float]], optional) – possible input wavefunction for tc.Circuit, defaults to None

  • circuit_params (Optional[Dict[str, Any]]) – kwargs given in Circuit.__init__ construction function, default to None.

Returns:

The same circuit but as tensorcircuit object

Return type:

Circuit

classmethod from_json(jsonstr: str, circuit_params: Dict[str, Any] | None = None) AbstractCircuit

load json str as a Circuit

Parameters:
  • jsonstr (str) – _description_

  • circuit_params (Optional[Dict[str, Any]], optional) – Extra circuit parameters in the format of __init__, defaults to None

Returns:

_description_

Return type:

AbstractCircuit

classmethod from_json_file(file: str, circuit_params: Dict[str, Any] | None = None) AbstractCircuit

load json file and convert it to a circuit

Parameters:
  • file (str) – filename

  • circuit_params (Optional[Dict[str, Any]], optional) – _description_, defaults to None

Returns:

_description_

Return type:

AbstractCircuit

classmethod from_openqasm(qasmstr: str, circuit_params: Dict[str, Any] | None = None, keep_measure_order: bool = False) AbstractCircuit
classmethod from_openqasm_file(file: str, circuit_params: Dict[str, Any] | None = None, keep_measure_order: bool = False) AbstractCircuit
classmethod from_qir(qir: List[Dict[str, Any]], circuit_params: Dict[str, Any] | None = None, allow_channel: bool = False) AbstractCircuit

Restore the circuit from the quantum intermediate representation.

Example:

>>> c = tc.Circuit(3)
>>> c.H(0)
>>> c.rx(1, theta=tc.array_to_tensor(0.7))
>>> c.exp1(0, 1, unitary=tc.gates._zz_matrix, theta=tc.array_to_tensor(-0.2), split=split)
>>> len(c)
7
>>> c.expectation((tc.gates.z(), [1]))
array(0.764842+0.j, dtype=complex64)
>>> qirs = c.to_qir()
>>>
>>> c = tc.Circuit.from_qir(qirs, circuit_params={"nqubits": 3})
>>> len(c._nodes)
7
>>> c.expectation((tc.gates.z(), [1]))
array(0.764842+0.j, dtype=complex64)
Parameters:
  • qir (List[Dict[str, Any]]) – The quantum intermediate representation of a circuit.

  • circuit_params (Optional[Dict[str, Any]]) – Extra circuit parameters.

Returns:

The circuit have same gates in the qir.

Return type:

Circuit

classmethod from_qiskit(qc: Any, n: int | None = None, inputs: List[float] | None = None, circuit_params: Dict[str, Any] | None = None, binding_params: Sequence[float] | Dict[Any, float] | None = None) AbstractCircuit

Import Qiskit QuantumCircuit object as a tc.Circuit object.

Example:

>>> from qiskit import QuantumCircuit
>>> qisc = QuantumCircuit(3)
>>> qisc.h(2)
>>> qisc.cswap(1, 2, 0)
>>> qisc.swap(0, 1)
>>> c = tc.Circuit.from_qiskit(qisc)
Parameters:
  • qc (QuantumCircuit in Qiskit) – Qiskit Circuit object

  • n (int) – The number of qubits for the circuit

  • inputs (Optional[List[float]], optional) – possible input wavefunction for tc.Circuit, defaults to None

  • circuit_params (Optional[Dict[str, Any]]) – kwargs given in Circuit.__init__ construction function, default to None.

  • binding_params (Optional[Union[Sequence[float], Dict[Any, float]]]) – (variational) parameters for the circuit. Could be either a sequence or dictionary depending on the type of parameters in the Qiskit circuit. For ParameterVectorElement use sequence. For Parameter use dictionary

Returns:

The same circuit but as tensorcircuit object

Return type:

Circuit

classmethod from_qsim_file(file: str, circuit_params: Dict[str, Any] | None = None) AbstractCircuit
classmethod from_stim_circuit(stim_circuit: Any) StabilizerTCircuit[source]

Create a StabilizerTCircuit from a stim.Circuit object.

Parameters:

stim_circuit (Any) – The stim circuit to convert.

Returns:

A new StabilizerTCircuit instance.

Return type:

StabilizerTCircuit

classmethod from_stim_str(stim_str: str) StabilizerTCircuit[source]

Create a StabilizerTCircuit from a stim circuit string.

Parameters:

stim_str (str) – The stim circuit string to parse.

Returns:

A new StabilizerTCircuit instance.

Return type:

StabilizerTCircuit

gate_aliases = [['cnot', 'cx'], ['fredkin', 'cswap'], ['toffoli', 'ccnot'], ['toffoli', 'ccx'], ['any', 'unitary'], ['sd', 'sdg'], ['td', 'tdg']]
gate_count(gate_list: str | Sequence[str] | None = None) int

count the gate number of the circuit

Example:

>>> c = tc.Circuit(3)
>>> c.h(0)
>>> c.multicontrol(0, 1, 2, ctrl=[0, 1], unitary=tc.gates._x_matrix)
>>> c.toffolli(1, 2, 0)
>>> c.gate_count()
3
>>> c.gate_count(["multicontrol", "toffoli"])
2
Parameters:

gate_list (Optional[Sequence[str]], optional) – gate name or gate name list to be counted, defaults to None (counting all gates)

Returns:

the total number of all gates or gates in the gate_list

Return type:

int

gate_count_by_condition(cond_func: Callable[[Dict[str, Any]], bool]) int

count the number of gates that satisfy certain condition

Example:

>>> c = tc.Circuit(3)
>>> c.x(0)
>>> c.h(0)
>>> c.multicontrol(0, 1, 2, ctrl=[0, 1], unitary=tc.gates._x_matrix)
>>> c.gate_count_by_condition(lambda qir: qir["index"] == (0, ))
2
>>> c.gate_count_by_condition(lambda qir: qir["mpo"])
1
Parameters:

cond_func (Callable[[Dict[str, Any]], bool]) – the condition for counting the gate

Returns:

the total number of all gates which satisfy the condition

Return type:

int

gate_summary() Dict[str, int]

return the summary dictionary on gate type - gate count pair

Returns:

the gate count dict by gate type

Return type:

Dict[str, int]

get_positional_logical_mapping() Dict[int, int]

Get positional logical mapping dict based on measure instruction. This function is useful when we only measure part of the qubits in the circuit, to process the count result from partial measurement, we must be aware of the mapping, i.e. for each position in the count bitstring, what is the corresponding qubits (logical) defined on the circuit

Returns:

positional_logical_mapping

Return type:

Dict[int, int]

h(q: int) None[source]
initial_mapping(logical_physical_mapping: Dict[int, int], n: int | None = None, circuit_params: Dict[str, Any] | None = None) AbstractCircuit

generate a new circuit with the qubit mapping given by logical_physical_mapping

Parameters:
  • logical_physical_mapping (Dict[int, int]) – how to map logical qubits to the physical qubits on the new circuit

  • n (Optional[int], optional) – number of qubit of the new circuit, can be different from the original one, defaults to None

  • circuit_params (Optional[Dict[str, Any]], optional) – _description_, defaults to None

Returns:

_description_

Return type:

AbstractCircuit

inputs: Any
inverse(circuit_params: Dict[str, Any] | None = None) AbstractCircuit

inverse the circuit, return a new inversed circuit

EXAMPLE:

>>> c = tc.Circuit(2)
>>> c.H(0)
>>> c.rzz(1, 2, theta=0.8)
>>> c1 = c.inverse()
Parameters:

circuit_params (Optional[Dict[str, Any]], optional) – keywords dict for initialization the new circuit, defaults to None

Returns:

the inversed circuit

Return type:

Circuit

is_mps: bool
measure_instruction(q: int, p: float = 0) None[source]

add a measurement instruction flag, no effect on numerical simulation

Parameters:

index (int) – the corresponding qubits

mpogates = ['multicontrol', 'mpo']
mr_instruction(q: int, p: float = 0) None[source]

add a measure-reset instruction flag, no effect on numerical simulation

Parameters:

q (int) – the corresponding qubit

mrx_instruction(q: int, p: float = 0) None[source]
mry_instruction(q: int, p: float = 0) None[source]
mrz_instruction(q: int, p: float = 0) None[source]
observable_instruction(lookback_indices: list[int], observable_index: int = 0) None[source]
outcome_probability(state: Array, shots: int = 1) Array[source]

Compute the probability of a specific measurement outcome state.

Parameters:
  • state (jax.Array) – The target measurement bitstring.

  • shots (int, optional) – Number of noise realizations to average over, defaults to 1.

Returns:

Probability of the outcome state for each noise realization.

Return type:

jax.Array

pauli(q: int, px: float | None = None, py: float | None = None, pz: float | None = None) None[source]
pauli2_instruction(q1: int, q2: int, **kws: Any) None

add a 2-qubit pauli instruction flag, no effect on numerical simulation

pauli_instruction(q: int, px: float | None = None, py: float | None = None, pz: float | None = None) None[source]

add a pauli instruction flag, no effect on numerical simulation

prepend(c: AbstractCircuit) AbstractCircuit

prepend circuit c before

Parameters:

c (BaseCircuit) – The other circuit to be prepended

Returns:

The composed circuit

Return type:

BaseCircuit

qubit_coords_instruction(qubit: int, coords: list[float]) None[source]
r(q: int, p: float = 0) None[source]
reset_instruction(q: int) None[source]

add a reset instruction flag, no effect on numerical simulation

Parameters:

index (int) – the corresponding qubits

reset_x(q: int) None[source]
reset_y(q: int) None[source]
reset_z(q: int, p: float = 0) None[source]
rx(q: int, theta: float = 0) None[source]
ry(q: int, theta: float = 0) None[source]
rz(q: int, theta: float = 0) None[source]
s(q: int) None[source]
sample_detector() Any

placeholder for sample detector results

sample_detectors(shots: int = 1, separate_observables: bool = False, use_reference: bool = False, seed: int | None = None, batch_size: int = 1000) Array | Tuple[Array, Array][source]

Sample detector and observable outcomes.

Parameters:
  • shots (int, optional) – Number of samples to draw, defaults to 1.

  • separate_objects (bool, optional) – Whether to return detectors and observables separately, defaults to False.

  • use_reference (bool, optional) – Whether to XOR results with a noiseless reference run, defaults to False.

  • seed (Optional[int], optional) – Random seed for this sampling run, defaults to None.

  • batch_size (int, optional) – Number of shots per JIT batch, defaults to 1000.

Returns:

Array of samples or tuple of (detectors, observables) arrays.

Return type:

Union[jax.Array, Tuple[jax.Array, jax.Array]]

sample_measurements(shots: int = 1, seed: int | None = None, batch_size: int = 1000) Array[source]

Sample all measurement outcomes in the circuit.

Parameters:
  • shots (int, optional) – Number of samples to draw, defaults to 1.

  • seed (Optional[int], optional) – Random seed for this sampling run, defaults to None.

  • batch_size (int, optional) – Number of shots per JIT batch, defaults to 1000.

Returns:

Array of measurement samples with shape (shots, num_measurements).

Return type:

jax.Array

sd(q: int) None[source]
sdg(q: int) None[source]
select_gate(which: Any, kraus: Sequence[Gate], *index: int) None

Apply which-th gate from kraus list, i.e. apply kraus[which]

Parameters:
  • which (Tensor) – Tensor of shape [] and dtype int

  • kraus (Sequence[Gate]) – A list of gate in the form of tc.gate or Tensor

  • index (int) – the qubit lines the gate applied on

sgates = ['i', 'x', 'y', 'z', 'h', 't', 's', 'td', 'sd', 'wroot', 'cnot', 'cz', 'swap', 'cy', 'ox', 'oy', 'oz', 'toffoli', 'fredkin']
static standardize_gate(name: str) str

standardize the gate name to tc common gate sets

Parameters:

name (str) – non-standard gate name

Returns:

the standard gate name

Return type:

str

swap(q1: int, q2: int) None[source]
t(q: int) None[source]
td(q: int) None[source]
tdg(q: int) None[source]
tex(**kws: Any) str

Generate latex string based on quantikz latex package

Returns:

Latex string that can be directly compiled via, e.g. latexit

Return type:

str

tick_instruction() None[source]
to_cirq(enable_instruction: bool = False) Any

Translate tc.Circuit to a cirq circuit object.

Parameters:

enable_instruction (bool, defaults to False) – whether also export measurement and reset instructions

Returns:

A cirq circuit of this circuit.

to_json(file: str | None = None, simplified: bool = False) Any

circuit dumps to json

Parameters:
  • file (Optional[str], optional) – file str to dump the json to, defaults to None, return the json str

  • simplified (bool) – If False, keep all info for each gate, defaults to be False. If True, suitable for IO since less information is required

Returns:

None if dumps to file otherwise the json str

Return type:

Any

to_openqasm(**kws: Any) str

transform circuit to openqasm via qiskit circuit, see https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.qasm.html for usage on possible options for kws

Returns:

circuit representation in openqasm format

Return type:

str

to_openqasm_file(file: str, **kws: Any) None

save the circuit to openqasm file

Parameters:

file (str) – the file path to save the circuit

to_qir() List[Dict[str, Any]]

Return the quantum intermediate representation of the circuit.

Example:

>>> c = tc.Circuit(2)
>>> c.CNOT(0, 1)
>>> c.to_qir()
[{'gatef': cnot, 'gate': Gate(
    name: 'cnot',
    tensor:
        array([[[[1.+0.j, 0.+0.j],
                [0.+0.j, 0.+0.j]],

                [[0.+0.j, 1.+0.j],
                [0.+0.j, 0.+0.j]]],


            [[[0.+0.j, 0.+0.j],
                [0.+0.j, 1.+0.j]],

                [[0.+0.j, 0.+0.j],
                [1.+0.j, 0.+0.j]]]], dtype=complex64),
    edges: [
        Edge(Dangling Edge)[0],
        Edge(Dangling Edge)[1],
        Edge('cnot'[2] -> 'qb-1'[0] ),
        Edge('cnot'[3] -> 'qb-2'[0] )
    ]), 'index': (0, 1), 'name': 'cnot', 'split': None, 'mpo': False}]
Returns:

The quantum intermediate representation of the circuit.

Return type:

List[Dict[str, Any]]

to_qiskit(enable_instruction: bool = False, enable_inputs: bool = False) Any

Translate tc.Circuit to a qiskit QuantumCircuit object.

Parameters:
  • enable_instruction (bool, defaults to False) – whether also export measurement and reset instructions

  • enable_inputs (bool, defaults to False) – whether also export the inputs

Returns:

A qiskit object of this circuit.

vgates = ['r', 'cr', 'u', 'cu', 'rx', 'ry', 'rz', 'phase', 'rxx', 'ryy', 'rzz', 'cphase', 'crx', 'cry', 'crz', 'orx', 'ory', 'orz', 'iswap', 'any', 'exp', 'exp1', 'su4']
vis_tex(**kws: Any) str

Generate latex string based on quantikz latex package

Returns:

Latex string that can be directly compiled via, e.g. latexit

Return type:

str

x(q: int) None[source]
x_error(q: int, p: float) None[source]
y(q: int) None[source]
y_error(q: int, p: float) None[source]
z(q: int) None[source]
z_error(q: int, p: float) None[source]
tensorcircuit.zx.stabilizertcircuit.sample_component(comp: CompiledComponent, f_params: Array, key: Any) Tuple[Array, Any, Array][source]

Sample measurement outcomes for a single compiled component.

Parameters:
  • comp (CompiledComponent) – The compiled component to sample from.

  • f_params (jax.Array) – The sampled error bit parameters (f-basis).

  • key (Any) – JAX PRNG key for sampling.

Returns:

A tuple containing the measurement samples, next PRNG key, and maximum deviation.

Return type:

Tuple[jax.Array, Any, jax.Array]

tensorcircuit.zx.stabilizertcircuit.sample_program(program: CompiledProgram, f_params: Array, key: Any) Array[source]

Sample measurement outcomes for an entire compiled program.

Parameters:
  • program (CompiledProgram) – The compiled program to sample from.

  • f_params (jax.Array) – The sampled error bit parameters (f-basis).

  • key (Any) – JAX PRNG key for sampling.

Returns:

The measurement samples for all qubits.

Return type:

jax.Array