2.1 Wave Function Overlap by Hadamard Test#
Basic Usage#
a. Import the instances#
from qurry import WaveFunctionOverlap
experiment_hadamard = WaveFunctionOverlap(method="hadamard")
# or another short name
# from qurry import EchoListen
# experiment_hadamard = EchoListen(method="hadamard")
b. Preparing quantum circuit#
from qiskit import QuantumCircuit
from qurry.recipe import TrivialParamagnet, GHZ
sample01 = TrivialParamagnet(8)
print("| trivial paramagnet in 8 qubits:")
print(sample01)
| trivial paramagnet in 8 qubits:
┌───┐
q_0: ┤ H ├
├───┤
q_1: ┤ H ├
├───┤
q_2: ┤ H ├
├───┤
q_3: ┤ H ├
├───┤
q_4: ┤ H ├
├───┤
q_5: ┤ H ├
├───┤
q_6: ┤ H ├
├───┤
q_7: ┤ H ├
└───┘
sample02 = GHZ(8)
print("| GHZ in 8 qubits:")
print(sample02)
| GHZ in 8 qubits:
┌───┐
q_0: ┤ H ├──■────────────────────────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────────────────────────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──────────────────────
└───┘┌─┴─┐
q_3: ───────────────┤ X ├──■─────────────────
└───┘┌─┴─┐
q_4: ────────────────────┤ X ├──■────────────
└───┘┌─┴─┐
q_5: ─────────────────────────┤ X ├──■───────
└───┘┌─┴─┐
q_6: ──────────────────────────────┤ X ├──■──
└───┘┌─┴─┐
q_7: ───────────────────────────────────┤ X ├
└───┘
sample03 = QuantumCircuit(8)
sample03.x(range(0, 8, 2))
print("| Custom circuit:")
print(sample03)
| Custom circuit:
┌───┐
q_0: ┤ X ├
└───┘
q_1: ─────
┌───┐
q_2: ┤ X ├
└───┘
q_3: ─────
┌───┐
q_4: ┤ X ├
└───┘
q_5: ─────
┌───┐
q_6: ┤ X ├
└───┘
q_7: ─────
c. Execute the circuit#
i. Directly input the circuit#
After executing, it will return a uuid of experiment. You can use this uuid to get the result of the experiment.
exp1 = experiment_hadamard.measure(sample01, sample01, degree=4, shots=4096)
exp1
'4df2ed94-70e0-481b-b57e-5e43f329d0eb'
Each experiment result will be stored in a container .exps
.
experiment_hadamard.exps[exp1]
<EchoListenHadamardExperiment(exp_id=4df2ed94-70e0-481b-b57e-5e43f329d0eb,
EchoListenHadamardArguments(exp_name='experiment.degree_4_8.qurrech_hadamard', degree=(4, 8)),
Commonparams(exp_id='4df2ed94-70e0-481b-b57e-5e43f329d0eb', target_keys=[0, 1], shots=4096, backend=<AerSimulator('aer_simulator')>, run_args={}, transpile_args={}, tags=(), save_location=PosixPath('.'), serial=None, summoner_id=None, summoner_name=None, datetimes=DatetimeDict({'build': '2025-06-26 11:45:23', 'run.001': '2025-06-26 11:45:23'})),
unused_args_num=0,
analysis_num=1))>
For EntropyMeasure(method="hadamard")
, its .analyze
in EntropyMeasureHadamardExperiment
does not require any arguments, so its post-processing will be executed automatically after .measure
.
experiment_hadamard.exps[exp1].reports
AnalysisContainer(length=1, {
0: <ELHAnalysis(serial=0, ELHAnalysisInput(), ELHAnalysisContent(echo=1.0)), unused_args_num=1>})
report01 = experiment_hadamard.exps[exp1].reports[0]
report01
<ELHAnalysis(
serial=0,
ELHAnalysisInput(),
ELHAnalysisContent(echo=1.0)),
unused_args_num=1
)>
The result will be 1.0
for overlapping with the same state.
main01, side_product01 = report01.export()
main01
{'echo': 1.0,
'input': {},
'header': {'serial': 0, 'datetime': '2025-06-26 11:45:23', 'log': {}}}
ii. Add the circuits to container .waves
, then call them later.#
Since we have executed an experiment, the circuit we input in exp1
is stored in the container .waves
with serial number 0
.
experiment_hadamard.waves
WaveContainer({
0: <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7a3086600590>,
1: <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7a3086600590>})
But we can also add the circuit to the container .waves
with a custom name.
The name should be unique, otherwise it will be overwritten.
The method add
will return the actual name of the circuit in the container.
print(experiment_hadamard.add(sample02, "ghz_8"))
print(experiment_hadamard.waves["ghz_8"])
ghz_8
┌───┐
q_0: ┤ H ├──■────────────────────────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────────────────────────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──────────────────────
└───┘┌─┴─┐
q_3: ───────────────┤ X ├──■─────────────────
└───┘┌─┴─┐
q_4: ────────────────────┤ X ├──■────────────
└───┘┌─┴─┐
q_5: ─────────────────────────┤ X ├──■───────
└───┘┌─┴─┐
q_6: ──────────────────────────────┤ X ├──■──
└───┘┌─┴─┐
q_7: ───────────────────────────────────┤ X ├
└───┘
If there is a circuit with the same name, it will be replaced by the new one.
print(experiment_hadamard.add(sample03, "ghz_8"))
print(experiment_hadamard.waves["ghz_8"])
ghz_8
┌───┐
q_0: ┤ X ├
└───┘
q_1: ─────
┌───┐
q_2: ┤ X ├
└───┘
q_3: ─────
┌───┐
q_4: ┤ X ├
└───┘
q_5: ─────
┌───┐
q_6: ┤ X ├
└───┘
q_7: ─────
Otherwise, you will need to use replace="duplicate"
to prevent it from being replaced.
duplicated_case01 = experiment_hadamard.add(sample02, "ghz_8", replace="duplicate")
print(duplicated_case01)
print(experiment_hadamard.waves[duplicated_case01])
ghz_8.3
┌───┐
q_0: ┤ H ├──■────────────────────────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────────────────────────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──────────────────────
└───┘┌─┴─┐
q_3: ───────────────┤ X ├──■─────────────────
└───┘┌─┴─┐
q_4: ────────────────────┤ X ├──■────────────
└───┘┌─┴─┐
q_5: ─────────────────────────┤ X ├──■───────
└───┘┌─┴─┐
q_6: ──────────────────────────────┤ X ├──■──
└───┘┌─┴─┐
q_7: ───────────────────────────────────┤ X ├
└───┘
Now we have prepared the circuit and stored it in the container .waves
.
experiment_hadamard.waves
WaveContainer({
0: <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7a3086600590>,
1: <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7a3086600590>,
'ghz_8': <qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x7a30865fd010>,
'ghz_8.3': <qurry.recipe.simple.cat.GHZ object at 0x7a30866023c0>})
Finally, we can execute the circuit and get the result.
exp2 = experiment_hadamard.measure("ghz_8.3", sample01, degree=4, shots=4096)
exp2
'b4313e16-119c-4af5-a59e-5b30dcfa3fdc'
experiment_hadamard.exps[exp2]
<EchoListenHadamardExperiment(exp_id=b4313e16-119c-4af5-a59e-5b30dcfa3fdc,
EchoListenHadamardArguments(exp_name='experiment.degree_4_8.qurrech_hadamard', degree=(4, 8)),
Commonparams(exp_id='b4313e16-119c-4af5-a59e-5b30dcfa3fdc', target_keys=['ghz_8.3', 4], shots=4096, backend=<AerSimulator('aer_simulator')>, run_args={}, transpile_args={}, tags=(), save_location=PosixPath('.'), serial=None, summoner_id=None, summoner_name=None, datetimes=DatetimeDict({'build': '2025-06-26 11:45:25', 'run.001': '2025-06-26 11:45:25'})),
unused_args_num=0,
analysis_num=1))>
report02 = experiment_hadamard.exps[exp2].analyze()
report02
<ELHAnalysis(
serial=1,
ELHAnalysisInput(),
ELHAnalysisContent(echo=0.06787109375)),
unused_args_num=1
)>
d. Export them after all#
exp1_id, exp1_files_info = experiment_hadamard.exps[exp1].write(
save_location=".", # where to save files
)
exp1_files_info
{'folder': 'experiment.degree_4_8.qurrech_hadamard.001',
'qurryinfo': 'experiment.degree_4_8.qurrech_hadamard.001/qurryinfo.json',
'args': 'experiment.degree_4_8.qurrech_hadamard.001/args/experiment.degree_4_8.qurrech_hadamard.001.id=4df2ed94-70e0-481b-b57e-5e43f329d0eb.args.json',
'advent': 'experiment.degree_4_8.qurrech_hadamard.001/advent/experiment.degree_4_8.qurrech_hadamard.001.id=4df2ed94-70e0-481b-b57e-5e43f329d0eb.advent.json',
'legacy': 'experiment.degree_4_8.qurrech_hadamard.001/legacy/experiment.degree_4_8.qurrech_hadamard.001.id=4df2ed94-70e0-481b-b57e-5e43f329d0eb.legacy.json',
'reports': 'experiment.degree_4_8.qurrech_hadamard.001/reports/experiment.degree_4_8.qurrech_hadamard.001.id=4df2ed94-70e0-481b-b57e-5e43f329d0eb.reports.json'}
Post-Process Availablities and Version Info#
from qurry.process import AVAIBILITY_STATESHEET
AVAIBILITY_STATESHEET
| Qurrium version: 0.13.0
---------------------------------------------------------------------------
### Qurrium Post-Processing
- Backend Availability ................... Python Cython Rust JAX
- randomized_measure
- entangled_entropy.entropy_core_2 ....... Yes Depr. Yes No
- entangle_entropy.purity_cell_2 ......... Yes Depr. Yes No
- entangled_entropy_v1.entropy_core ...... Yes Depr. Yes No
- entangle_entropy_v1.purity_cell ........ Yes Depr. Yes No
- wavefunction_overlap.echo_core_2 ....... Yes Depr. Yes No
- wavefunction_overlap.echo_cell_2 ....... Yes Depr. Yes No
- wavefunction_overlap_v1.echo_core ...... Yes Depr. Yes No
- wavefunction_overlap_v1.echo_cell ...... Yes Depr. Yes No
- hadamard_test
- purity_echo_core ....................... Yes No Yes No
- magnet_square
- magnsq_core ............................ Yes No Yes No
- string_operator
- strop_core ............................. Yes No Yes No
- classical_shadow
- rho_m_core ............................. Yes No No Yes
- utils
- randomized ............................. Yes Depr. Yes No
- counts_process ......................... Yes No Yes No
- bit_slice .............................. Yes No Yes No
- dummy .................................. Yes No Yes No
- test ................................... Yes No Yes No
---------------------------------------------------------------------------
+ Yes ...... Working normally.
+ Error .... Exception occurred.
+ No ....... Not supported.
+ Depr. .... Deprecated.
---------------------------------------------------------------------------
by <Hoshi>