-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
182 additions
and
34 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
|
||
from htstabilizer.stabilizer_circuits import * | ||
from qiskit.quantum_info import random_clifford | ||
|
||
""" | ||
You can compress a Clifford circuit by replacing it with a | ||
hardware-tailored optimized circuit. | ||
The resulting circuit will only contain two-qubit gates between | ||
connected qubits (with respect to the given connectivity), so no | ||
further SWAP gates will be introduced when transpiling the circuit | ||
to hardware connectivity. | ||
Hint: try | ||
>>> from htstabilizer.connectivity_support import * | ||
>>> get_available_connectivities() | ||
to get a list of all available connectivities and for instance | ||
>>> get_connectivity_graph(5, "T").draw() | ||
to display the graph of a specific connectivity. | ||
""" | ||
|
||
|
||
# Generate some Clifford circuit | ||
qc = random_clifford(5, seed=23).to_circuit() | ||
|
||
# Optimizing it for T-shaped connectivity | ||
compressed_qc = compress_preparation_circuit(qc, "T") | ||
print(qc) | ||
print(compressed_qc) |
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,49 @@ | ||
from htstabilizer.stabilizer_circuits import * | ||
|
||
|
||
""" | ||
Example: Get a readout circuit for a 3-qubit stabilizer group | ||
optimized for linear connectivity. | ||
Hint: try | ||
>>> from htstabilizer.connectivity_support import * | ||
>>> get_available_connectivities() | ||
to get a list of all available connectivities and for instance | ||
>>> get_connectivity_graph(5, "T").draw() | ||
to display the graph of a specific connectivity. | ||
""" | ||
qc = get_readout_circuit(Stabilizer(["XZZ", "ZXI", "ZIX"]), "linear") | ||
|
||
|
||
""" | ||
Notes on building the `Stabilizer` object | ||
""" | ||
|
||
|
||
# You can also pass a QuantumCircuit that only contains Clifford gates: | ||
qc = QuantumCircuit(3) | ||
# ... add gates | ||
stabilizer = Stabilizer(qc, validate=True) | ||
|
||
# If you specify `validate=True`, then the stabilizer will check | ||
# that the given Paulis actually form a valid stabilizer: | ||
stabilizer = Stabilizer(["XZZ", "ZXI", "ZIX"], validate=True) | ||
|
||
# You can initialize a Stabilizer through a graph representing | ||
# a graph state: | ||
graph = Graph(3) | ||
graph.add_path([0, 1, 2]) | ||
stabilizer = Stabilizer(graph) | ||
|
||
|
||
# ... or by passing X and Z matrices for the stabilizer | ||
import numpy as np | ||
R = np.array([[1, 0, 0], | ||
[0, 1, 0], # each column corresponds to one Pauli | ||
[0, 0, 1]]) | ||
S = np.array([[0, 1, 1], | ||
[1, 0, 0], | ||
[1, 0, 0]]) | ||
s3 = Stabilizer((R, S)) | ||
|
||
# This would be equivalent to `Stabilizer(["XZZ", "ZXI", "ZIX"])` |
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,54 @@ | ||
|
||
from htstabilizer.tomography import * | ||
import qiskit | ||
|
||
|
||
backend = qiskit.Aer.get_backend("qasm_simulator") | ||
|
||
|
||
# Create a preparation circuit for the state to measure | ||
preparation_circuit = QuantumCircuit(5) | ||
preparation_circuit.h(0) | ||
preparation_circuit.cx(range(4), range(1, 5)) | ||
|
||
|
||
############################## | ||
# Full state tomography | ||
############################## | ||
|
||
# Get 2^5 optimized circuits for measurement on linear hardware connectivity | ||
qst = full_state_tomography_circuits(preparation_circuit, "linear") | ||
job = qiskit.execute(qst, backend=backend, shots=100) | ||
|
||
fitter = FullStateTomographyFitter(job.result(), qst) | ||
|
||
# We can get a dictionaray of expectation values | ||
print(fitter.expectation_values()) | ||
# Or the state matrix | ||
print(fitter.density_matrix()) | ||
|
||
|
||
# It is possible to measure marginals by passing the a list of qubits to measure | ||
qst = full_state_tomography_circuits(preparation_circuit, "all", measured_qubits=[0, 1]) | ||
job = qiskit.execute(qst, backend=backend, shots=100) | ||
|
||
fitter = FullStateTomographyFitter(job.result(), qst) | ||
print(fitter.density_matrix()) | ||
|
||
|
||
|
||
|
||
############################## | ||
# Measure only a stabilizer group | ||
############################## | ||
|
||
smc = stabilizer_measurement_circuit( | ||
preparation_circuit, | ||
Stabilizer(["XX", "YY"]), | ||
"all", | ||
measured_qubits=[0, 1] | ||
) | ||
job = qiskit.execute(smc, backend=backend, shots=100) | ||
|
||
fitter = StabilizerMeasurementFitter(job.result(), smc) | ||
print(fitter.expectation_values()) |
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,24 @@ | ||
# This test file is designated for running the example files | ||
# (and checking that they run without error). The example files | ||
# lie in the example folder and thus a call to for example | ||
# import htstabilizer.graph | ||
# results in an import error. | ||
# To solve this, we add the src/ directory to the sys path here | ||
|
||
import unittest | ||
import sys | ||
|
||
sys.path.insert(0, "src/") # simulate the package being installed, so that | ||
|
||
|
||
class TestExamples(unittest.TestCase): | ||
|
||
def test_readout_example(self): | ||
import examples.readout_circuit | ||
|
||
def test_tomography_example(self): | ||
import examples.state_tomography | ||
|
||
def test_compress_preparation_circuit(self): | ||
import examples.compress_preparation_circuit | ||
|