or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdoperators.mdphase-space.mdprocess-tomography.mdquantum-gates.mdquantum-information.mdquantum-objects.mdrandom-objects.mdsolvers.mdstates.mdsuperoperators.mdtensor-operations.mdutilities.mdvisualization.md

quantum-objects.mddocs/

0

# Quantum Objects and States

1

2

The fundamental quantum object manipulation, state construction, and basic operations in QuTiP. The `Qobj` class serves as the foundation for all quantum computations.

3

4

## Capabilities

5

6

### Qobj Class

7

8

The main quantum object class that represents quantum states, operators, and superoperators with automatic type detection and efficient sparse matrix storage.

9

10

```python { .api }

11

class Qobj:

12

def __init__(self, inpt=None, dims=None, shape=None, type=None,

13

isherm=None, isunitary=None, copy=True):

14

"""

15

Create a quantum object.

16

17

Parameters:

18

- inpt: Array-like data or another Qobj

19

- dims: List of dimensions for tensor structure

20

- shape: Tuple of matrix dimensions

21

- type: 'ket', 'bra', 'oper', or 'super'

22

- isherm: Boolean indicating Hermiticity

23

- isunitary: Boolean indicating unitarity

24

- copy: Whether to copy input data

25

"""

26

27

def copy(self) -> 'Qobj':

28

"""Create a copy of the quantum object."""

29

30

def dag(self) -> 'Qobj':

31

"""Return the adjoint (conjugate transpose) of the quantum object."""

32

33

def conj(self) -> 'Qobj':

34

"""Return the complex conjugate of the quantum object."""

35

36

def trans(self) -> 'Qobj':

37

"""Return the transpose of the quantum object."""

38

39

def norm(self, norm=None, sparse=False, tol=0, maxiter=100000):

40

"""

41

Calculate the norm of the quantum object.

42

43

Parameters:

44

- norm: Type of norm ('tr', 'fro', 'one', 'max', 'l2')

45

- sparse: Use sparse eigensolver

46

- tol: Tolerance for sparse solver

47

- maxiter: Maximum iterations for sparse solver

48

49

Returns:

50

- float: The calculated norm

51

"""

52

53

def tr(self):

54

"""Calculate the trace of the quantum object."""

55

56

def ptrace(self, sel):

57

"""

58

Partial trace over specified subsystems.

59

60

Parameters:

61

- sel: Integer or list of integers specifying subsystems to trace out

62

63

Returns:

64

- Qobj: Reduced quantum object

65

"""

66

67

def eigenstates(self, sparse=False, sort='low', eigvals=0, tol=0, maxiter=100000):

68

"""

69

Calculate eigenvalues and eigenstates.

70

71

Parameters:

72

- sparse: Use sparse eigensolver

73

- sort: 'low' or 'high' for eigenvalue ordering

74

- eigvals: Number of eigenvalues to find (0 for all)

75

- tol: Tolerance for sparse solver

76

- maxiter: Maximum iterations

77

78

Returns:

79

- tuple: (eigenvalues, eigenstates)

80

"""

81

82

def eigenenergies(self, sparse=False, sort='low', eigvals=0, tol=0, maxiter=100000):

83

"""

84

Calculate eigenvalues only.

85

86

Parameters: Same as eigenstates()

87

88

Returns:

89

- array: Eigenvalues

90

"""

91

92

def expm(self, dtype=None) -> 'Qobj':

93

"""Calculate matrix exponential."""

94

95

def logm(self, dtype=None) -> 'Qobj':

96

"""Calculate matrix logarithm."""

97

98

def sqrtm(self, dtype=None) -> 'Qobj':

99

"""Calculate matrix square root."""

100

101

def unit(self, inplace=False) -> 'Qobj':

102

"""

103

Return normalized quantum object.

104

105

Parameters:

106

- inplace: Modify object in-place

107

108

Returns:

109

- Qobj: Normalized quantum object

110

"""

111

112

def tidyup(self, atol=None, rtol=None) -> 'Qobj':

113

"""

114

Remove small matrix elements.

115

116

Parameters:

117

- atol: Absolute tolerance

118

- rtol: Relative tolerance

119

120

Returns:

121

- Qobj: Cleaned quantum object

122

"""

123

```

124

125

### Basic Quantum Object Creation

126

127

Functions for creating basic quantum objects from arrays and other data structures.

128

129

```python { .api }

130

def qeye(dimensions) -> Qobj:

131

"""

132

Create identity operator.

133

134

Parameters:

135

- dimensions: Integer or list of dimensions

136

137

Returns:

138

- Qobj: Identity operator

139

"""

140

141

def qzero(dimensions) -> Qobj:

142

"""

143

Create zero operator.

144

145

Parameters:

146

- dimensions: Integer or list of dimensions

147

148

Returns:

149

- Qobj: Zero operator

150

"""

151

152

def qdiags(diagonals, offsets=None, dims=None, shape=None) -> Qobj:

153

"""

154

Create diagonal quantum object.

155

156

Parameters:

157

- diagonals: Array-like diagonal elements

158

- offsets: Integer or list of diagonal offsets

159

- dims: Dimensions for tensor structure

160

- shape: Matrix shape

161

162

Returns:

163

- Qobj: Diagonal quantum object

164

"""

165

166

def ket(label, dim=None) -> Qobj:

167

"""

168

Create ket state from label.

169

170

Parameters:

171

- label: String or integer label

172

- dim: Total dimension of Hilbert space

173

174

Returns:

175

- Qobj: Ket state

176

"""

177

178

def bra(label, dim=None) -> Qobj:

179

"""

180

Create bra state from label.

181

182

Parameters:

183

- label: String or integer label

184

- dim: Total dimension of Hilbert space

185

186

Returns:

187

- Qobj: Bra state

188

"""

189

190

def ket2dm(psi) -> Qobj:

191

"""

192

Convert ket to density matrix.

193

194

Parameters:

195

- psi: Input ket state

196

197

Returns:

198

- Qobj: Density matrix |ψ⟩⟨ψ|

199

"""

200

```

201

202

### Partial Trace Operations

203

204

Functions for working with composite quantum systems and reduced states.

205

206

```python { .api }

207

def ptrace(obj: Qobj, sel) -> Qobj:

208

"""

209

Partial trace over specified subsystems.

210

211

Parameters:

212

- obj: Input quantum object

213

- sel: Integer or list of integers specifying subsystems to keep

214

215

Returns:

216

- Qobj: Reduced quantum object after tracing out unselected subsystems

217

"""

218

```

219

220

### Usage Examples

221

222

```python

223

import qutip as qt

224

import numpy as np

225

226

# Create quantum objects

227

psi = qt.basis(2, 0) # |0⟩ state in 2-level system

228

rho = psi * psi.dag() # Density matrix |0⟩⟨0|

229

H = qt.sigmaz() # Pauli-Z Hamiltonian

230

231

# Basic operations

232

psi_dag = psi.dag() # Conjugate transpose

233

norm_psi = psi.norm() # Norm calculation

234

trace_rho = rho.tr() # Trace

235

236

# Matrix functions

237

U = (-1j * H * 0.5).expm() # Time evolution operator e^(-iHt/2)

238

sqrt_rho = rho.sqrtm() # Matrix square root

239

240

# Eigenanalysis

241

evals, estates = H.eigenstates() # Find eigenvalues and eigenstates

242

ground_energy = H.groundstate()[0] # Ground state energy

243

244

# Two-qubit system partial trace

245

psi_00 = qt.tensor(qt.basis(2,0), qt.basis(2,0)) # |00⟩

246

rho_total = psi_00 * psi_00.dag() # Total density matrix

247

rho_A = qt.ptrace(rho_total, 0) # Reduced state of first qubit

248

249

# Create custom operators

250

data = np.array([[1, 0.5], [0.5, 0]])

251

custom_op = qt.Qobj(data) # Custom 2x2 operator

252

custom_op.isherm # Check if Hermitian

253

```

254

255

## Types

256

257

```python { .api }

258

class Qobj:

259

"""

260

Quantum object representing states, operators, and superoperators.

261

262

Attributes:

263

data: Underlying matrix data (sparse or dense)

264

dims: List representing tensor structure dimensions

265

shape: Tuple of matrix dimensions (rows, cols)

266

type: String type ('ket', 'bra', 'oper', 'super')

267

isherm: Boolean indicating Hermiticity

268

isunitary: Boolean indicating unitarity

269

superrep: Superoperator representation ('super', 'choi', etc.)

270

"""

271

```