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
'fbb5a479-2679-4213-95a7-209c88dd5839'
Each experiment result will be stored in a container .exps
.
experiment_hadamard.exps[exp1]
<EntropyMeasureHadamardExperiment(exp_id=fbb5a479-2679-4213-95a7-209c88dd5839,
EntropyMeasureHadamardArguments(exp_name='experiment.degree_4_8.qurrent_hadamard', degree=(4, 8)),
Commonparams(exp_id='fbb5a479-2679-4213-95a7-209c88dd5839', 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-07-08 16:59:05', 'run.001': '2025-07-08 16:59:05'})),
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-07-08 16:59:05', '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 0x74e33d53cb90>})
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 0x74e33d53cb90>,
'ghz_8': <qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x74e33d4191f0>,
'ghz_8.2': <qurry.recipe.simple.cat.GHZ object at 0x74e33d6217c0>})
Finally, we can execute the circuit and get the result.
exp2 = experiment_hadamard.measure("ghz_8.2", degree=4, shots=4096)
exp2
'1c784095-05af-419b-848b-a7ebe8f9b45e'
experiment_hadamard.exps[exp2]
<EntropyMeasureHadamardExperiment(exp_id=1c784095-05af-419b-848b-a7ebe8f9b45e,
EntropyMeasureHadamardArguments(exp_name='experiment.degree_4_8.qurrent_hadamard', degree=(4, 8)),
Commonparams(exp_id='1c784095-05af-419b-848b-a7ebe8f9b45e', 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-07-08 16:59:09', 'run.001': '2025-07-08 16:59:09'})),
unused_args_num=0,
analysis_num=1))>
report02 = experiment_hadamard.exps[exp2].analyze()
report02
<EMHAnalysis(
serial=1,
EMHAnalysisInput(),
EMHAnalysisContent(purity=0.48681640625, entropy=1.0385503056018042)),
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=fbb5a479-2679-4213-95a7-209c88dd5839.args.json',
'advent': 'experiment.degree_4_8.qurrent_hadamard.001/advent/experiment.degree_4_8.qurrent_hadamard.001.id=fbb5a479-2679-4213-95a7-209c88dd5839.advent.json',
'legacy': 'experiment.degree_4_8.qurrent_hadamard.001/legacy/experiment.degree_4_8.qurrent_hadamard.001.id=fbb5a479-2679-4213-95a7-209c88dd5839.legacy.json',
'reports': 'experiment.degree_4_8.qurrent_hadamard.001/reports/experiment.degree_4_8.qurrent_hadamard.001.id=fbb5a479-2679-4213-95a7-209c88dd5839.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>