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

circuit-formats.mddocs/

0

# Quantum Circuit Formats

1

2

Qiskit supports import/export of quantum circuits in OpenQASM 2.0/3.0 and QPY binary formats for interoperability with other quantum computing tools and long-term circuit storage.

3

4

## Capabilities

5

6

### OpenQASM 2.0 Interface

7

8

```python { .api }

9

# qiskit.qasm2 module

10

def load(filename):

11

"""Load OpenQASM 2.0 circuit from file."""

12

13

def loads(qasm_str):

14

"""Load OpenQASM 2.0 circuit from string."""

15

16

def dump(circuit, filename):

17

"""Export circuit to OpenQASM 2.0 file."""

18

19

def dumps(circuit):

20

"""Export circuit to OpenQASM 2.0 string."""

21

```

22

23

### OpenQASM 3.0 Interface

24

25

```python { .api }

26

# qiskit.qasm3 module

27

def load(filename):

28

"""Load OpenQASM 3.0 circuit from file."""

29

30

def loads(qasm_str):

31

"""Load OpenQASM 3.0 circuit from string."""

32

33

def dump(circuit, filename):

34

"""Export circuit to OpenQASM 3.0 file."""

35

36

def dumps(circuit):

37

"""Export circuit to OpenQASM 3.0 string."""

38

```

39

40

### QPY Binary Format

41

42

```python { .api }

43

# qiskit.qpy module

44

def dump(circuits, file_obj):

45

"""Serialize quantum circuits to QPY binary format."""

46

47

def load(file_obj):

48

"""Deserialize quantum circuits from QPY binary format."""

49

50

def get_qpy_version():

51

"""Get current QPY format version."""

52

53

QPY_VERSION: int = 12

54

QPY_COMPATIBILITY_VERSION: int = 10

55

```

56

57

### Usage Examples

58

59

```python

60

from qiskit import QuantumCircuit

61

from qiskit import qasm2, qasm3, qpy

62

63

circuit = QuantumCircuit(2, 2)

64

circuit.h(0)

65

circuit.cx(0, 1)

66

circuit.measure_all()

67

68

# QASM export/import

69

qasm2_str = qasm2.dumps(circuit)

70

loaded_circuit = qasm2.loads(qasm2_str)

71

72

# QPY binary format

73

with open('circuit.qpy', 'wb') as f:

74

qpy.dump([circuit], f)

75

76

with open('circuit.qpy', 'rb') as f:

77

loaded_circuits = qpy.load(f)

78

```