forked from ScQ-Cloud/pyquafu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
357ed3b
commit f5cdf86
Showing
9 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
|
||
from quafu import QuantumCircuit, simulate, Task | ||
|
||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
|
||
def build_a_circuit(): | ||
# initialize (with 1 qubit) | ||
qc = QuantumCircuit(num=1) | ||
|
||
# apply (a Hadamard qu_gate on the first qubit) | ||
qc.h(pos=0) | ||
|
||
# measure (on the first qubit) | ||
qc.measure(pos=[0]) | ||
return qc | ||
|
||
|
||
def save_a_circuit(qc: QuantumCircuit): | ||
print(qc.to_openqasm()) | ||
# with open('openqasm.txt', 'w') as f: | ||
# f.write(qc.to_openqasm()) | ||
return None | ||
|
||
|
||
def load_a_circuit(): | ||
f = open('openqasm.txt', 'r') | ||
openqasm_lines = f.read() | ||
|
||
qc = QuantumCircuit(num=1) | ||
qc.from_openqasm(openqasm_lines) | ||
qc.draw_circuit() | ||
return qc | ||
|
||
|
||
def simulation(qc: QuantumCircuit): | ||
simu_res = simulate(qc, output='probabilities') | ||
print(simu_res.probabilities) | ||
return simu_res | ||
|
||
|
||
def execution(qc: QuantumCircuit): | ||
task = Task() | ||
shots_num = 200 | ||
backend = "ScQ-P10" # ScQ-P10, ScQ-P18, ScQ-P136 | ||
task.config(backend=backend, shots=shots_num, compile=True) | ||
|
||
exp_results = task.send(qc, wait=True) | ||
print(exp_results.probabilities) | ||
# exp_results.transpiled_circuit.plot_circuit(show=True) | ||
return exp_results | ||
|
||
|
||
if __name__ == '__main__': | ||
qc_ = build_a_circuit() | ||
# simulation(qc_) | ||
execution(qc_) | ||
|
||
# simu_res.plot_probabilities() | ||
# plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print('hi, this is pyquafu!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
|
||
from quafu import QuantumCircuit, simulate, Task, User | ||
# logging.basicConfig(level=logging.INFO, | ||
# format='%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - Line %(lineno)d - %(message)s') | ||
|
||
logging.info('Quick test started.') | ||
|
||
qc = QuantumCircuit(num=4) | ||
|
||
# apply (a Hadamard qu_gate on the first qubit) | ||
qc.h(pos=0) | ||
|
||
# measure (on the first qubit) | ||
# qc.measure(pos=[0]) | ||
qc.measure() | ||
qc_draw = qc.draw_circuit(return_str=True) | ||
|
||
logging.info('built qc:\n' + qc_draw) | ||
|
||
simu_res = simulate(qc, output='probabilities').probabilities | ||
logging.info('simulated results:\nprobabilities = ' + str(simu_res)) | ||
|
||
|
||
user = User() | ||
user.get_available_backends() | ||
|
||
task = Task() | ||
task.retrieve('30BEE0A009ADD81C') | ||
|
||
# shots_num = 200 | ||
# backend = "ScQ-P18" # ScQ-P10, ScQ-P18, ScQ-P136 | ||
# task.config(backend=backend, shots=shots_num, compile=True) | ||
# | ||
# exp_results = task.send(qc, wait=True) | ||
# print(exp_results.probabilities) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from quafu.users.userapi import User | ||
|
||
user = User(api_token='wuNZGTDAHQfsQ0Ngtq_j0fh1RLV-IeeM7eFWJeN1-21.9dDN0QzMyQTO2EjOiAHelJCL3k' | ||
'DN6ICZpJye.9JiN1IzUIJiOicGbhJCLiQ1VKJiOiAXe0Jye') | ||
user.save_apitoken() |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from quafu.users.userapi import User | ||
|
||
user = User() | ||
# user._load_account_token() | ||
# user.save_apitoken() | ||
print(user.api_token) | ||
user.save_apitoken('hahah') | ||
print(user.api_token) | ||
|
||
# print(api) | ||
# print('ha') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UAk1o5DFoBitcbQab_Y96m6bAtHmAS9QSubw-3txCct.9BjMzIDNxcDO2EjOiAHelJCL3kDN6ICZpJye.9JiN1IzUIJiOicGbhJCLiQ1VKJiOiAXe0Jye | ||
hahah |