Qiskit 1.0に対応したローカルシミュレータ(AerSimulator)、IBMシミュレータ、IBM実機の実行コード (python)
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler
### ログイン
service_real = QiskitRuntimeService(channel="ibm_quantum", token='IBM Quantum PlatformのAPI Tokenを入力')
service_simulator = QiskitRuntimeService(channel="ibm_cloud",
token = "IBM CloudのAPIキーを入力",
instance = "IBM CloudのCRNを入力")
### Circuitの用意
circuit = QuantumCircuit(2, 2) # 量子回路を初期化
# 量子回路の組み立て
circuit.h(0) # アダマール行列を適用
circuit.cx(0, 1) # CNOTを適用
# 測定
circuit.measure([0, 1], [0, 1])
# 出力
#circuit.draw(output="mpl")
circuit2 = QuantumCircuit(3, 3) # 量子回路を初期化
# 量子回路の組み立て
circuit2.h(0) # アダマール行列を適用
circuit2.h(1) # アダマール行列を適用
circuit2.h(2) # アダマール行列を適用
circuit2.cx(0, 1) # CNOTを適用
circuit2.cx(1, 2) # CNOTを適用
circuit2.cx(0, 2) # CNOTを適用
# 測定
circuit2.measure([0, 1, 2], [0, 1, 2])
# 出力
#circuit2.draw(output="mpl")
### ローカルシミュレータ(AerSimulator)
from qiskit.primitives import BackendSampler
from qiskit_aer import AerSimulator
simulator = AerSimulator()
job = simulator.run([circuit, circuit2], shots=100, memory=False)
result = job.result()
#print(result)
#for i in range(2):
# print( result.results[i].data )
### IBMシミュレータ
#実行と結果取得
from qiskit.primitives import BackendSampler
backend = service_simulator.backend("ibmq_qasm_simulator")
sampler = BackendSampler(backend)
job = sampler.run([circuit, circuit2])
result = job.result()
print(result)
### IBM量子コンピュータ実機
from qiskit.primitives import BackendSampler
backend = service_real.least_busy(simulator=False)
sampler = BackendSampler(backend)
job = sampler.run([circuit])
result = job.result()
print(result)
#from qiskit.visualization import plot_distribution
#plot_distribution(result.quasi_dists)
参考:https://qiita.com/TeruS_4/items/694f82c9eb781d8e8faa
参考:https://docs.quantum.ibm.com/guides/get-started-with-primitives
※ただし、AerSimulatorとIBMシミュレータ・量子実機では出力が異なるため、注意
スライドテンプレート (更新:2018/01/10)
- ご自由にお使いください。
- 2次配布も自由です。
- pptx形式
- potx形式(テンプレート形式)
Raspberry piを「USB電力計 サンワサプライ TAP-TST10」に接続して電力測定する方法 (更新:2018/02/04)
- PC側での設定
- Raspberry pi側での設定
- sudo raspi-configから設定編集
- 1.Change User Password...でパスワード変更
- 2.Network Options で
- "N1 Hostname" で端末のホスト名を変更
- "N2 Wi-fi" でSSIDとPasswordを入力
- "N3 Network interface names Enable/Disable ..." でinterface nameでの検索をenable
- 4.Localisation Options...で
- "I2 Change Timezone" でタイムゾーンを"Tokyo"に設定
- "I3 Change Keyboard Layout" でキーボードを"Generic 105-key(Intl)PC"に設定し、Layoutを"Japanese"に設定
- "I4 Change Wi-fi Country" で"JP"に設定
- 5.Interfacing Options ...で
- "P2 SSH" を"enable"に設定
- 8.Update で
- raspi-configをアップデート
- 本体のアップデート
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install -y rpi-update
- sudo rpi-update
- sudo reboot
- sudo apt-get install -y emacs
- pythonの環境設定
- 電力データ収集時の操作
- USBのバインドを解除する
- cd /sys/bus/usb/drivers/usbhid
- ls -l
- echo "?-?.?:?.?" | sudo tee -a unbind # lsで表示されたUSB番号をバインド
- tapsts10ctl.pyを実行して結果をファイルに出力
- sudo ./tapsts10ctl.py > tmp.csv
参考URL
USB電力計 サンワサプライ TAP-TST10をLinuxで使ってみた - OSAKANA TAROのメモ帳
nonakap/taptst10ctl - Git Hub
pyusb 1.0.0a2 - Python Software Foundation
Graphvizで指定可能な操作一覧
- ノード
- label="xxx" : ノードに"xxx"と表示させる
- style=dashed : 点線で囲む
- shape=doublecircle : 二重線で囲まれた丸い形にする
- color=red : 赤線で囲む
- 枝
- penwidth=4 : 枝の線の太さを4ptにする
- style=dashed : 枝を点線にする
Wireshark パケット結合
- mergecap.exeを使用
- "C:\Program Files\Wireshark\mergecap.exe" -a *.pcap -w merged.pcap
- "C:\Program Files\Wireshark\mergecap.exe" 1.pcap 2.pcap 3.pcap 4.pcap(複数選択可) -w merged.pcap
- -w : 書き出し(ファイル名指定)
- 参考URL
Wireshark tsharkによるフィルタリング
- tshark.exeを使用
- "C:\Program Files\Wireshark\tshark" -r *.pcap -R "ssh" -w pick-out-1.pcap
- "ssh"の部分にはディスプレイフィルタの構文を使用
- -R : 抽出条件
- -Y : 抽出条件が複数の場合
- 参考URL
Wireshark tsharkによるフィールド内容の出力
- tshark.exeを使用
- tshark -r file.pcap -T fields -e frame.time_epoch -e ip.src -e ip.dst -e tcp.dstport -e http.content_length "http"
- タブ区切りで出力
- "http":httpデータのみを対象
- -T fileds -e : 抽出内容の指定
- 参考URL
shell lsのファイル全てにアクションを実行
#!/bin/shfor file in *; do
echo "${file}"
done
Murata Lab home