3.1 Magnetization Square on Z Direction#
Basic Usage#
a. Import the instances#
from qurry import ZDirMagnetSquare
experiment_zdir_magnet_square = ZDirMagnetSquare()
b. Preparing quantum circuit#
from qurry.recipe import Cat, TrivialParamagnet
circuits_dict = {
"trivialPM_2": TrivialParamagnet(2),
"trivialPM_4": TrivialParamagnet(4),
"trivialPM_6": TrivialParamagnet(6),
"trivialPM_8": TrivialParamagnet(8),
"cat_2": Cat(2),
"cat_4": Cat(4),
"cat_6": Cat(6),
"cat_8": Cat(8),
}
print("| trivial paramagnet and cat in 4 qubits:")
print(circuits_dict["trivialPM_4"])
print(circuits_dict["cat_4"])
| trivial paramagnet and cat in 4 qubits:
┌───┐
q_0: ┤ H ├
├───┤
q_1: ┤ H ├
├───┤
q_2: ┤ H ├
├───┤
q_3: ┤ H ├
└───┘
┌───┐
q_0: ┤ H ├──■────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──
└───┘┌─┴─┐
q_3: ───────────────┤ X ├
└───┘
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_zdir_magnet_square.measure(circuits_dict["cat_6"], shots=4096)
exp1
'f45c7388-20aa-4cb0-a47e-122836d992d4'
Each experiment result will be stored in a container .exps
.
experiment_zdir_magnet_square.exps[exp1]
<ZDirMagnetSquareExperiment(exp_id=f45c7388-20aa-4cb0-a47e-122836d992d4,
ZDirMagnetSquareArguments(exp_name='experiment.qurmagsq_magnet_square_zdir', num_qubits=6),
Commonparams(exp_id='f45c7388-20aa-4cb0-a47e-122836d992d4', 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:44:28', 'run.001': '2025-06-26 11:44:28'})),
unused_args_num=0,
analysis_num=1))>
For ZDirMagnetSquare
, its .analyze
in ZDirMagnetSquareExperiment
does not require any arguments, so its post-processing will be executed automatically after .measure
.
experiment_zdir_magnet_square.exps[exp1].reports
AnalysisContainer(length=1, {
0: <ZDirMSAnalysis(serial=0, ZDirMSAnalysisInput(), ZDirMSAnalysisContent(magnet_square=1.0, and others)), unused_args_num=0>})
report01 = experiment_zdir_magnet_square.exps[exp1].reports[0]
report01
<ZDirMSAnalysis(
serial=0,
ZDirMSAnalysisInput(),
ZDirMSAnalysisContent(magnet_square=1.0, and others)),
unused_args_num=0
)>
main01, side_product01 = report01.export()
print("| magnetization square", main01["magnet_square"])
for k, v in main01.items():
if "magnet_square" in k:
continue
print(f"| {k}: {v}")
| magnetization square 1.0
| num_qubits: 6
| shots: 4096
| taking_time: 0.00039123
| input: {}
| header: {'serial': 0, 'datetime': '2025-06-26 11:44:28', 'log': {}}
print("| side product is empty here:", side_product01)
| side product is empty here: {}
main
contains another keys "magnet_square_cells"
which is a dict,
It contains the magnetization square cells they correspond to the magnetization square.
print(main01["magnet_square_cells"])
{23: 1.0, 2: 1.0, 4: 1.0, 10: 1.0, 9: 1.0, 11: 1.0, 21: 1.0, 7: 1.0, 15: 1.0, 13: 1.0, 17: 1.0, 29: 1.0, 24: 1.0, 14: 1.0, 16: 1.0, 28: 1.0, 12: 1.0, 25: 1.0, 5: 1.0, 26: 1.0, 3: 1.0, 6: 1.0, 27: 1.0, 19: 1.0, 20: 1.0, 22: 1.0, 0: 1.0, 1: 1.0, 18: 1.0, 8: 1.0}
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_zdir_magnet_square.waves
WaveContainer({ 0: <qurry.recipe.simple.cat.Cat object at 0x7df95bb9f250>})
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.
for k, v in circuits_dict.items():
key_of_cirq = experiment_zdir_magnet_square.add(v, k)
print(f"| {k} added with key: {key_of_cirq}")
print(experiment_zdir_magnet_square.waves["cat_4"])
| trivialPM_2 added with key: trivialPM_2
| trivialPM_4 added with key: trivialPM_4
| trivialPM_6 added with key: trivialPM_6
| trivialPM_8 added with key: trivialPM_8
| cat_2 added with key: cat_2
| cat_4 added with key: cat_4
| cat_6 added with key: cat_6
| cat_8 added with key: cat_8
┌───┐
q_0: ┤ H ├──■────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──
└───┘┌─┴─┐
q_3: ───────────────┤ X ├
└───┘
If there is a circuit with the same name, it will be replaced by the new one.
print(experiment_zdir_magnet_square.add(circuits_dict["cat_4"], "cat_4"))
print(experiment_zdir_magnet_square.waves["cat_4"])
cat_4
┌───┐
q_0: ┤ H ├──■────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──
└───┘┌─┴─┐
q_3: ───────────────┤ X ├
└───┘
Otherwise, you will need to use replace="duplicate"
to prevent it from being replaced.
duplicated_case01 = experiment_zdir_magnet_square.add(
circuits_dict["cat_4"], "cat_4", replace="duplicate"
)
print(duplicated_case01)
print(experiment_zdir_magnet_square.waves[duplicated_case01])
cat_4.9
┌───┐
q_0: ┤ H ├──■────────────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■───────
└───┘┌─┴─┐
q_2: ──────────┤ X ├──■──
└───┘┌─┴─┐
q_3: ───────────────┤ X ├
└───┘
Now we have prepared the circuit and stored it in the container .waves
.
experiment_zdir_magnet_square.waves
WaveContainer({
0: <qurry.recipe.simple.cat.Cat object at 0x7df95bb9f250>,
'trivialPM_2': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7df95bb08830>,
'trivialPM_4': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7df95bb9ee90>,
'trivialPM_6': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7df95bb9efd0>,
'trivialPM_8': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7df95babd480>,
'cat_2': <qurry.recipe.simple.cat.Cat object at 0x7df95bb08440>,
'cat_4': <qurry.recipe.simple.cat.Cat object at 0x7df95bb9f110>,
'cat_6': <qurry.recipe.simple.cat.Cat object at 0x7df95bb9f250>,
'cat_8': <qurry.recipe.simple.cat.Cat object at 0x7df95babd5b0>,
'cat_4.9': <qurry.recipe.simple.cat.Cat object at 0x7df95bb9f110>})
Finally, we can execute the circuit and get the result.
exp2 = experiment_zdir_magnet_square.measure("cat_4", shots=4096)
exp2
'16d4e0f8-5b54-4e7e-93d8-722adc96e2c1'
experiment_zdir_magnet_square.exps[exp2]
<ZDirMagnetSquareExperiment(exp_id=16d4e0f8-5b54-4e7e-93d8-722adc96e2c1,
ZDirMagnetSquareArguments(exp_name='experiment.qurmagsq_magnet_square_zdir', num_qubits=4),
Commonparams(exp_id='16d4e0f8-5b54-4e7e-93d8-722adc96e2c1', target_keys=['cat_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:44:30', 'run.001': '2025-06-26 11:44:30'})),
unused_args_num=0,
analysis_num=1))>
report02 = experiment_zdir_magnet_square.exps[exp2].reports[0]
report02
<ZDirMSAnalysis(
serial=0,
ZDirMSAnalysisInput(),
ZDirMSAnalysisContent(magnet_square=1.0, and others)),
unused_args_num=0
)>
d. Export them after all#
exp1_id, exp1_files_info = experiment_zdir_magnet_square.exps[exp1].write(
save_location=".", # where to save files
)
exp1_files_info
{'folder': 'experiment.qurmagsq_magnet_square_zdir.001',
'qurryinfo': 'experiment.qurmagsq_magnet_square_zdir.001/qurryinfo.json',
'args': 'experiment.qurmagsq_magnet_square_zdir.001/args/experiment.qurmagsq_magnet_square_zdir.001.id=f45c7388-20aa-4cb0-a47e-122836d992d4.args.json',
'advent': 'experiment.qurmagsq_magnet_square_zdir.001/advent/experiment.qurmagsq_magnet_square_zdir.001.id=f45c7388-20aa-4cb0-a47e-122836d992d4.advent.json',
'legacy': 'experiment.qurmagsq_magnet_square_zdir.001/legacy/experiment.qurmagsq_magnet_square_zdir.001.id=f45c7388-20aa-4cb0-a47e-122836d992d4.legacy.json',
'reports': 'experiment.qurmagsq_magnet_square_zdir.001/reports/experiment.qurmagsq_magnet_square_zdir.001.id=f45c7388-20aa-4cb0-a47e-122836d992d4.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>