or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

circuit-construction.mdcircuit-formats.mdgates-operations.mdindex.mdprimitives.mdproviders.mdquantum-information.mdsynthesis.mdtranspilation.mdvisualization.md

quantum-information.mddocs/

0

# Quantum Information Processing

1

2

Qiskit's quantum information module provides mathematical foundations for quantum computing including quantum states, operators, channels, and information-theoretic measures. This enables quantum algorithm development, state analysis, and quantum channel characterization.

3

4

## Capabilities

5

6

### Quantum States

7

8

Representations of pure and mixed quantum states with manipulation and analysis operations.

9

10

```python { .api }

11

class Statevector:

12

def __init__(self, data, dims=None):

13

"""

14

Initialize a quantum state vector.

15

16

Parameters:

17

- data: State vector data (array-like, QuantumCircuit, or Instruction)

18

- dims: Subsystem dimensions

19

"""

20

21

def evolve(self, other, qargs=None):

22

"""Evolve state by quantum operation."""

23

24

def expectation_value(self, oper, qargs=None):

25

"""Calculate expectation value of observable."""

26

27

def sample_counts(self, shots):

28

"""Sample measurement outcomes."""

29

30

def sample_memory(self, shots):

31

"""Sample individual measurement results."""

32

33

def probabilities(self, qargs=None):

34

"""Get measurement probabilities."""

35

36

def probabilities_dict(self, qargs=None, decimals=None):

37

"""Get probabilities as dictionary."""

38

39

def reset(self, qargs=None):

40

"""Reset specified qubits to |0⟩."""

41

42

def measure(self, qargs=None):

43

"""Measure specified qubits."""

44

45

def is_valid(self, atol=None, rtol=None):

46

"""Check if state is valid (normalized)."""

47

48

def purity(self):

49

"""Calculate state purity."""

50

51

def conjugate(self):

52

"""Return complex conjugate of state."""

53

54

def tensor(self, other):

55

"""Tensor product with another state."""

56

57

@classmethod

58

def from_label(cls, label):

59

"""Create state from computational basis label."""

60

61

@classmethod

62

def from_instruction(cls, instruction):

63

"""Create state from quantum instruction."""

64

65

class DensityMatrix:

66

def __init__(self, data, dims=None):

67

"""

68

Initialize a density matrix.

69

70

Parameters:

71

- data: Density matrix data

72

- dims: Subsystem dimensions

73

"""

74

75

def evolve(self, other, qargs=None):

76

"""Evolve state by quantum channel."""

77

78

def expectation_value(self, oper, qargs=None):

79

"""Calculate expectation value."""

80

81

def probabilities(self, qargs=None):

82

"""Get measurement probabilities."""

83

84

def sample_counts(self, shots):

85

"""Sample measurement outcomes."""

86

87

def purity(self):

88

"""Calculate state purity."""

89

90

def trace(self):

91

"""Calculate trace of density matrix."""

92

93

def is_valid(self, atol=None, rtol=None):

94

"""Check if density matrix is valid."""

95

96

def tensor(self, other):

97

"""Tensor product with another state."""

98

99

@classmethod

100

def from_label(cls, label):

101

"""Create density matrix from basis label."""

102

103

class StabilizerState:

104

def __init__(self, data, validate=True):

105

"""

106

Initialize a stabilizer state.

107

108

Parameters:

109

- data: Stabilizer tableau or quantum circuit

110

- validate: Whether to validate the stabilizer state

111

"""

112

113

def evolve(self, other, qargs=None):

114

"""Evolve by Clifford operation."""

115

116

def expectation_value(self, oper, qargs=None):

117

"""Calculate Pauli expectation value."""

118

119

def probabilities(self, qargs=None):

120

"""Get measurement probabilities."""

121

122

def sample_counts(self, shots):

123

"""Sample measurement outcomes."""

124

125

def measure(self, qargs=None):

126

"""Measure qubits and collapse state."""

127

128

def reset(self, qargs=None):

129

"""Reset qubits to |0⟩."""

130

131

def is_valid(self):

132

"""Check if stabilizer state is valid."""

133

```

134

135

### Quantum Operators

136

137

Mathematical representations of quantum operations and measurements.

138

139

```python { .api }

140

class Operator:

141

def __init__(self, data, input_dims=None, output_dims=None):

142

"""

143

Initialize a quantum operator.

144

145

Parameters:

146

- data: Operator matrix data

147

- input_dims: Input subsystem dimensions

148

- output_dims: Output subsystem dimensions

149

"""

150

151

def compose(self, other, qargs=None, front=False):

152

"""Compose with another operator."""

153

154

def tensor(self, other):

155

"""Tensor product with another operator."""

156

157

def expand(self, other):

158

"""Tensor expand with another operator."""

159

160

def power(self, n):

161

"""Return operator raised to power n."""

162

163

def conjugate(self):

164

"""Return complex conjugate."""

165

166

def transpose(self):

167

"""Return transpose."""

168

169

def adjoint(self):

170

"""Return adjoint (conjugate transpose)."""

171

172

def is_unitary(self, atol=None, rtol=None):

173

"""Check if operator is unitary."""

174

175

def trace(self):

176

"""Calculate trace."""

177

178

@classmethod

179

def from_label(cls, label):

180

"""Create operator from Pauli label."""

181

182

@classmethod

183

def from_circuit(cls, circuit):

184

"""Create operator from quantum circuit."""

185

186

class Pauli:

187

def __init__(self, data=None):

188

"""

189

Initialize a Pauli operator.

190

191

Parameters:

192

- data: Pauli string or array representation

193

"""

194

195

def compose(self, other, qargs=None, front=False):

196

"""Compose with another Pauli."""

197

198

def tensor(self, other):

199

"""Tensor product with another Pauli."""

200

201

def expand(self, other):

202

"""Tensor expand with another Pauli."""

203

204

def conjugate(self):

205

"""Return complex conjugate."""

206

207

def transpose(self):

208

"""Return transpose."""

209

210

def adjoint(self):

211

"""Return adjoint."""

212

213

def commutes(self, other):

214

"""Check if commutes with another Pauli."""

215

216

def anticommutes(self, other):

217

"""Check if anticommutes with another Pauli."""

218

219

def evolve(self, other, frame='h'):

220

"""Evolve Pauli by Clifford operation."""

221

222

@property

223

def x(self):

224

"""X component of Pauli."""

225

226

@property

227

def z(self):

228

"""Z component of Pauli."""

229

230

@property

231

def phase(self):

232

"""Phase of Pauli (+1, -1, +1j, -1j)."""

233

234

class PauliList:

235

def __init__(self, data):

236

"""

237

Initialize a list of Pauli operators.

238

239

Parameters:

240

- data: List of Pauli strings or array data

241

"""

242

243

def compose(self, other, qargs=None, front=False):

244

"""Compose with another PauliList."""

245

246

def tensor(self, other):

247

"""Tensor product with another PauliList."""

248

249

def commutes(self, other):

250

"""Check commutation with another PauliList."""

251

252

def anticommutes(self, other):

253

"""Check anticommutation with another PauliList."""

254

255

def evolve(self, other, frame='h'):

256

"""Evolve PauliList by Clifford."""

257

258

def sort(self, weight=False):

259

"""Sort Pauli operators."""

260

261

def unique(self, return_indices=False, return_counts=False):

262

"""Find unique Pauli operators."""

263

264

class Clifford:

265

def __init__(self, data, validate=True):

266

"""

267

Initialize a Clifford operator.

268

269

Parameters:

270

- data: Clifford data (matrix, QuantumCircuit, or Instruction)

271

- validate: Whether to validate the Clifford representation

272

"""

273

274

def compose(self, other, qargs=None, front=False):

275

"""Compose with another Clifford."""

276

277

def tensor(self, other):

278

"""Tensor product with another Clifford."""

279

280

def expand(self, other):

281

"""Tensor expand with another Clifford."""

282

283

def conjugate(self):

284

"""Return complex conjugate."""

285

286

def transpose(self):

287

"""Return transpose."""

288

289

def adjoint(self):

290

"""Return adjoint."""

291

292

def is_unitary(self):

293

"""Check if Clifford is unitary."""

294

295

def to_circuit(self):

296

"""Convert to quantum circuit."""

297

298

def to_matrix(self):

299

"""Convert to unitary matrix."""

300

301

@classmethod

302

def from_circuit(cls, circuit):

303

"""Create Clifford from quantum circuit."""

304

305

@classmethod

306

def from_label(cls, label):

307

"""Create Clifford from Pauli label."""

308

309

class ScalarOp:

310

def __init__(self, dims, coeff=1):

311

"""

312

Initialize a scalar operator (identity times scalar).

313

314

Parameters:

315

- dims: Operator dimensions

316

- coeff: Scalar coefficient

317

"""

318

319

def compose(self, other, qargs=None, front=False):

320

"""Compose with another operator."""

321

322

def tensor(self, other):

323

"""Tensor product with another operator."""

324

325

def to_operator(self):

326

"""Convert to dense Operator."""

327

328

class CNOTDihedral:

329

def __init__(self, data=None, num_qubits=None):

330

"""

331

Initialize a CNOT-dihedral operator.

332

333

Parameters:

334

- data: Operator data

335

- num_qubits: Number of qubits

336

"""

337

338

def compose(self, other, qargs=None, front=False):

339

"""Compose with another CNOTDihedral."""

340

341

def tensor(self, other):

342

"""Tensor product with another CNOTDihedral."""

343

344

def adjoint(self):

345

"""Return adjoint."""

346

347

def to_operator(self):

348

"""Convert to dense Operator."""

349

350

class SparsePauliOp:

351

def __init__(self, data, coeffs=None, ignore_pauli_phase=False, copy=True):

352

"""

353

Initialize a sparse Pauli operator.

354

355

Parameters:

356

- data: Pauli operators (PauliList or list of strings)

357

- coeffs: Coefficients for each Pauli

358

- ignore_pauli_phase: Whether to ignore Pauli phases

359

- copy: Whether to copy input data

360

"""

361

362

def compose(self, other, qargs=None, front=False):

363

"""Compose with another operator."""

364

365

def tensor(self, other):

366

"""Tensor product with another operator."""

367

368

def expand(self, other):

369

"""Tensor expand with another operator."""

370

371

def conjugate(self):

372

"""Return complex conjugate."""

373

374

def transpose(self, copy=True):

375

"""Return transpose."""

376

377

def adjoint(self):

378

"""Return adjoint."""

379

380

def simplify(self, atol=None):

381

"""Simplify by combining duplicate Paulis."""

382

383

def is_hermitian(self, atol=None):

384

"""Check if operator is Hermitian."""

385

386

def expectation_value(self, state):

387

"""Calculate expectation value for given state."""

388

389

@classmethod

390

def from_operator(cls, op):

391

"""Convert general operator to SparsePauliOp."""

392

393

@classmethod

394

def from_list(cls, obj):

395

"""Create from list of (Pauli string, coefficient) pairs."""

396

```

397

398

### Quantum Channels

399

400

Representations of quantum channels and noise processes.

401

402

```python { .api }

403

class Choi:

404

def __init__(self, data, input_dims=None, output_dims=None):

405

"""

406

Initialize Choi matrix representation.

407

408

Parameters:

409

- data: Choi matrix data

410

- input_dims: Input dimensions

411

- output_dims: Output dimensions

412

"""

413

414

def compose(self, other, qargs=None, front=False):

415

"""Compose with another channel."""

416

417

def tensor(self, other):

418

"""Tensor product with another channel."""

419

420

def expand(self, other):

421

"""Tensor expand with another channel."""

422

423

def conjugate(self):

424

"""Return complex conjugate."""

425

426

def transpose(self):

427

"""Return transpose."""

428

429

def adjoint(self):

430

"""Return adjoint."""

431

432

def is_cp(self, atol=None, rtol=None):

433

"""Check if completely positive."""

434

435

def is_tp(self, atol=None, rtol=None):

436

"""Check if trace preserving."""

437

438

def is_cptp(self, atol=None, rtol=None):

439

"""Check if CPTP (valid quantum channel)."""

440

441

class Kraus:

442

def __init__(self, data, input_dims=None, output_dims=None):

443

"""

444

Initialize Kraus operator representation.

445

446

Parameters:

447

- data: List of Kraus operators

448

- input_dims: Input dimensions

449

- output_dims: Output dimensions

450

"""

451

452

def compose(self, other, qargs=None, front=False):

453

"""Compose with another channel."""

454

455

def tensor(self, other):

456

"""Tensor product with another channel."""

457

458

def is_cp(self, atol=None, rtol=None):

459

"""Check if completely positive."""

460

461

def is_tp(self, atol=None, rtol=None):

462

"""Check if trace preserving."""

463

464

class SuperOp:

465

def __init__(self, data, input_dims=None, output_dims=None):

466

"""

467

Initialize superoperator representation.

468

469

Parameters:

470

- data: Superoperator matrix

471

- input_dims: Input dimensions

472

- output_dims: Output dimensions

473

"""

474

475

def compose(self, other, qargs=None, front=False):

476

"""Compose with another channel."""

477

478

def tensor(self, other):

479

"""Tensor product with another channel."""

480

481

def is_cptp(self, atol=None, rtol=None):

482

"""Check if CPTP."""

483

```

484

485

### Information Measures

486

487

Quantum information-theoretic measures and distance functions.

488

489

```python { .api }

490

def state_fidelity(state1, state2, validate=True):

491

"""

492

Calculate fidelity between two quantum states.

493

494

Parameters:

495

- state1, state2: Quantum states (Statevector, DensityMatrix, or array)

496

- validate: Whether to validate input states

497

498

Returns:

499

float: State fidelity (0 to 1)

500

"""

501

502

def process_fidelity(channel1, channel2, require_cptp=True):

503

"""

504

Calculate process fidelity between quantum channels.

505

506

Parameters:

507

- channel1, channel2: Quantum channels

508

- require_cptp: Whether channels must be CPTP

509

510

Returns:

511

float: Process fidelity

512

"""

513

514

def average_gate_fidelity(channel, target=None, require_cptp=True):

515

"""

516

Calculate average gate fidelity.

517

518

Parameters:

519

- channel: Quantum channel

520

- target: Target unitary (identity if None)

521

- require_cptp: Whether channel must be CPTP

522

523

Returns:

524

float: Average gate fidelity

525

"""

526

527

def gate_error(channel, target=None, require_cptp=True):

528

"""

529

Calculate gate error (1 - average_gate_fidelity).

530

531

Parameters:

532

- channel: Quantum channel

533

- target: Target unitary

534

- require_cptp: Whether channel must be CPTP

535

536

Returns:

537

float: Gate error

538

"""

539

540

def diamond_norm(choi, **kwargs):

541

"""

542

Calculate diamond norm of quantum channel.

543

544

Parameters:

545

- choi: Channel in Choi representation

546

547

Returns:

548

float: Diamond norm

549

"""

550

551

def entropy(state, base=2):

552

"""

553

Calculate von Neumann entropy.

554

555

Parameters:

556

- state: Quantum state (DensityMatrix)

557

- base: Logarithm base

558

559

Returns:

560

float: von Neumann entropy

561

"""

562

563

def mutual_information(state, base=2):

564

"""

565

Calculate mutual information between subsystems.

566

567

Parameters:

568

- state: Bipartite quantum state

569

- base: Logarithm base

570

571

Returns:

572

float: Mutual information

573

"""

574

575

def entanglement_of_formation(state):

576

"""

577

Calculate entanglement of formation.

578

579

Parameters:

580

- state: Bipartite quantum state

581

582

Returns:

583

float: Entanglement of formation

584

"""

585

586

def concurrence(state):

587

"""

588

Calculate concurrence entanglement measure.

589

590

Parameters:

591

- state: Bipartite quantum state

592

593

Returns:

594

float: Concurrence (0 to 1)

595

"""

596

597

def partial_trace(state, qargs):

598

"""

599

Calculate partial trace over specified subsystems.

600

601

Parameters:

602

- state: Quantum state

603

- qargs: Subsystems to trace out

604

605

Returns:

606

Reduced quantum state

607

"""

608

```

609

610

### Random Quantum Objects

611

612

Generation of random quantum states, operators, and channels for testing and research.

613

614

```python { .api }

615

def random_statevector(dims, seed=None):

616

"""

617

Generate random quantum state vector.

618

619

Parameters:

620

- dims: Dimensions (int or list)

621

- seed: Random seed

622

623

Returns:

624

Statevector: Random state vector

625

"""

626

627

def random_density_matrix(dims, rank=None, method='Hilbert-Schmidt', seed=None):

628

"""

629

Generate random density matrix.

630

631

Parameters:

632

- dims: Dimensions

633

- rank: Rank of density matrix

634

- method: Generation method

635

- seed: Random seed

636

637

Returns:

638

DensityMatrix: Random density matrix

639

"""

640

641

def random_unitary(dims, seed=None):

642

"""

643

Generate random unitary matrix.

644

645

Parameters:

646

- dims: Matrix dimensions

647

- seed: Random seed

648

649

Returns:

650

Operator: Random unitary operator

651

"""

652

653

def random_hermitian(dims, traceless=False, seed=None):

654

"""

655

Generate random Hermitian matrix.

656

657

Parameters:

658

- dims: Matrix dimensions

659

- traceless: Whether matrix should be traceless

660

- seed: Random seed

661

662

Returns:

663

Operator: Random Hermitian operator

664

"""

665

666

def random_pauli(num_qubits, group_phase=False, seed=None):

667

"""

668

Generate random Pauli operator.

669

670

Parameters:

671

- num_qubits: Number of qubits

672

- group_phase: Whether to include group phase

673

- seed: Random seed

674

675

Returns:

676

Pauli: Random Pauli operator

677

"""

678

679

def random_clifford(num_qubits, seed=None):

680

"""

681

Generate random Clifford operator.

682

683

Parameters:

684

- num_qubits: Number of qubits

685

- seed: Random seed

686

687

Returns:

688

Clifford: Random Clifford operator

689

"""

690

```

691

692

### Usage Examples

693

694

```python

695

from qiskit.quantum_info import Statevector, DensityMatrix, Operator, Pauli, SparsePauliOp

696

from qiskit.quantum_info import state_fidelity, process_fidelity, entropy, random_statevector

697

import numpy as np

698

699

# Create quantum states

700

bell_state = Statevector.from_label('00')

701

bell_state = bell_state.evolve(Operator.from_label('HI')) # H on first qubit

702

bell_state = bell_state.evolve(Operator.from_label('CX')) # CNOT

703

704

# Calculate expectation values

705

z_obs = SparsePauliOp.from_list([('ZZ', 1.0)])

706

expectation = bell_state.expectation_value(z_obs)

707

708

# Work with mixed states

709

mixed_state = DensityMatrix(bell_state)

710

purity = mixed_state.purity()

711

712

# Create operators

713

pauli_x = Pauli('X')

714

pauli_y = Pauli('Y')

715

xy_op = pauli_x.tensor(pauli_y) # X⊗Y operator

716

717

# Sparse Pauli operators for Hamiltonians

718

hamiltonian = SparsePauliOp.from_list([

719

('XX', 0.5),

720

('YY', 0.5),

721

('ZZ', -1.0),

722

('ZI', 0.1),

723

('IZ', 0.1)

724

])

725

726

# Calculate information measures

727

state1 = random_statevector(4)

728

state2 = random_statevector(4)

729

fidelity = state_fidelity(state1, state2)

730

731

# Partial trace for subsystem analysis

732

bipartite_state = random_statevector(4) # 2-qubit state

733

reduced_state = partial_trace(bipartite_state, [1]) # Trace out second qubit

734

735

# Channel operations

736

unitary_channel = Operator.from_label('H')

737

evolved_state = bell_state.evolve(unitary_channel)

738

```