Device Independent Test Documentation¶
Device Independent Test is a python library which runs tests on quantum systems through IBM's Qiskit.
The motivation for this library is the following scenario: there are two quantum computers (say, Alice's and Bob's) with some sort of network connecting them. We trust Alice's computer to be a functional quantum device. However, we do not yet trust Bob's computer. We wish to transmit states from Alice's computer to Bob's, and ask Bob to run certain operations to ascertain the functionality of our transmission and his system.
There are 3 tests in this library: dimensionality, incompatible measurements, and entanglement.
This library includes the following modules: dimension, incompatible_measurement, and entanglement. In addition, there are two classes: handshake and QuantumDispatcher. The documentation below goes over each of these files in detail.
Classes¶
HandShake¶
Interface between the user and the test modules. Initialized with an instance of QuantumDispatcher. You can use this object to run and store the results of tests.
Methods | Descriptions |
---|---|
dimensionality(tolerance, shots) |
Runs the dimensionality test with specified tolerance (float) and number of shots (int). |
measurement_incompatibility(tolerance, shots) |
Runs the incompatible measurement test with specified tolerance and shots. Returns a tuple with the pass/fail and the value of the bell violation. |
entanglement(tolerance, shots) |
Runs the entanglement test with specified tolerance and number of shots. |
test_all(params) |
Run all tests to verify functioning computer/connection. params should look like: {"dimensionality": {"tolerance": 0.1, "shots": 1000}} |
print_tests() |
Prints the available tests. |
Below is an example of using a handshake object to run an incompatible measurment test.
provider = IBMQ.load_account()
dispatch = quantum_communicator.LocalDispatcher([provider.get_backend('ibmq_qasm_simulator')])
test = incompatible_measurement.run_test(dispatch,0.0,1000)
QuantumDispatcher¶
An abstract base class to generalize the dispatching and running of operations across a system. Offers an interface from which future classes that work with a quantum network can run the tests.
Methods | Descriptions |
---|---|
init(backends) |
Constructor requiring a list of backends. |
Abstract Methods | Description |
run_and_transmit( pre_operations, post_operations, shots) |
Dispatches a single job to the quantum system. The circuit specified in pre_operations is ran on the device responsible for preparing states. The states from input_registers are then sent to the output_registers. Next, the operations in the list post_operations are executed. The index of the operation in this array corresponds to which device it runs on. Returns a dictionary with the counts from measurements on the system. |
multi_run_and_transmit( pre_operations, post_operations, shots) |
Dispatches multiple jobs to the quantum system. Pre_operations is a list of circuits. Post_operations is a list of lists, representing operations to run on different machines. Returns a list of dictionaries with the counts from measurements on the system. |
batch_run_and_transmit( pre_operations, post_operations, shots) |
Distpatches and runs all permuations of the given operations. Returns a list of dictionaries with the counts from measurements on the system. |
LocalDispatcher¶
Implements the Quantum_Dispatcher interface for running tests on a single computer. Note that the input and output register parameters are not used by this class.
Methods | Descriptions |
---|---|
init(backends) |
Only the first element in the list backends is used. |
run_and_transmit( pre_operations, post_operations, shots) |
See QuantumDispatcher. Does not use the registers. Returns counts from running the circuits. |
multi_run_and_transmit( pre_operations, post_operations, shots) |
See QuantumDispatcher. Does not use the registers. Returns a list of counts from running the circuits. |
batch_run_and_transmit( pre_operations, post_operations, shots) |
See QuantumDispatcher. Does not use the registers. Returns a list of counts from running all permutations of the circuits. |
Below is an example of creating an instance of LocalDispatcher.
provider = IBMQ.load_account()
dispatch = quantum_communicator.LocalDispatcher([provider.get_backend('ibmq_qasm_simulator')])
Device Independent Test Modules¶
Dimension¶
Methods | Descriptions | |
---|---|---|
run_test(dispatcher, tolerance, shots) |
Runs dimensionality test for 2-qubits system. Alice prepares all possible orthogonal states (no rotation), and Bob measures in corresponding canonical states. Returns a tuple of (pass/fail, test value). |
Incompatible Measurement¶
A module to conduct tests of Bell violations from incompatible measurements.
Methods | Descriptions | |
---|---|---|
run_test(dispatcher, tolerance, shots) |
Runs all incompatible measurements tests (seperate circuits). Creates and runs all cases x={0,1,2,3} and y={0,1} then determines if the bell inequality has been violated. Returns a tuple of (pass/fail, test value). | |
run_test_parallel(dispatcher, tolerance, shots) |
Runs all incompatible measurements test on 4 qubits in parallel for better performance. Returns a tuple of (pass/fail, test value). |
Entanglement¶
Methods | Descriptions | |
---|---|---|
run_test(dispatcher, tolerance, shots) |
Runs a CHSH test with bell state and checks for Tsirelson bound within tolerance. Returns a tuple of (pass/fail, test value). | |
run_test_parallel(dispatcher, tolerance, shots) |
Runs a CHSH test with bell state and checks for Tsirelson bound within tolerance. Tests are run in parallel for better performance. Returns a tuple of (pass/fail, test value). |
Example Code¶
HandShake Example¶
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from qiskit.providers.ibmq.managed import IBMQJobManager
# Loading your IBM Q account(s)
import qiskit
from qiskit import IBMQ
provider = IBMQ.load_account()
import numpy as np
import context
from device_independent_test.handshake import HandShake
from device_independent_test.quantum_communicator import LocalDispatcher
from device_independent_test import entanglement
Below is an incompatibility test that should output a violation.
communicator = LocalDispatcher([provider.get_backend('ibmq_qasm_simulator')])
handshake = HandShake(communicator)
handshake.measurement_incompatibility(0.2, 1000)
handshake.entanglement(0.1, 1000)
handshake.dimensionality(0.0, 1000)
Passed Measurment Incompatibility with value: 6.806
Passed Entanglement with value: 2.83
Passed Dimensionality with value: 1.0
(True, 1.0)
We can run all the test with specific parameters.
parameters = {
"dimensionality": { "tolerance": 0.1, "shots": 3000 },
"entanglement": { "tolerance": 0.1, "shots": 2000 },
"measurement_incompatibility": { "tolerance": 0.1, "shots": 1000 }
}
handshake.test_all(parameters)
Passed Dimensionality with value: 1.0
Passed Measurment Incompatibility with value: 6.835999999999999
Passed Entanglement with value: 2.8489999999999998
True