quimb.tensor.circuit.gates

Gate definitions, registries, and the Gate class for circuits.

Attributes

Classes

Gate

A simple class for storing the details of a quantum circuit gate.

Functions

recursive_stack(x)

register_constant_gate(name, G, num_qubits[, tag])

register_param_gate(name, param_fn, num_qubits[, tag])

register_special_gate(name, fn, num_qubits[, tag, array])

rx_gate_param_gen(params)

ry_gate_param_gen(params)

rz_gate_param_gen(params)

u3_gate_param_gen(params)

u2_gate_param_gen(params)

u1_gate_param_gen(params)

cu3_param_gen(params)

cu2_param_gen(params)

cu1_param_gen(params)

crx_param_gen(params)

Parametrized controlled X-rotation.

cry_param_gen(params)

Parametrized controlled Y-rotation.

crz_param_gen(params)

Parametrized controlled Z-rotation.

fsim_param_gen(params)

fsimg_param_gen(params)

givens_param_gen(params)

givens2_param_gen(params)

xx_plus_yy_param_gen(params)

xx_minus_yy_param_gen(params)

rxx_param_gen(params)

Parametrized two qubit XX-rotation.

ryy_param_gen(params)

Parametrized two qubit YY-rotation.

rzz_param_gen(params)

Parametrized two qubit ZZ-rotation.

su4_gate_param_gen(params)

See https://arxiv.org/abs/quant-ph/0308006 - Fig. 7.

apply_swap(psi, i, j, **gate_opts)

build_controlled_gate_htn(ncontrol, gate, upper_inds, ...)

Build a low rank hyper tensor network (CP-decomp like) representation of

_apply_controlled_gate_mps(psi, gate[, tags])

Apply a multi-controlled gate to a state represented as an MPS.

_apply_controlled_gate_htn(psi, gate[, tags, ...])

_apply_controlled_gate_eager(psi, gate[, tags])

Apply a multi-controlled gate to a state whose gates are eagerly

apply_controlled_gate(psi, gate[, tags, contract, ...])

_cached_param_gate_build(fn, params)

sample_bitstring_from_prob_ndarray(p[, seed])

Sample a bitstring from n-dimensional tensor p of probabilities.

rehearsal_dict(tn, tree)

parse_to_gate(gate_id, *gate_args[, params, qubits, ...])

Map all types of gate specification into a Gate object.

Module Contents

quimb.tensor.circuit.gates.recursive_stack(x)[source]
quimb.tensor.circuit.gates.ALL_GATES
quimb.tensor.circuit.gates.ONE_QUBIT_GATES
quimb.tensor.circuit.gates.TWO_QUBIT_GATES
quimb.tensor.circuit.gates.ALL_PARAM_GATES
quimb.tensor.circuit.gates.ONE_QUBIT_PARAM_GATES
quimb.tensor.circuit.gates.TWO_QUBIT_PARAM_GATES
quimb.tensor.circuit.gates.GATE_TAGS
quimb.tensor.circuit.gates.GATE_SIZE
quimb.tensor.circuit.gates.CONSTANT_GATES
quimb.tensor.circuit.gates.PARAM_GATES
quimb.tensor.circuit.gates.SPECIAL_GATES
quimb.tensor.circuit.gates.register_constant_gate(name, G, num_qubits, tag=None)[source]
quimb.tensor.circuit.gates.register_param_gate(name, param_fn, num_qubits, tag=None)[source]
quimb.tensor.circuit.gates.register_special_gate(name, fn, num_qubits, tag=None, array=None)[source]
quimb.tensor.circuit.gates.rx_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.ry_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.rz_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.u3_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.u2_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.u1_gate_param_gen(params)[source]
quimb.tensor.circuit.gates.cu3_param_gen(params)[source]
quimb.tensor.circuit.gates.cu2_param_gen(params)[source]
quimb.tensor.circuit.gates.cu1_param_gen(params)[source]
quimb.tensor.circuit.gates.crx_param_gen(params)[source]

Parametrized controlled X-rotation.

quimb.tensor.circuit.gates.cry_param_gen(params)[source]

Parametrized controlled Y-rotation.

quimb.tensor.circuit.gates.crz_param_gen(params)[source]

Parametrized controlled Z-rotation.

quimb.tensor.circuit.gates.fsim_param_gen(params)[source]
quimb.tensor.circuit.gates.fsimg_param_gen(params)[source]
quimb.tensor.circuit.gates.givens_param_gen(params)[source]
quimb.tensor.circuit.gates.givens2_param_gen(params)[source]
quimb.tensor.circuit.gates.xx_plus_yy_param_gen(params)[source]
quimb.tensor.circuit.gates.xx_minus_yy_param_gen(params)[source]
quimb.tensor.circuit.gates.rxx_param_gen(params)[source]

Parametrized two qubit XX-rotation.

\[\mathrm{RXX}(\theta) = \exp(-i \frac{\theta}{2} X_i X_j)\]
quimb.tensor.circuit.gates.ryy_param_gen(params)[source]

Parametrized two qubit YY-rotation.

\[\mathrm{RYY}(\theta) = \exp(-i \frac{\theta}{2} Y_i Y_j)\]
quimb.tensor.circuit.gates.rzz_param_gen(params)[source]

Parametrized two qubit ZZ-rotation.

\[\mathrm{RZZ}(\theta) = \exp(-i \frac{\theta}{2} Z_i Z_j)\]
quimb.tensor.circuit.gates.su4_gate_param_gen(params)[source]

See https://arxiv.org/abs/quant-ph/0308006 - Fig. 7. params: # theta1, phi1, lamda1, # theta2, phi2, lamda2, # theta3, phi3, lamda3, # theta4, phi4, lamda4, # t1, t2, t3,

quimb.tensor.circuit.gates._MPS_METHODS
quimb.tensor.circuit.gates.apply_swap(psi, i, j, **gate_opts)[source]
quimb.tensor.circuit.gates.build_controlled_gate_htn(ncontrol, gate, upper_inds, lower_inds, tags_each=None, tags_all=None, bond_ind=None)[source]

Build a low rank hyper tensor network (CP-decomp like) representation of a multi controlled gate.

quimb.tensor.circuit.gates._apply_controlled_gate_mps(psi, gate, tags=None, **gate_opts)[source]

Apply a multi-controlled gate to a state represented as an MPS.

quimb.tensor.circuit.gates._apply_controlled_gate_htn(psi, gate, tags=None, propagate_tags='register', **gate_opts)[source]
quimb.tensor.circuit.gates._apply_controlled_gate_eager(psi, gate, tags=None, **gate_opts)[source]

Apply a multi-controlled gate to a state whose gates are eagerly contracted (e.g. a dense statevector): insert the low-rank HTN representation of the gate, then contract the resulting tensor network back into the dense state. This avoids ever forming the full 2**(2N) dense operator.

quimb.tensor.circuit.gates.apply_controlled_gate(psi, gate, tags=None, contract='auto-split-gate', propagate_tags='register', **gate_opts)[source]
quimb.tensor.circuit.gates._cached_param_gate_build(fn, params)[source]
class quimb.tensor.circuit.gates.Gate(label, params, qubits=None, controls=None, round=None, parametrize=False)[source]

A simple class for storing the details of a quantum circuit gate.

Parameters:
  • label (str) – The name or ‘identifier’ of the gate.

  • params (Iterable[float]) – The parameters of the gate.

  • qubits (Iterable[int], optional) – Which qubits the gate acts on.

  • controls (Iterable[int], optional) – Which qubits are the controls.

  • round (int, optional) – If given, which round or layer the gate is part of.

  • parametrize (bool, optional) – Whether the gate will correspond to a parametrized tensor.

__slots__ = ('_label', '_params', '_qubits', '_controls', '_round', '_parametrize', '_tag', '_special',...
_label
_params
_round
_parametrize = False
_tag
_special
_constant
_array = None
classmethod from_raw(U, qubits=None, controls=None, round=None)[source]
copy()[source]
property label
property params
property qubits
property total_qubit_count
property controls
property round
property special
property parametrize
property tag
copy_with(**kwargs)[source]

Take a copy of this gate but with some attributes changed.

build_array()[source]

Build the array representation of the gate. For controlled gates this excludes the control qubits.

property array
build_mpo(L=None, **kwargs)[source]

Build an MPO representation of this gate.

__repr__()[source]
quimb.tensor.circuit.gates.sample_bitstring_from_prob_ndarray(p, seed=None)[source]

Sample a bitstring from n-dimensional tensor p of probabilities.

Examples

>>> import numpy as np
>>> p = np.zeros(shape=(2, 2, 2, 2, 2))
>>> p[0, 1, 0, 1, 1] = 1.0
>>> sample_bitstring_from_prob_ndarray(p)
'01011'
quimb.tensor.circuit.gates.rehearsal_dict(tn, tree)[source]
quimb.tensor.circuit.gates.parse_to_gate(gate_id, *gate_args, params=None, qubits=None, controls=None, gate_round=None, parametrize=None)[source]

Map all types of gate specification into a Gate object.