1.1 Entanglement Entropy by Hadamard Test#
Basic Usage#
a. Import the instances#
from qurry import EntropyMeasure
experiment_hadamard = EntropyMeasure(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, degree=4, shots=4096)
exp1
'53dc1032-8eb5-4d10-a6c3-37c5f48b0131'
Each experiment result will be stored in a container .exps
.
experiment_hadamard.exps[exp1]
<EntropyMeasureHadamardExperiment(exp_id=53dc1032-8eb5-4d10-a6c3-37c5f48b0131,
EntropyMeasureHadamardArguments(exp_name='experiment.degree_4_8.qurrent_hadamard', degree=(4, 8)),
Commonparams(exp_id='53dc1032-8eb5-4d10-a6c3-37c5f48b0131', target_keys=[0], 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:46:10', 'run.001': '2025-06-26 11:46:10'})),
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: <EMHAnalysis(serial=0, EMHAnalysisInput(), EMHAnalysisContent(purity=1.0, entropy=-0.0)), unused_args_num=1>})
report01 = experiment_hadamard.exps[exp1].reports[0]
report01
<EMHAnalysis(
serial=0,
EMHAnalysisInput(),
EMHAnalysisContent(purity=1.0, entropy=-0.0)),
unused_args_num=1
)>
main01, side_product01 = report01.export()
main01
{'purity': 1.0,
'entropy': np.float64(-0.0),
'input': {},
'header': {'serial': 0, 'datetime': '2025-06-26 11:46:10', '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 0x76ddf06e4590>})
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.2
┌───┐
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 0x76ddf06e4590>,
'ghz_8': <qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x76ddf06e1010>,
'ghz_8.2': <qurry.recipe.simple.cat.GHZ object at 0x76ddf06e63c0>})
Finally, we can execute the circuit and get the result.
exp2 = experiment_hadamard.measure("ghz_8.2", degree=4, shots=4096)
exp2
'0a91c631-6e67-4bac-b3a8-93bf0b3abc41'
experiment_hadamard.exps[exp2]
<EntropyMeasureHadamardExperiment(exp_id=0a91c631-6e67-4bac-b3a8-93bf0b3abc41,
EntropyMeasureHadamardArguments(exp_name='experiment.degree_4_8.qurrent_hadamard', degree=(4, 8)),
Commonparams(exp_id='0a91c631-6e67-4bac-b3a8-93bf0b3abc41', target_keys=['ghz_8.2'], 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:46:12', 'run.001': '2025-06-26 11:46:12'})),
unused_args_num=0,
analysis_num=1))>
report02 = experiment_hadamard.exps[exp2].analyze()
report02
<EMHAnalysis(
serial=1,
EMHAnalysisInput(),
EMHAnalysisContent(purity=0.49609375, entropy=1.011315313227834)),
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.qurrent_hadamard.001',
'qurryinfo': 'experiment.degree_4_8.qurrent_hadamard.001/qurryinfo.json',
'args': 'experiment.degree_4_8.qurrent_hadamard.001/args/experiment.degree_4_8.qurrent_hadamard.001.id=53dc1032-8eb5-4d10-a6c3-37c5f48b0131.args.json',
'advent': 'experiment.degree_4_8.qurrent_hadamard.001/advent/experiment.degree_4_8.qurrent_hadamard.001.id=53dc1032-8eb5-4d10-a6c3-37c5f48b0131.advent.json',
'legacy': 'experiment.degree_4_8.qurrent_hadamard.001/legacy/experiment.degree_4_8.qurrent_hadamard.001.id=53dc1032-8eb5-4d10-a6c3-37c5f48b0131.legacy.json',
'reports': 'experiment.degree_4_8.qurrent_hadamard.001/reports/experiment.degree_4_8.qurrent_hadamard.001.id=53dc1032-8eb5-4d10-a6c3-37c5f48b0131.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>