tensorcircuit.analogcircuit¶
Analog-Digital Hybrid Circuit class wrapper only support jax backend
- class tensorcircuit.analogcircuit.AnalogBlock(hamiltonian_func: Callable[[Any], Any], time: float, index: List[int] | None = None, solver_options: Dict[str, Any] | None = None)[source]¶
Bases:
objectA data structure to hold information about an analog evolution block.
- __init__(hamiltonian_func: Callable[[Any], Any], time: float, index: List[int] | None = None, solver_options: Dict[str, Any] | None = None) None¶
- hamiltonian_func: Callable[[Any], Any]¶
- index: List[int] | None = None¶
- solver_options: Dict[str, Any] | None = None¶
- time: float¶
- class tensorcircuit.analogcircuit.AnalogCircuit(nqubits: int, inputs: Any | None = None, mps_inputs: QuOperator | None = None, split: Dict[str, Any] | None = None, dim: int | None = None)[source]¶
Bases:
objectA class for hybrid digital-analog quantum simulation with time-dependent Hamiltonians.
- __init__(nqubits: int, inputs: Any | None = None, mps_inputs: QuOperator | None = None, split: Dict[str, Any] | None = None, dim: int | None = None)[source]¶
Initializes the hybrid circuit.
- param nqubits:
The number of qubits in the circuit.
- type nqubits:
int
- param dim:
The local Hilbert space dimension per site. Qudit is supported for 2 <= d <= 36.
- type dim:
If None, the dimension of the circuit will be 2, which is a qubit system.
- param inputs:
If not None, the initial state of the circuit is taken as
inputsinstead of :math:`
ert 0 angle^n` qubits, defaults to None.
- type inputs:
Optional[Tensor], optional
- param mps_inputs:
QuVector for a MPS like initial wavefunction.
- type mps_inputs:
Optional[QuOperator]
- param split:
dict if two qubit gate is ready for split, including parameters for at least one of
max_singular_valuesandmax_truncation_err.- type split:
Optional[Dict[str, Any]]
- add_analog_block(hamiltonian: Callable[[float], Any], time: float | List[Any], index: List[int] | None = None, **solver_options: Any) AnalogCircuit[source]¶
Adds a time-dependent analog evolution block to the circuit.
This finalizes the current digital block and prepares a new one for subsequent gates.
- Parameters:
hamiltonian_func (Callable[[float], np.ndarray]) – A function H(t) that takes a time t (from 0 to time) and returns the Hamiltonian matrix at that instant.
time (float) – The total evolution time ‘T’.
index (Optional[List[int]]) – The indices of the qubits to apply the analog evolution to. Defaults None for global application.
solver_options (Dict[str, Any]) – Keyword arguments passed directly to tc.timeevol.ode_evolve
- amplitude(l: str | Any) Any[source]¶
Return the amplitude for a given bitstring l.
For state simulators, this computes \(\langle l \vert \psi \rangle\).
- Parameters:
l (Union[str, Tensor]) – Bitstring in base-d using 0-9A-Z.
- Returns:
Complex amplitude.
- Return type:
Tensor
- analog_blocks: List[AnalogBlock]¶
- append(c: Any, indices: List[int] | None = None) AnalogCircuit[source]¶
Append a circuit or another AnalogCircuit to the current hybrid circuit. If an AnalogCircuit is appended, its block structure is merged into the current one.
- Parameters:
c (Union[Circuit, AnalogCircuit]) – The circuit to append.
indices (Optional[Sequence[int]]) – Optional qubit indices to map the appended circuit to.
- Returns:
The updated AnalogCircuit.
- Return type:
- property effective_circuit: Circuit¶
Returns the effective circuit after all blocks have been added.
- expectation(*ops: Tuple[Node, List[int]], reuse: bool = True, enable_lightcone: bool = False, nmc: int = 1000, **kws: Any) Any[source]¶
Compute expectation(s) of local operators.
- Parameters:
ops (Tuple[tn.Node, List[int]]) – Pairs of (operator_node, [sites]) specifying where each operator acts.
reuse (bool, optional) – If True, then the wavefunction tensor is cached for further expectation evaluation, defaults to be true.
enable_lightcone (bool, optional) – whether enable light cone simplification, defaults to False
nmc (int, optional) – repetition time for Monte Carlo sampling for noisfy calculation, defaults to 1000
- Returns:
Tensor with one element
- Return type:
Tensor
- expectation_ps(x: Sequence[int] | None = None, y: Sequence[int] | None = None, z: Sequence[int] | None = None, ps: Sequence[int] | None = None, reuse: bool = True, noise_conf: Any | None = None, nmc: int = 1000, status: Any | None = None, **kws: Any) Any[source]¶
Shortcut for Pauli string expectation. x, y, z list are for X, Y, Z positions
- Example:
>>> c = tc.Circuit(2) >>> c.X(0) >>> c.H(1) >>> c.expectation_ps(x=[1], z=[0]) array(-0.99999994+0.j, dtype=complex64)
- Parameters:
x (Optional[Sequence[int]], optional) – sites to apply X gate, defaults to None
y (Optional[Sequence[int]], optional) – sites to apply Y gate, defaults to None
z (Optional[Sequence[int]], optional) – sites to apply Z gate, defaults to None
ps (Optional[Sequence[int]], optional) – or one can apply a ps structures instead of
x,y,z, e.g. [0, 1, 3, 0, 2, 2] for X_1Z_2Y_4Y_5 defaults to None,pscan overwritex,yandzreuse (bool, optional) – whether to cache and reuse the wavefunction, defaults to True
noise_conf (Optional[NoiseConf], optional) – Noise Configuration, defaults to None
nmc (int, optional) – repetition time for Monte Carlo sampling for noisfy calculation, defaults to 1000
status (Optional[Tensor], optional) – external randomness given by tensor uniformly from [0, 1], defaults to None, used for noisfy circuit sampling
- Returns:
Expectation value
- Return type:
Tensor
- inverse() AnalogCircuit[source]¶
Inverse the hybrid circuit, including digital gate sequences and analog evolutions. Analog blocks are inverted by negating the Hamiltonian (H -> -H), which gives the physical inverse e^{+iHT} of the evolution e^{-iHT}.
- Returns:
The inversed AnalogCircuit.
- Return type:
- measure(*index: int, with_prob: bool = False, status: Any | None = None) Tuple[Any, Any]¶
Take measurement on the given site indices (computational basis). This method is jittable!
- Parameters:
index (int) – Measure on which site (wire) index.
with_prob (bool, optional) – If true, theoretical probability is also returned.
status (Optional[Tensor]) – external randomness, with shape [index], defaults to None
- Returns:
The sample output and probability (optional) of the quantum line.
- Return type:
Tuple[Tensor, Tensor]
- measure_jit(*index: int, with_prob: bool = False, status: Any | None = None) Tuple[Any, Any][source]¶
Take measurement on the given site indices (computational basis). This method is jittable!
- Parameters:
index (int) – Measure on which site (wire) index.
with_prob (bool, optional) – If true, theoretical probability is also returned.
status (Optional[Tensor]) – external randomness, with shape [index], defaults to None
- Returns:
The sample output and probability (optional) of the quantum line.
- Return type:
Tuple[Tensor, Tensor]
- probability() Any[source]¶
Get the length-2^n probability vector over the computational basis.
- Returns:
Probability vector of shape [dim^n].
- Return type:
Tensor
- sample(batch: int | None = None, allow_state: bool = False, readout_error: Sequence[Any] | None = None, format: str | None = None, random_generator: Any | None = None, status: Any | None = None, jittable: bool = True) Any[source]¶
Batched sampling from the circuit or final state.
- Parameters:
batch (Optional[int]) – Number of samples. If None, returns a single draw.
allow_state (bool) – If True, sample from the final state (when memory allows). Prefer True for speed.
readout_error (Optional[Sequence[Any]]) – Optional readout error model.
format (Optional[str]) – Output format. See
tensorcircuit.quantum.measurement_results().format – alias for the argument
formatrandom_generator (Optional[Any], optional) – random generator, defaults to None
status (Optional[Tensor]) – external randomness given by tensor uniformly from [0, 1], if set, can overwrite random_generator, shape [batch] for allow_state=True and shape [batch, nqudits] for allow_state=False using perfect sampling implementation
jittable (bool, defaults true) – when converting to count, whether keep the full size. if false, may be conflict external jit, if true, may fail for large scale system with actual limited count results
- Returns:
List (if batch) of tuple (binary configuration tensor and corresponding probability) if the format is None, and consistent with format when given
- Return type:
Any
- state(form: str = 'default') Any[source]¶
Executes the full digital-analog sequence.
- Returns:
The final state vector after the full evolution
- Return type:
Tensor
- wavefunction(form: str = 'default') Any¶
Executes the full digital-analog sequence.
- Returns:
The final state vector after the full evolution
- Return type:
Tensor