-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_run.py
More file actions
34 lines (22 loc) · 1002 Bytes
/
test_run.py
File metadata and controls
34 lines (22 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def test_incremental():
import numpy as np
from qiskit.quantum_info import random_unitary
from quantumreservoirpy.reservoirs import Incremental
encoder = {0: "00", 1: "01", 2: "10", 3: "11"}
SHOTS = 100
class RandomUnitary(Incremental):
def __init__(self, n_qubits, memory=np.inf, backend=None, num_features=8) -> None:
super().__init__(n_qubits, memory, backend, num_features)
self.operator = random_unitary(2**n_qubits)
def before(self, circuit):
circuit.h(circuit.qubits)
def during(self, circuit, timestep, reservoirnumber):
circuit.measure([0, 1])
circuit.initialize(encoder[timestep], [0, 1])
circuit.append(self.operator, circuit.qubits)
def after(self, circuit):
circuit.measure_all()
res = RandomUnitary(n_qubits=4, memory=8)
timestep = [0, 1, 2, 3, 0, 1, 2, 2, 3]
timeseries = timestep * 10
res.run(timeseries, shots=SHOTS)