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
'a73abfed-daa7-4675-b931-ad864344665e'
Each experiment result will be stored in a container .exps.
experiment_zdir_magnet_square.exps[exp1]
<ZDirMagnetSquareExperiment(exp_id=a73abfed-daa7-4675-b931-ad864344665e,
ZDirMagnetSquareArguments(exp_name='experiment.qurmagsq_magnet_square_zdir', num_qubits=6),
Commonparams(exp_id='a73abfed-daa7-4675-b931-ad864344665e', 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:56:16', 'run.001': '2025-07-08 16:56:16'})),
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.000593496
| input: {}
| header: {'serial': 0, 'datetime': '2025-07-08 16:56:16', '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"])
{5: 1.0, 8: 1.0, 26: 1.0, 0: 1.0, 7: 1.0, 29: 1.0, 28: 1.0, 2: 1.0, 11: 1.0, 16: 1.0, 17: 1.0, 23: 1.0, 22: 1.0, 4: 1.0, 6: 1.0, 10: 1.0, 18: 1.0, 25: 1.0, 24: 1.0, 19: 1.0, 27: 1.0, 1: 1.0, 20: 1.0, 12: 1.0, 3: 1.0, 15: 1.0, 13: 1.0, 14: 1.0, 9: 1.0, 21: 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 0x7546bf807d40>})
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 0x7546bf807d40>,
'trivialPM_2': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7547b4447500>,
'trivialPM_4': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7546bf9cce60>,
'trivialPM_6': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7546bf807770>,
'trivialPM_8': <qurry.recipe.simple.paramagnet.TrivialParamagnet object at 0x7546bf807650>,
'cat_2': <qurry.recipe.simple.cat.Cat object at 0x7546bf807a70>,
'cat_4': <qurry.recipe.simple.cat.Cat object at 0x7546bf807c80>,
'cat_6': <qurry.recipe.simple.cat.Cat object at 0x7546bf807d40>,
'cat_8': <qurry.recipe.simple.cat.Cat object at 0x7546bf807e90>,
'cat_4.9': <qurry.recipe.simple.cat.Cat object at 0x7546bf807c80>})
Finally, we can execute the circuit and get the result.
exp2 = experiment_zdir_magnet_square.measure("cat_4", shots=4096)
exp2
'fec1b361-1b37-421e-b178-0a96a3d5a1f3'
experiment_zdir_magnet_square.exps[exp2]
<ZDirMagnetSquareExperiment(exp_id=fec1b361-1b37-421e-b178-0a96a3d5a1f3,
ZDirMagnetSquareArguments(exp_name='experiment.qurmagsq_magnet_square_zdir', num_qubits=4),
Commonparams(exp_id='fec1b361-1b37-421e-b178-0a96a3d5a1f3', 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-07-08 16:56:20', 'run.001': '2025-07-08 16:56:20'})),
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.002',
'qurryinfo': 'experiment.qurmagsq_magnet_square_zdir.002/qurryinfo.json',
'args': 'experiment.qurmagsq_magnet_square_zdir.002/args/experiment.qurmagsq_magnet_square_zdir.002.id=a73abfed-daa7-4675-b931-ad864344665e.args.json',
'advent': 'experiment.qurmagsq_magnet_square_zdir.002/advent/experiment.qurmagsq_magnet_square_zdir.002.id=a73abfed-daa7-4675-b931-ad864344665e.advent.json',
'legacy': 'experiment.qurmagsq_magnet_square_zdir.002/legacy/experiment.qurmagsq_magnet_square_zdir.002.id=a73abfed-daa7-4675-b931-ad864344665e.legacy.json',
'reports': 'experiment.qurmagsq_magnet_square_zdir.002/reports/experiment.qurmagsq_magnet_square_zdir.002.id=a73abfed-daa7-4675-b931-ad864344665e.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>