Skip to content

Commit ff4b1a1

Browse files
committed
[major] refine the interface: add the QuantumState class, state.gate is supported such as state.h
1 parent f38fb42 commit ff4b1a1

File tree

3 files changed

+721
-0
lines changed

3 files changed

+721
-0
lines changed

test/quantumstate_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import torchquantum as tq
2+
import pdb
3+
import numpy as np
4+
import torch
5+
6+
if __name__ == '__main__':
7+
pdb.set_trace()
8+
state = tq.QuantumState(
9+
n_wires=4,
10+
bsz=1
11+
)
12+
state.hadamard(wires=1, inverse=True)
13+
state.h(wires=2)
14+
state.rx(wires=1, params=torch.Tensor([np.pi]))
15+
16+
state.h(wires=0)
17+
state.rx(wires=1, params=0.1)
18+
19+
state.u1(wires=1, params=[0.2])
20+
state.qubitunitary(wires=0, params=[[0,1], [1,0]])
21+
22+
state.u3(wires=2, params=[0.1, 0.2, 0.3])
23+
state.crot(wires=[0,3], params=[0.3, 0.4, 0.5])
24+
state.rot(wires=3, params=[0.4, 0.5, 0.6])
25+
26+
print(state)
27+
28+

torchquantum/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .utils import *
1515
from .noise_model import *
1616
from .node import *
17+
from .states import *
1718

1819
# here we check whether the Qiskit parameterization bug is fixed, if not, a
1920
# warning message will be printed

0 commit comments

Comments
 (0)