QiskitFlow. Reproducible quantum experiments.
Project description
QiskitFlow library
Hot to run
Flow
Flow of actions while using QiskitFlow is following:
- Install QiskitFlow if not installed yet
- Annotate your code with
Experiment
abstraction QiskitFlow library provides - Run your code as usual: QiskitFlow will write metadata of your experiment execution in local folder
- You can review experiments using CLI interface
We are tracking metrics, parameters, artifacts and measurements of experiments. Artifacts, circuits, sourcecode and other useful things are on their way.
Note: qiskitflow creates
_experiments
folder in place of execution of code, where all serialized information is stored in json format, so it's easy to track it even in git
Installation
pip install qiskitflow
Code annotation
Library for quantum programs annotation
Sample example of annotation:
from qiskitflow import Experiment
with Experiment("awesome_experiment") as experiment:
# your quantum program here!
experiment.write_metric("test metric", 0.1)
experiment.write_metric("test metric 2", 2)
experiment.write_parameter("test parameter", "test parameter value")
experiment.write_parameter("test parameter 2", "test paraeter value 2")
experiment.write_counts("measurement", {"00": 1024, "11": 0})
Full example with quantum teleportation
import numpy as np
import time
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, BasicAer, IBMQ
from qiskit.visualization import plot_histogram, plot_bloch_multivector
from qiskit.extensions import Initialize
from qiskit_textbook.tools import random_state, array_to_latex
from qiskitflow import Experiment
with Experiment("quantum teleportation") as experiment:
start_time = time.time()
# conduct experiment as usual
psi = random_state(1)
init_gate = Initialize(psi)
init_gate.label = "init"
inverse_init_gate = init_gate.gates_to_uncompute()
qr = QuantumRegister(3, name="q")
crz = ClassicalRegister(1, name="crz")
crx = ClassicalRegister(1, name="crx")
qc = QuantumCircuit(qr, crz, crx)
qc.append(init_gate, [0])
qc.barrier()
create_bell_pair(qc, 1, 2)
qc.barrier()
alice_gates(qc, 0, 1)
measure_and_send(qc, 0, 1)
bob_gates(qc, 2, crz, crx)
qc.append(inverse_init_gate, [2])
cr_result = ClassicalRegister(1)
qc.add_register(cr_result)
qc.measure(2,2)
backend_name = "qasm_simulator"
backend = BasicAer.get_backend(backend_name)
counts = execute(qc, backend, shots=1024).result().get_counts()
end_time = time.time()
runtime = end_time - start_time
# qiskitflow =========
# log parameters used
experiment.write_parameter("backend name", backend_name)
# log metrics of experiment
experiment.write_metric("runtime", runtime)
# log counts of experiment
experiment.write_counts("experiment counts", counts)
CLI
List of experiments
qiskitflow experiments list
experiments list screenshot
Experiment information (runs)
qiskitflow experiments info <NAME_OF_EXPERIMENT> --metrics="<METRIC_NAME>,<OTHER_METRIC_NAME>" --parameters="<PARAM>,<OTHER PARAM>"
experiment information screenshots
Experiment information
Experiment with specified optional flags
Examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qiskitflow-0.0.3a0.tar.gz
(12.1 kB
view hashes)
Built Distribution
Close
Hashes for qiskitflow-0.0.3a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e191c201a1ec2930f6f15ecdc56c780ba60eb4b3954f92ef3e99e84478b7b207 |
|
MD5 | 9db7db1c7cd367529e005217d7477aa0 |
|
BLAKE2b-256 | 59d1d371912257b2c8f59c60e0b0d614326813a0d14e1ff6369d389f9c6ab3c4 |