├── examples ├── SchWARMAPaperExamples │ ├── Figure 3 │ │ ├── src │ │ │ ├── check_circuits.pdf │ │ │ ├── check_circuits.png │ │ │ ├── compiled_cnot.pdf │ │ │ ├── compiled_cnot.png │ │ │ ├── output │ │ │ │ ├── xsyn │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-6.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-0-7.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-6.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-1-7.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-6.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-2-7.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-6.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-3-7.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-6.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-4-7.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-0.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-1.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-2.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-3.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-4.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-5.p │ │ │ │ │ ├── surface_xsyndrome_xyznoise-5-6.p │ │ │ │ │ └── surface_xsyndrome_xyznoise-5-7.p │ │ │ │ └── zsyn │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-6.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-0-7.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-6.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-1-7.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-6.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-2-7.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-6.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-3-7.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-6.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-4-7.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-0.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-1.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-2.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-3.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-4.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-5.p │ │ │ │ │ ├── surface_zsyndrome_xyznoise-5-6.p │ │ │ │ │ └── surface_zsyndrome_xyznoise-5-7.p │ │ │ ├── submit_xsyn.sh │ │ │ ├── submit_zsyn.sh │ │ │ ├── Gates.py │ │ │ ├── qutip_gates.py │ │ │ ├── MultiAxisDephasingPMD.py │ │ │ ├── circuit.py │ │ │ └── qecc.py │ │ └── README │ ├── Figure S5 │ │ ├── data │ │ │ ├── grover_dephasing_corr_RC_Nq2_NN4000_Sw0.0010_NC10.00.p │ │ │ └── grover_dephasing_schwarma_RC_corr_Nq2_NN4000_NNsch100_Sw0.0010_NC7.57-v0.p │ │ └── aqc_implementations.py │ └── Figure 2.ipynb ├── 1_StateAndChannelDemo.ipynb ├── 3_PMDExample.ipynb ├── 6_DynamicalDecouplingExample.ipynb ├── 2_SimulationDemo.ipynb ├── 4_ExpandedChannelDemo.ipynb └── 5_CorrelatedNoiseExamples.ipynb ├── setup.py ├── LICENSE ├── tests ├── __init__.py ├── test_ham.py ├── test_ARMA.py ├── test_exotic_pmds.py ├── test_noise.py ├── test_qutrit_simulation.py ├── test_SchWAR.py ├── test_basis.py ├── test_simulation_outputs.py ├── test_SchWMA.py ├── test_SchWARMA.py ├── test_SchWARMA_conversion.py ├── test_random_uniform.py ├── test_quantum_channel_ops.py ├── test_quantum_state_dtype.py └── test_channel_multi_qudit_xforms.py ├── mezze ├── random │ ├── SchWARMA │ │ └── __init__.py │ ├── uniform │ │ ├── __init__.py │ │ └── uniform.py │ └── __init__.py ├── tfq │ ├── __init__.py │ └── helpers.py ├── core.py ├── __init__.py ├── controls.py ├── metrics.py └── lindblad.py └── README.md /examples/SchWARMAPaperExamples/Figure 3/src/check_circuits.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/check_circuits.pdf -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/check_circuits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/check_circuits.png -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/compiled_cnot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/compiled_cnot.pdf -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/compiled_cnot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/compiled_cnot.png -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-0-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-1-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-2-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-3-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-4-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/xsyn/surface_xsyndrome_xyznoise-5-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-0-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-1-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-2-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-3-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-4-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-0.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-1.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-1.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-2.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-2.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-3.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-3.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-4.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-4.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-5.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-5.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-6.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-6.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-7.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure 3/src/output/zsyn/surface_zsyndrome_xyznoise-5-7.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure S5/data/grover_dephasing_corr_RC_Nq2_NN4000_Sw0.0010_NC10.00.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure S5/data/grover_dephasing_corr_RC_Nq2_NN4000_Sw0.0010_NC10.00.p -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure S5/data/grover_dephasing_schwarma_RC_corr_Nq2_NN4000_NNsch100_Sw0.0010_NC7.57-v0.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mezze-team/mezze/HEAD/examples/SchWARMAPaperExamples/Figure S5/data/grover_dephasing_schwarma_RC_corr_Nq2_NN4000_NNsch100_Sw0.0010_NC7.57-v0.p -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright (C) 2015-2017 JHU/APL 4 | # 5 | 6 | from setuptools import setup, find_packages 7 | 8 | # 9 | # Install the package using distutils 10 | # 11 | 12 | setup( 13 | name='mezze', 14 | version='0.0.1', 15 | description='Mezze Quantum Simulator', 16 | author='Johns Hopkins University Applied Physics Laboratory', 17 | author_email='kevin.schultz@jhuapl.edu', 18 | url='http://jhuapl.edu', 19 | packages=find_packages(), 20 | install_requires=[ 21 | 'cirq', 22 | 'numpy', 23 | 'scipy', 24 | ], 25 | extras_require={ 26 | 'zne': ['mitiq','tensorflow','tensorflow-quantum'], 27 | 'tfq': ['tensorflow','tensorflow-quantum'], 28 | 'qsim': ['qsimcirq'] 29 | }, 30 | classifiers=[ 31 | 'Development Status :: Beta', 32 | 'Environment :: Console', 33 | 'Operating System :: POSIX', 34 | 'Operating System :: MacOS :: MacOS X', 35 | 'Operating System :: Microsoft :: Windows', 36 | 'Programming Language :: Python' 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/README: -------------------------------------------------------------------------------- 1 | For a fairly gentle intoduction to using SchWARMA within a circuit model of quantum computing, look through the SurfaceSyndromeSchWARMAExample.ipynb example. 2 | 3 | The two python scripts SurfaceXSyndrome.py and SurfaceYSyndrome.py files were the scripts used to generate Fig. 3 in arXiv:xxxx.xxxxx. Example PBS bash scripts that call those files to generate the plots are given in the two bash scripts. The calling procedure is the same for both: 4 | python SurfaceXSyndrome.py 5 | python SurfaceZSyndrome.py 6 | where = [0,1,...,5] inclusive, = [0,1,...,7] inclusive, and is the directory to dump the output files. 7 | 8 | The results can be plotting by using the command: 9 | python plot_syndrome_results --savefig --syndrome 10 | The optional argument --savefig causes all the output figures to be saved in the directory. 11 | The optional argument --syndrome X makes the titles specific to X syndromes and --syndrome Z makes the titles specific to Z syndromes. 12 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/submit_xsyn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #$ -N SurfaceXSyndrome 3 | #$ -cwd 4 | ## Set this to number of jobs (number of samples below) 5 | #$ -t 1-48 6 | 7 | # This job is created by using an array job. This means that we index into the noise amplitude and noise correlation using the single index 8 | # SGE_TASK_ID. This ID range, listed above, must span between 1-num_jobs where num_jobs=num_noise_corr*num_noise_amp. These numbers 9 | # currently need to match what is in the python code. I can probably make this more robust, but this is how I'm doing it for now. 10 | # BE CAREFUL! 11 | 12 | savedir=$1"/" 13 | # Get output directory 14 | if [ -z "$1" ] 15 | then 16 | echo "No directory specified. Using output/" 17 | savedir="output/" 18 | fi 19 | 20 | mkdir -p $savedir 21 | 22 | echo "Task ID is $SGE_TASK_ID" 23 | 24 | num_bw=8 25 | 26 | # i is noise_amp and j is noise_corr 27 | SGE_TASK_ID_MINUS_ONE=$((SGE_TASK_ID -1)) 28 | i=$((SGE_TASK_ID_MINUS_ONE / num_bw)) 29 | j=$((SGE_TASK_ID_MINUS_ONE % num_bw)) 30 | 31 | cp MultiAxisDephasingPMD.py $savedir"/" 32 | cp SurfaceXSyndrome.py $savedir"/" 33 | 34 | echo "python \"SurfaceXSyndrome.py $i $j $savedir\" -logfile "$savedir"logfile_"$i"_"$j".out" 35 | python SurfaceXSyndrome.py $i $j $savedir -logfile $savedir"logfile_"$i"_"$j".out" 1> $savedir"surface_xsyn_"$i"_"$j".stdout" 2> $savedir"surface_xsyn_"$i"_"$j".stderr" 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2021 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/submit_zsyn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #$ -m bea 3 | #$ -N SurfaceZSyndrome 4 | #$ -cwd 5 | ## Set this to number of jobs (number of samples below) 6 | #$ -t 1-48 7 | 8 | # This job is created by using an array job. This means that we index into the noise amplitude and noise correlation using the single index 9 | # SGE_TASK_ID. This ID range, listed above, must span between 1-num_jobs where num_jobs=num_noise_corr*num_noise_amp. These numbers 10 | # currently need to match what is in the python code. I can probably make this more robust, but this is how I'm doing it for now. 11 | # BE CAREFUL! 12 | 13 | savedir=$1"/" 14 | # Get output directory 15 | if [ -z "$1" ] 16 | then 17 | echo "No directory specified. Using output/" 18 | savedir="output/" 19 | fi 20 | 21 | mkdir -p $savedir 22 | 23 | echo "Task ID is $SGE_TASK_ID" 24 | 25 | num_bw=8 26 | 27 | # i is noise_amp and j is noise_corr 28 | SGE_TASK_ID_MINUS_ONE=$((SGE_TASK_ID -1)) 29 | i=$((SGE_TASK_ID_MINUS_ONE / num_bw)) 30 | j=$((SGE_TASK_ID_MINUS_ONE % num_bw)) 31 | 32 | 33 | cp MultiAxisDephasingPMD.py $savedir"/" 34 | cp SurfaceZSyndrome.py $savedir"/" 35 | 36 | echo "python \"SurfaceZSyndrome.py $i $j $savedir\" -logfile "$savedir"logfile_"$i"_"$j".out" 37 | python SurfaceZSyndrome.py $i $j $savedir -logfile $savedir"logfile_"$i"_"$j".out" 1> $savedir"surface_zsyn_"$i"_"$j".stdout" 2> $savedir"surface_xsyn_"$i"_"$j".stderr" 38 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | -------------------------------------------------------------------------------- /mezze/random/SchWARMA/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2020 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from .SchWARMA import * 24 | -------------------------------------------------------------------------------- /mezze/random/uniform/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2020 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from .uniform import * 24 | -------------------------------------------------------------------------------- /mezze/random/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2020 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from . import uniform 24 | from . import SchWARMA 25 | -------------------------------------------------------------------------------- /mezze/tfq/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2020 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from .simulate import * 24 | from .inference import * 25 | from .filter_fcn import * 26 | from .helpers import * 27 | -------------------------------------------------------------------------------- /mezze/core.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | #Single qubit Pauli operators 24 | s_i = [[1,0],[0,1]] 25 | s_x = [[0,1],[1,0]] 26 | s_y = [[0,-1j],[1j,0]] 27 | s_z = [[1,0],[0,-1]] 28 | 29 | def is_multi_qubit(num_qubit): 30 | return num_qubit >= 2 31 | -------------------------------------------------------------------------------- /mezze/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from .simulation import Simulation, SimulationConfig 24 | from .hamiltonian import HamiltonianFunction, PrecomputedHamiltonian, HamiltonianIteratorInterface 25 | from .pmd import PMD 26 | from .implementations import * 27 | from .controls import * 28 | from .noise import Noise 29 | -------------------------------------------------------------------------------- /mezze/controls.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import numpy as np 24 | 25 | def get_zero_control(num_steps): 26 | return np.zeros(num_steps) 27 | 28 | def get_pi_pulse_control(num_steps, gate_duration): 29 | return np.ones(num_steps) * np.pi / gate_duration 30 | 31 | def get_piover2_pulse_control(num_steps, gate_duration): 32 | return np.ones(num_steps) * np.pi / (2.0 * gate_duration) 33 | 34 | def get_theta_pulse_control(num_steps, gate_duration, theta): 35 | return np.ones(num_steps) * theta / gate_duration 36 | 37 | -------------------------------------------------------------------------------- /tests/test_ham.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.hamiltonian as ham 25 | 26 | class TestHam(unittest.TestCase): 27 | 28 | def test_attribute_pass_thru(self): 29 | def pmd():pass 30 | pmd.xtalk = 36 31 | 32 | h = ham.HamiltonianFunction(pmd) 33 | 34 | self.assertEqual(pmd.xtalk, h.xtalk) 35 | 36 | try: 37 | h.unknown 38 | except AttributeError: 39 | return 40 | self.assertTrue(False, "HamlitonianFunction object failed to throw exception on unknown attribute") 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/Gates.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Dec 21 09:32:35 2015 4 | 5 | @author: dclader 6 | """ 7 | 8 | from circuit import * 9 | 10 | class Gates(UARCircuitSimulator): 11 | """ 12 | Class to build a circuit and simulate it using the UAR simulator code 13 | """ 14 | def __init__(self, pmd, config): 15 | 16 | self._gate_defs = {'I': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((0.0,),)}, 17 | 'I2': {'Control': ((0,),), 'Time': (2.0,), 'Theta': ((0.0,),)}, 18 | 'I3': {'Control': ((0,),), 'Time': (3.0,), 'Theta': ((0.0,),)}, 19 | 'I4': {'Control': ((0,),), 'Time': (4.0,), 'Theta': ((0.0,),)}, 20 | 'XI': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((np.pi,),)}, 21 | 'X': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((np.pi/2.0,),)}, 22 | 'Y': {'Control': ((1,),), 'Time': (1.0,), 'Theta': ((np.pi/2.0,),)}, 23 | 'ZZ90': {'Control': ((2,),), 'Time': (4.0,), 'Theta': ((-np.pi/4.0,),)}, 24 | 'S': {'Control': ((2,),), 'Time': (1.0,), 'Theta': ((np.pi/4.0,),)}, 25 | 'H': {'Control': ((1,),(0,)), 'Time': (0.5,0.5), 'Theta': ((np.pi/4.0,),(np.pi/2.0,))}, 26 | 'Z90H': {'Control': ((1,), (0,)), 'Time': (0.5, 0.5), 'Theta': ((np.pi / 4.0,), (-np.pi / 4.0,))}, 27 | 'H2': {'Control': ((0,),(1,)), 'Time': (0.5,0.5), 'Theta': ((np.pi/2.0,),(-np.pi/4.0,))}} 28 | 29 | #self._gate_defs = {'I': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((0.0,),)}, 30 | # 'P': {'Control': ((2,),), 'Time': (1.0,), 'Theta': ((np.pi/4.0,),)}, 31 | # 'H': {'Control': ((1,),(0,)), 'Time': (0.5,0.5), 'Theta': ((np.pi/4.0,),(np.pi/2.0,))}} 32 | 33 | UARCircuitSimulator.__init__(self, pmd, config, self._gate_defs) 34 | 35 | 36 | def get_gate_names(self): 37 | return self._gate_defs.keys() 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /mezze/metrics.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import scipy.linalg as la 24 | import numpy as np 25 | from .channel import _vec 26 | 27 | def fidelity(A,B): 28 | AA = A.density_matrix() 29 | BB = B.density_matrix() 30 | 31 | sqA = la.sqrtm(AA) 32 | return np.trace(np.real(la.sqrtm(sqA@BB@sqA)))**2 33 | 34 | def infidelity(A,B): 35 | return 1. - fidelity(A,B) 36 | 37 | def process_fidelity(A,B): 38 | if A.rank() == 1: 39 | return process_fidelity_to_unitary(B,A) 40 | elif B.rank() == 1: 41 | return process_fidelity_to_unitary(A,B) 42 | else: 43 | return fidelity(A.Jamiliokowski(),B.Jamiliokowski()) 44 | 45 | def process_fidelity_to_unitary(A,U): 46 | N = U.kraus()[0].shape[0] 47 | 48 | return 1./N**2*np.real(_vec(U.kraus()[0]).conj().T@A.choi()@_vec(U.kraus()[0]))[0,0] 49 | 50 | def process_infidelity(A,B): 51 | return 1. - process_fidelity(A,B) 52 | 53 | def process_infidelity_to_unitary(A,U): 54 | return 1. - process_fidelity_to_unitary(A,U) 55 | 56 | def unitarity(A): 57 | P = A.ptm()[1:,1:] 58 | d = np.sqrt(P.shape[0]+1) 59 | 60 | return 1./(d**2-1)*np.trace(P.conj().T@P) 61 | -------------------------------------------------------------------------------- /tests/test_ARMA.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | from mezze.random.SchWARMA import ARMA 25 | import numpy as np 26 | 27 | class TestARMA(unittest.TestCase): 28 | 29 | def test_init_and_step(self): 30 | model = ARMA(a = [1,2,3], b = [4,5]) 31 | 32 | self.assertTrue(np.all(model.a == [1,2,3]) and \ 33 | np.all(model.b == [4,5])) 34 | 35 | for i in range(100): 36 | model.step(np.random.randn(1)) 37 | 38 | #now check other inputs 39 | model.step(1.) 40 | model.step(0) 41 | model.step([2]) 42 | 43 | def test_MA_in_depth(self): 44 | model = ARMA( a=[],b = [1., .5, .25]) 45 | 46 | y = model.step(1) 47 | 48 | self.assertEqual(y,1) 49 | 50 | y = model.step(2) 51 | 52 | self.assertEqual(y, 2.5) 53 | 54 | y = model.step(3) 55 | 56 | self.assertEqual(y, 4.25) 57 | 58 | y = model.step(0) 59 | 60 | self.assertEqual(y,2) 61 | 62 | def test_AR_in_depth(self): 63 | 64 | model = ARMA(a = [1,.5], b = [1]) 65 | 66 | y = model.step(1) 67 | 68 | self.assertEqual(y,1) 69 | 70 | y = model.step(1) 71 | 72 | self.assertEqual(y,2) 73 | 74 | y = model.step(1) 75 | 76 | self.assertEqual(y,3.5) 77 | 78 | if __name__ == '__main__': 79 | unittest.main() 80 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure S5/aqc_implementations.py: -------------------------------------------------------------------------------- 1 | from mezze.pmd import PMD 2 | import mezze.core as uar 3 | import scipy.special 4 | import numpy as np 5 | 6 | 7 | class LZSTransverse(PMD): 8 | def __init__(self, noise_amp=0, corr_time=1): 9 | num_qubits = 1 10 | self.num_qubits = num_qubits 11 | single_control_dim = 2 12 | single_noise_dim = 1 13 | num_lindblad = 0 14 | two_control_dim = 0 15 | two_noise_dim = 0 16 | PMD.__init__(self, single_control_dim, single_noise_dim, num_lindblad, num_qubits, two_control_dim, two_noise_dim) 17 | self.single_qubit_control[0][0] = lambda c, gamma: 0 18 | self.single_qubit_control[0][1] = lambda c, gamma: c[0]/2 19 | self.single_qubit_control[0][3] = lambda c, gamma: c[1]/2 20 | 21 | self.single_qubit_noise[1] = lambda c,gamma: gamma[0] 22 | 23 | self.noise_hints[0] = {'type':'gauss', 'amp': noise_amp, 'ham_value': 1, 'corr_time': corr_time, 'ctrl': False} 24 | 25 | 26 | class LZNTransverse(PMD): 27 | def __init__(self, basis): 28 | num_qubits = 1 29 | self.num_qubits = num_qubits 30 | single_control_dim = 2 31 | single_noise_dim = 1 32 | num_lindblad = 0 33 | two_control_dim = 0 34 | two_noise_dim = 0 35 | PMD.__init__(self, single_control_dim, single_noise_dim, num_lindblad, num_qubits, two_control_dim, two_noise_dim) 36 | self.basis = basis 37 | self.single_qubit_control[0][0] = lambda c, gamma: c[0] 38 | self.single_qubit_control[0][1] = lambda c, gamma: c[1] 39 | 40 | # Noise 41 | self.single_qubit_noise[2] = lambda c,gamma: gamma[0] 42 | self.noise_hints[0] = {'type':'gauss', 'amp': 0.01, 'ham_value': 1, 'corr_time': 2.0, 'ctrl': False} 43 | 44 | 45 | 46 | class DephasingGrover(PMD): 47 | def __init__(self, num_qubits, init_state, marked_state, O_noise): 48 | self.real_num_qubits = 1 49 | control_dim = 2 50 | noise_dim = 1 51 | num_lindblad = 0 52 | 53 | PMD.__init__(self, control_dim, noise_dim, num_lindblad, self.real_num_qubits) 54 | 55 | Iden = np.identity(2**num_qubits) 56 | init_projector = init_state @ np.conjugate(np.transpose(init_state)) 57 | H0 = Iden - init_projector 58 | marked_projector = marked_state @ np.conjugate(np.transpose(marked_state)) 59 | Hp = Iden - marked_projector 60 | self.basis = [H0, Hp, O_noise] 61 | 62 | # c = [A(t), B(t)] 63 | self.single_qubit_control[0][0] = lambda c, gamma: c[0] 64 | self.single_qubit_control[0][1] = lambda c, gamma: c[1] 65 | 66 | # Noise 67 | self.single_qubit_noise[2] = lambda c,gamma: gamma[0] 68 | self.noise_hints[0] = {'type':'gauss', 'amp': 0.01, 'ham_value': 1, 'corr_time': 2.0, 'ctrl': False} -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/qutip_gates.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.linalg as la 3 | import qutip as qt 4 | from mezze.channel import _sigmaI, _sigmaX, _sigmaY, _sigmaZ 5 | 6 | def zz_gate(arg_value): 7 | # ZZ interaction 8 | mat = np.zeros((4, 4), dtype=np.complex) 9 | mat[0, 0] = mat[3, 3] = np.exp(-0.5j*arg_value) 10 | mat[1, 1] = mat[2, 2] = np.exp(0.5j*arg_value) 11 | return qt.Qobj(mat, dims=[[2, 2], [2, 2]]) 12 | 13 | def xyz_gate(arg_value): 14 | mat = la.expm(-0.5j * (arg_value[0] * _sigmaX + arg_value[1] * _sigmaY +arg_value[2] * _sigmaZ)) 15 | return qt.Qobj(mat, dims=[[2], [2]]) 16 | 17 | def add_qtcnot(qcirc, ctrl, targ, xerr=None, yerr=None, zerr=None): 18 | qcirc.add_gate("SNOT", targets=[targ]) 19 | for i in range(qcirc.N): 20 | xerrval = xerr[i][0] if xerr is not None else 0.0 21 | yerrval = yerr[i][0] if yerr is not None else 0.0 22 | zerrval = zerr[i][0] if zerr is not None else 0.0 23 | qcirc.add_gate("XYZ", targets=[i], arg_value=[xerrval, yerrval, zerrval]) 24 | 25 | qcirc.add_gate("CZZ", arg_value=-np.pi / 2.0, targets=[ctrl, targ], arg_label=r'\frac{\pi}{2}') 26 | for i in range(qcirc.N): 27 | for j in range(4): 28 | xerrval = xerr[i][1+j] if xerr is not None else 0.0 29 | yerrval = yerr[i][1+j] if yerr is not None else 0.0 30 | zerrval = zerr[i][1+j] if zerr is not None else 0.0 31 | qcirc.add_gate("XYZ", targets=[i], arg_value=[xerrval, yerrval, zerrval]) 32 | 33 | qcirc.add_gate("RY", targets=[targ], arg_value=np.pi / 2.0, arg_label=r'\frac{\pi}{2}') 34 | qcirc.add_gate("RX", targets=[targ], arg_value=-np.pi / 2.0, arg_label=r'\frac{\pi}{2}') 35 | for i in range(qcirc.N): 36 | xerrval = xerr[i][5] if xerr is not None else 0.0 37 | yerrval = yerr[i][5] if yerr is not None else 0.0 38 | zerrval = zerr[i][5] if zerr is not None else 0.0 39 | qcirc.add_gate("XYZ", targets=[i], arg_value=[xerrval, yerrval, zerrval]) 40 | 41 | def add_qtzz(qcirc, ctrl, targ, xerr=None, yerr=None, zerr=None): 42 | qcirc.add_gate("CZZ", arg_value=-np.pi / 2.0, targets=[ctrl, targ], arg_label=r'\frac{\pi}{2}') 43 | for i in range(qcirc.N): 44 | for j in range(4): 45 | xerrval = xerr[i][j] if xerr is not None else 0.0 46 | yerrval = yerr[i][j] if yerr is not None else 0.0 47 | zerrval = zerr[i][j] if zerr is not None else 0.0 48 | qcirc.add_gate("XYZ", targets=[i], arg_value=[xerrval, yerrval, zerrval]) 49 | 50 | def add_qth(qcirc, targ, xerr=None, yerr=None, zerr=None): 51 | qcirc.add_gate("SNOT", targets=[targ]) 52 | for i in range(qcirc.N): 53 | xerrval = xerr[i] if xerr is not None else 0.0 54 | yerrval = yerr[i] if yerr is not None else 0.0 55 | zerrval = zerr[i] if zerr is not None else 0.0 56 | qcirc.add_gate("XYZ", targets=[i], arg_value=[xerrval, yerrval, zerrval]) -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/MultiAxisDephasingPMD.py: -------------------------------------------------------------------------------- 1 | from mezze.pmd import PMD 2 | import mezze.core as uar 3 | import scipy.special 4 | import numpy as np 5 | 6 | 7 | class MultiAxisDephasing(PMD): 8 | def __init__(self, num_qs, amp, corr_time): 9 | num_qubits = num_qs 10 | single_control_dim = 3 11 | single_noise_dim = 3 12 | two_control_dim = 1 13 | two_noise_dim = 0 14 | num_lindblad = 0 15 | PMD.__init__(self, single_control_dim, single_noise_dim, num_lindblad, num_qubits, two_control_dim, two_noise_dim) 16 | 17 | self.single_qubit_control[0][1] = lambda c, gamma: c[0] 18 | self.single_qubit_control[0][2] = lambda c, gamma: c[1] 19 | #self.single_qubit_control[0][3] = lambda c, gamma: c[2] 20 | 21 | self.single_qubit_noise[1] = lambda c, gamma: gamma[0] / 2.0 22 | self.single_qubit_noise[2] = lambda c, gamma: gamma[1] / 2.0 23 | self.single_qubit_noise[3] = lambda c, gamma: gamma[2] / 2.0 24 | #self.noise_hints[0]={'type':'gauss', 'amp': noise_amp, 'ham_value': 1, 'corr_time': corr_time, 'ctrl': False} 25 | #self.noise_hints = [{'type': 'gauss', 'amp': noise_amp, 'ham_value': 1, 'corr_time': corr_time, 'ctrl': False}]*num_qubits 26 | for i in range(num_qubits*3): 27 | self.noise_hints[i]['type'] = 'gauss' 28 | if len(amp) == 1: 29 | for i in range(num_qubits * 3): 30 | self.noise_hints[i]['amp'] = amp[0] 31 | self.noise_hints[i]['corr_time'] = corr_time[0] 32 | else: 33 | for i in range(num_qubits): 34 | self.noise_hints[3*i]['amp'] = amp[0] 35 | self.noise_hints[1 + 3*i]['amp'] = amp[1] 36 | self.noise_hints[2 + 3*i]['amp'] = amp[2] 37 | self.noise_hints[3 * i]['corr_time'] = corr_time[0] 38 | self.noise_hints[1 + 3 * i]['corr_time'] = corr_time[1] 39 | self.noise_hints[2 + 3 * i]['corr_time'] = corr_time[2] 40 | 41 | self.two_qubit_control[0][3][3] = lambda c, gamma: c[0] 42 | 43 | 44 | class SingleQubitDephasing(PMD): 45 | def __init__(self, noise_amp, corr_time): 46 | num_qubits = 1 47 | single_control_dim = 3 48 | single_noise_dim = 1 49 | two_control_dim = 0 50 | two_noise_dim = 0 51 | num_lindblad = 0 52 | PMD.__init__(self, single_control_dim, single_noise_dim, num_lindblad, num_qubits, two_control_dim, two_noise_dim) 53 | 54 | self.single_qubit_control[0][1] = lambda c, gamma: c[0] 55 | self.single_qubit_control[0][2] = lambda c, gamma: c[1] 56 | #self.single_qubit_control[0][3] = lambda c, gamma: c[2] 57 | 58 | self.single_qubit_noise[1] = lambda c, gamma: gamma[0] 59 | self.noise_hints[0]={'type':'gauss', 'amp': noise_amp, 'ham_value': 1, 'corr_time': corr_time, 'ctrl': False} 60 | -------------------------------------------------------------------------------- /mezze/tfq/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2020 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | #import tensorflow_quantum as tfq 24 | #import tensorflow as tf 25 | import numpy as np 26 | import scipy.signal as si 27 | import sympy 28 | import cirq 29 | import mezze.channel as ch 30 | 31 | def cirq_to_total_channel(circ: cirq.Circuit): 32 | 33 | return ch.QuantumChannel(circ.unitary(), 'unitary') 34 | 35 | def cirq_moments_to_channel_list(circ: cirq.Circuit): 36 | 37 | channel_list = [] 38 | 39 | for m in circ: 40 | m_circ = cirq.Circuit(m) 41 | for qbit in circ.all_qubits(): 42 | if qbit not in m_circ.all_qubits(): 43 | m_circ.append(cirq.I.on(qbit)) 44 | 45 | channel_list.append(cirq_to_total_channel(m_circ)) 46 | 47 | return channel_list 48 | 49 | def channel_to_circuit(C: ch.QuantumChannel, qbits = None): 50 | 51 | if qbits is None: 52 | num_qubits = int(np.log2(C.kraus()[0].shape[0])) 53 | qbits = cirq.GridQubit.rect(num_qubits,1) 54 | 55 | return cirq.Circuit(cirq.MatrixGate(C.kraus()[0]).on(*qbits)) 56 | 57 | def channel_list_to_circuit(Clist, qbits = None): 58 | 59 | if qbits is None: 60 | num_qubits = int(np.log2(Clist[0].kraus()[0].shape[0])) 61 | qbits = cirq.GridQubit.rect(num_qubits,1) 62 | 63 | return cirq.Circuit([channel_to_circuit(C, qbits) for C in Clist]) 64 | 65 | 66 | def compute_PTM_prop(Clist): 67 | PTMProp = [Clist[0].ptm()[1:,1:]] 68 | for i in range(1,len(Clist)): 69 | PTMProp.append(Clist[i].ptm()[1:,1:]@PTMProp[-1]) 70 | 71 | return np.array(PTMProp) 72 | -------------------------------------------------------------------------------- /tests/test_exotic_pmds.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import mezze.implementations as implementations 24 | import mezze.simulation as simulation 25 | import mezze.hamiltonian as hamiltonian 26 | import mezze.channel as basis 27 | import unittest 28 | import mezze.core as core 29 | import numpy as np 30 | import scipy.linalg as la 31 | 32 | 33 | class TestExoticPMDs(unittest.TestCase): 34 | 35 | def test_blatt_pmd_comp_1(self): 36 | config=simulation.SimulationConfig(time_length=.1,num_steps=50) 37 | config.num_runs=1 38 | pmd = implementations.BlattPMDComp(1) 39 | pmd.noise_off() 40 | ham = hamiltonian.HamiltonianFunction(pmd) 41 | ctrls = np.zeros((50,0)) 42 | pham = hamiltonian.PrecomputedHamiltonian(pmd,ctrls,config, 43 | ham.get_function()) 44 | sim = simulation.Simulation(config,pmd,pham) 45 | report = sim.run() 46 | self.assertEqual(la.norm(report.channel.liouvillian()-np.eye(4)),0) 47 | 48 | def test_blatt_pmd_comp_3(self): 49 | config=simulation.SimulationConfig(time_length=.1,num_steps=50) 50 | config.num_runs=1 51 | pmd = implementations.BlattPMDComp(3) 52 | pmd.noise_off() 53 | ham = hamiltonian.HamiltonianFunction(pmd) 54 | ctrls = np.zeros((50,0)) 55 | pham = hamiltonian.PrecomputedHamiltonian(pmd,ctrls,config, 56 | ham.get_function()) 57 | sim = simulation.Simulation(config,pmd,pham) 58 | report = sim.run() 59 | self.assertEqual(la.norm(report.channel.liouvillian()-np.eye(64)),0) 60 | 61 | 62 | if __name__ == '__main__': 63 | unittest.main() 64 | -------------------------------------------------------------------------------- /tests/test_noise.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | from mezze.noise import * 25 | import numpy as np 26 | 27 | 28 | class TestNoise(unittest.TestCase): 29 | 30 | def test_factory(self): 31 | factory = NoiseFactory(100, 1.0) 32 | 33 | # White 34 | n = factory.get({'type': 'white', 'amp': 0.3}) 35 | self.assertIsInstance(n, WhiteNoise) 36 | 37 | # White with cutoff 38 | n = factory.get({'type': 'white', 'amp': 0.3, 'omega_min': 2*np.pi, 'omega_max': 2*np.pi*1e9}) 39 | self.assertIsInstance(n, WhiteCutoffNoise) 40 | 41 | # Pink with cutoff 42 | n = factory.get({'type': 'pink', 'amp': 0.3, 'omega_min': 2*np.pi, 'omega_max': 2*np.pi*1e9}) 43 | self.assertIsInstance(n, PinkCutoffNoise) 44 | 45 | # Gaussian 46 | n = factory.get({'type': 'gauss', 'amp': 17.0, 'corr_time': 0.8}) 47 | self.assertIsInstance(n, GaussianNoise) 48 | self.assertEqual(17.0, n.amplitude) 49 | self.assertEqual(0.8, n.corr_time) 50 | 51 | # Exponential 52 | n = factory.get({'type': 'exp', 'amp': 14.0, 'corr_time': 0.2}) 53 | self.assertIsInstance(n, ExponentialNoise) 54 | 55 | # Telegraph 56 | n = factory.get({'type': 'telegraph', 'vals': 12.0, 'taus': [2.0, 5.0]}) 57 | self.assertIsInstance(n, TelegraphNoise) 58 | 59 | # User Defined 60 | n = factory.get({'type':'time', 'corrfn': lambda t: t + 1}) 61 | self.assertIsInstance(n, UserDefinedNoise) 62 | 63 | # Null 64 | n = factory.get({'type': 'null'}) 65 | self.assertIsInstance(n, NullNoise) 66 | 67 | with self.assertRaises(NotImplementedError): 68 | factory.get({'type': 'red'}) 69 | 70 | 71 | def test_generation(self): 72 | factory = NoiseFactory(1, 1000) 73 | n = factory.get({'type': 'pink', 'amp': 0.3, 'omega_min': 2*np.pi, 'omega_max': 2*np.pi*1e9}) 74 | self.assertIsInstance(n, PinkCutoffNoise) 75 | 76 | v = n.generate() 77 | self.assertEqual(len(v),1000) 78 | 79 | if __name__ == '__main__': 80 | unittest.main() 81 | -------------------------------------------------------------------------------- /mezze/random/uniform/uniform.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import numpy as np 24 | from ...channel import * 25 | from ...channel import _TrB 26 | import scipy.linalg as la 27 | 28 | def unitary(N, as_channel=True, rgen = np.random): 29 | S = stiefel(N,1,as_channel=False,rgen=rgen) 30 | if as_channel: 31 | return QuantumChannel(S[:N,:N],'unitary') 32 | else: 33 | return S[:N,:N] 34 | 35 | def choi(N, rank = None, as_channel=True, rgen = np.random): 36 | if rank is None: 37 | rank = N**2 38 | elif rank <1 or rank > N**2: 39 | raise RuntimeError 40 | 41 | X = np.array(rgen.randn(N**2,rank) + 1j*rgen.randn(N**2,rank)) 42 | Y = _TrB(X@X.conj().T) 43 | sqrtY = la.sqrtm(Y) 44 | invsY = la.inv(sqrtY) 45 | LR = np.array(np.kron(invsY,np.eye(N))) 46 | D = LR@X@X.conj().T@LR 47 | idx = np.diag_indices(N**2) 48 | D[idx[0],idx[1]] = np.real(np.diag(D)) 49 | 50 | if as_channel: 51 | return QuantumChannel(D,'choi') 52 | else: 53 | return np.array(D) 54 | 55 | 56 | def stiefel(N, rank = None,as_channel=True, rgen = np.random): 57 | if rank is None: 58 | rank = N**2 59 | elif rank < 1 or rank >N**2: 60 | raise RuntimeError 61 | 62 | 63 | X = rgen.randn(rank*N,N) + 1j*rgen.randn(rank*N,N) 64 | q,_ = la.qr(X) 65 | q = np.array(q[:,:N]) 66 | 67 | if as_channel: 68 | return QuantumChannel(q,'stiefel') 69 | else: 70 | return np.array(q) 71 | 72 | def density_matrix(N, rank = None, as_state=True, rgen=np.random): 73 | U = unitary(N,as_channel=False,rgen=rgen) 74 | 75 | if rank is None: 76 | rank = N 77 | elif rank <1 or rank >N: 78 | raise NotImplementedError 79 | 80 | d = rgen.randn(N) + 1j*rgen.randn(N) 81 | d[rank:]=0 82 | d = d/la.norm(d) 83 | if as_state: 84 | return QuantumState(np.dot(U,np.dot(np.diag(np.conj(d)*d),U.conj().T)),'dm') 85 | else: 86 | return np.dot(U,np.dot(np.diag(np.conj(d)*d),U.conj().T)) 87 | 88 | def bloch_vector(N, pure = False, as_state=True, rgen=np.random): 89 | x = np.array(rgen.randn(N**2-1,1)) 90 | x = x/la.norm(x) 91 | 92 | if pure == False: 93 | U = rgen.rand(1)**(1./(N**2-1.)) 94 | x = U[0]*x 95 | 96 | if as_state: 97 | return QuantumState(x,'bv') 98 | else: 99 | return x 100 | 101 | -------------------------------------------------------------------------------- /tests/test_qutrit_simulation.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | from mezze.pmd import PMD 24 | import mezze.simulation as simulation 25 | import mezze.hamiltonian as hamiltonian 26 | import mezze.channel as basis 27 | import unittest 28 | import mezze.core as core 29 | import numpy as np 30 | import scipy.linalg as la 31 | 32 | class QutritPMD(PMD): 33 | def __init__(self,num_qubits=1): 34 | control_dim = 0 35 | noise_dim = 0 36 | num_lindblad = 0 37 | 38 | if core.is_multi_qubit(num_qubits): 39 | two_control_dim = 0 40 | two_noise_dim = 0 41 | PMD.__init__(self,control_dim,noise_dim, num_lindblad, 42 | num_qubits,two_control_dim,two_noise_dim) 43 | else: 44 | PMD.__init__(self,control_dim,noise_dim,num_lindblad,num_qubits) 45 | 46 | self.basis = basis.GellMannBasis(1).basis_list[1:] 47 | self.single_qubit_noise=[0 for x in range(len(self.basis))] 48 | self.single_qubit_drift=[0 for x in range(len(self.basis))] 49 | for x in range(len(self.basis)): 50 | self.single_qubit_noise[x] = lambda c, gamma: None 51 | self.single_qubit_drift[x] = lambda c, gamma: None 52 | 53 | class TestQutritSimulation(unittest.TestCase): 54 | 55 | def test_one_qutrit_I(self): 56 | config=simulation.SimulationConfig(time_length=.1,num_steps=50) 57 | config.num_runs=1 58 | pmd = QutritPMD(1) 59 | ham = hamiltonian.HamiltonianFunction(pmd) 60 | ctrls = np.zeros((50,0)) 61 | pham = hamiltonian.PrecomputedHamiltonian(pmd,ctrls,config, 62 | ham.get_function()) 63 | sim = simulation.Simulation(config,pmd,pham) 64 | report = sim.run() 65 | self.assertEqual(la.norm(report.channel.liouvillian()-np.eye(9)),0) 66 | 67 | def test_two_qutrit_I(self): 68 | config=simulation.SimulationConfig(time_length=.1,num_steps=50) 69 | config.num_runs=1 70 | pmd = QutritPMD(2) 71 | ham = hamiltonian.HamiltonianFunction(pmd) 72 | ctrls = np.zeros((50,0)) 73 | pham = hamiltonian.PrecomputedHamiltonian(pmd,ctrls,config, 74 | ham.get_function()) 75 | sim = simulation.Simulation(config,pmd,pham) 76 | report = sim.run() 77 | self.assertEqual(la.norm(report.channel.liouvillian()-np.eye(81)),0) 78 | 79 | if __name__ == '__main__': 80 | unittest.main() 81 | -------------------------------------------------------------------------------- /mezze/lindblad.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import numpy as np 24 | import logging 25 | 26 | # Define unnormalized Pauli Matrices 27 | sigI = np.array([[1., 0], [0, 1.]],dtype=complex) 28 | sigX = np.array([[0, 1.], [1., 0]],dtype=complex) 29 | sigY = np.array([[0, -1.j], [1.j, 0]],dtype=complex) 30 | sigZ = np.array([[1., 0], [0, -1.]],dtype=complex) 31 | 32 | class LindbladFactory(object): 33 | """ 34 | Factory for getting Lindblad calculator based on a PMD 35 | """ 36 | @classmethod 37 | def get(cls, pmd): 38 | lindblad = Lindblad(pmd.num_qubits) 39 | if len(pmd.lindblad_rates) >= 1: 40 | lindblad.add_with_t1(1.0 / pmd.lindblad_rates[0]) 41 | if len(pmd.lindblad_rates) >= 2: 42 | lindblad.add_with_t2(1.0 / pmd.lindblad_rates[1]) 43 | return lindblad 44 | 45 | class Lindblad(object): 46 | """ 47 | Lindblad calculator. 48 | """ 49 | def __init__(self, num_qubits): 50 | self.logger = logging.getLogger(__name__) 51 | self.num_qubits = num_qubits 52 | self.operator = np.zeros([4**num_qubits, 4**num_qubits]) 53 | self.identity = np.array(np.eye(2**num_qubits,dtype=complex)) 54 | 55 | def add_with_t1(self, t1_time): 56 | rate = 1.0 / t1_time 57 | sigma_minus = np.array([[0, 1.0], [0, 0]]) 58 | if self.num_qubits == 1: 59 | self.add_lindblad(sigma_minus, rate) 60 | if self.num_qubits == 2: 61 | self.add_lindblad(np.kron(sigI, sigma_minus), rate) 62 | self.add_lindblad(np.kron(sigma_minus, sigI), rate) 63 | 64 | def add_with_t2(self, t2_time): 65 | rate = 1.0 / t2_time 66 | if self.num_qubits == 1: 67 | lindblad_operator = sigZ 68 | self.add_lindblad(sigZ, rate) 69 | if self.num_qubits == 2: 70 | self.add_lindblad(np.kron(sigI, sigZ), rate) 71 | self.add_lindblad(np.kron(sigZ, sigI), rate) 72 | 73 | def add_lindblad(self, operator, scale_factor): 74 | """ 75 | Update the lindblad operator 76 | """ 77 | lindblad_operator = np.array(operator) 78 | update = np.kron(lindblad_operator.conj(), lindblad_operator) \ 79 | - 0.5 * np.kron(self.identity, np.dot(lindblad_operator.conj().T, lindblad_operator)) \ 80 | - 0.5 * np.kron(np.dot(lindblad_operator.conj().T, lindblad_operator).T, self.identity) 81 | self.operator = self.operator + scale_factor * update 82 | 83 | def get_matrix(self): 84 | """ 85 | Get the matrix for the Lindblad superoperator 86 | """ 87 | return self.operator 88 | 89 | def set_matrix(self, operator): 90 | """ 91 | Set the matrix for the Lindblad operator 92 | """ 93 | self.operator = operator -------------------------------------------------------------------------------- /tests/test_SchWAR.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.random.SchWARMA as SchWARMA 25 | import numpy as np 26 | import scipy.linalg as la 27 | import copy 28 | import scipy.special as sp 29 | import mezze.channel as ch 30 | 31 | s_i = np.array([[1,0],[0,1]],dtype=complex) 32 | s_x = np.array([[0,1],[1,0]],dtype=complex) 33 | s_y = np.array([[0,-1j],[1j,0]],dtype=complex) 34 | s_z = np.array([[1,0],[0,-1]],dtype=complex) 35 | 36 | 37 | 38 | class TestSchAR(unittest.TestCase): 39 | 40 | def test_init(self): 41 | 42 | ARMAS = [SchWARMA.ARMA(np.random.randn(np.random.randint(5))+2) for _ in range(3)] 43 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 44 | AR = SchWARMA.SchWAR(ARMAS, [s_x, s_y, s_z], D) 45 | 46 | def test_bad_init(self): 47 | ARMAS = [SchWARMA.ARMA(np.random.randn(5), np.random.randn(2)) for _ in range(3)] 48 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 49 | self.assertRaises(AssertionError, SchWARMA.SchWAR, 50 | *[ARMAS, [s_x, s_y, s_z], D]) 51 | 52 | 53 | def test_1d_fit(self): 54 | 55 | D = {'I': ch.QuantumChannel(np.array(np.eye(4)))} 56 | AR = SchWARMA.SchWAR([], [s_z], D) 57 | 58 | alpha = np.sqrt(.00001) 59 | sigma = 1.#1./2. 60 | 61 | arg = lambda t: alpha**2*sigma*(np.sqrt(np.pi)*t*sp.erf(t/sigma)+sigma*(np.exp(-t**2/sigma**2)-1)) 62 | args = np.exp(-2*np.array([arg(t) for t in range(100)])) 63 | args = (1.-args)/2. 64 | 65 | AR.fit([args], 5) 66 | self.assertEqual(5,len(AR.models[0].a)) 67 | self.assertEqual(1,len(AR.models[0].b)) 68 | AR.init_ARMAs() 69 | AR['I'] 70 | 71 | 72 | #Note now I have brackets on the second argument 73 | AR.fit([args], [7]) 74 | self.assertEqual(7,len(AR.models[0].a)) 75 | self.assertEqual(1,len(AR.models[0].b)) 76 | AR.init_ARMAs() 77 | L = AR['I'].liouvillian() 78 | 79 | #Known structure of \sigma_z arma 80 | self.assertEqual(la.norm(L-np.diag(np.diag(L))),0.0) 81 | self.assertEqual(L[0,0], L[3,3]) 82 | self.assertAlmostEqual(L[0,0], 1.,9) 83 | self.assertEqual(L[1,1], np.conj(L[2,2])) 84 | 85 | 86 | 87 | def test_3d_fit(self): 88 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 89 | AR = SchWARMA.SchWAR([], [s_z], D) 90 | 91 | alpha = np.sqrt(.00001) 92 | sigma = 1.#1./2. 93 | 94 | arg = lambda t: alpha**2*sigma*(np.sqrt(np.pi)*t*sp.erf(t/sigma)+sigma*(np.exp(-t**2/sigma**2)-1)) 95 | args = np.exp(-2*np.array([arg(t) for t in range(100)])) 96 | args = (1.-args)/2. 97 | 98 | #Note now I have brackets on the second argument 99 | AR.fit([args, args, args], [3,5,7]) 100 | self.assertEqual(3,len(AR.models[0].a)) 101 | self.assertEqual(5,len(AR.models[1].a)) 102 | self.assertEqual(7,len(AR.models[2].a)) 103 | AR.init_ARMAs() 104 | L = AR['I'] 105 | 106 | 107 | if __name__ == '__main__': 108 | unittest.main() 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mezze 2 | 3 | A toolbox for simulating open quantum system dynamics 4 | 5 | ## Getting Started 6 | 7 | 8 | For users who just want to use the master equation solver, channel classes, and/or `cirq`-based SchWARMA simulation cloning the repo and running `pip install . ` from the project directory should work fine. The install can be verified by installing `nose` and running `nosetests` from the project directory. Some tests may fail with extremely small numerical differences based on random inputs. 9 | 10 | The basic install does not include the faster Tensorflow-based simulation routines as well as the inference routines. Note that some of the example notebooks use this capability. To use these capabilities, see the next session. 11 | 12 | ### Advanced Install -- Tensorflow-based simulation and inference 13 | 14 | There are some issues with dependencies that may occur when using `pip` only so instead follow these steps: 15 | 16 | * Install TensorFlow Quantum using the instructions [here](https://www.tensorflow.org/quantum/install) 17 | * *Note* sometimes there are issues with these directions, you may need to try other versions of tensorflow and tensorflow-quantum (in particular `tfq-nightly` will often work) 18 | * If installation fails on `sympy`, clone and install via git or with `conda install sympy` and repeat above instructions 19 | * Install mezze - `pip install .` (or similar) 20 | 21 | Even if there are `pip` issues with dependencies, as long as the tests run you should be fine. 22 | 23 | ## Usage 24 | 25 | Look at the notebooks in the `examples` folder, and also `tests` for more granular usage. The example notebooks have the following structure: 26 | 27 | * `examples` - notebooks in this directory cover the older `mezze` functionality for manipulating quanutum states and channels, as well as stochastic master equation simulation 28 | * `examples/SchWARMAPaperExamples` - notebooks in this directory generate the figures for Ref. [1], and are instructive for the finer details of SchWARMA, but most of that functionality has incorporated in a faster and more flexible codebase in `mezze.mtfq` 29 | * `examples/TFQ` - notebooks that cover the new functionality uses `cirq` objects and "SchWARMAFies" them to induce spatiotemporally correlated noise, these can then be simulated by simulators from `cirq`, `tensorflow-quantum`, and `qsim` (assuming the latter two are installed). This directory also contains an example of how to do noise injection in the IBMQE as in [2]. The `mtfq` codebase also supports heavy-tailed distributions as in [3]. 30 | * `examples/ZNE` - notebooks from the paper [4], that show how temporally correlated dephasing noise impacts circuit folding techniques for zero noise extrapolation. Also has some examples of the recent filter function interface from the appendix of [4]. 31 | 32 | 33 | 34 | ### Citing mezze 35 | 36 | If you use the SchWARMA tools in your research, please cite: 37 | 38 | [1] Schultz, K., Quiroz, G., Titum, P., & Clader, B. D. (2020). SchWARMA: A model-based approach for time-correlated noise in quantum circuits. Physical Review Research 3, 033229. Available as an arXiv preprint [arXiv:2010.04580](https://arxiv.org/abs/2010.04580). 39 | 40 | If you use SchWARMA for noise injection, please cite: 41 | 42 | [2] Murphy, A., Epstein, J., Quiroz, G., Schultz, K., Tewala, L., McElroy, K., ... & Sweeney, T. M. (2021). Universal Dephasing Noise Injection via Schrodinger Wave Autoregressive Moving Average Models. arXiv preprint [arXiv:2102.03370](https://arxiv.org/abs/2102.03370). 43 | 44 | If you experiment with the heavy-tailed (Levy-alpha stable) variants of SchWARMA, please cite: 45 | 46 | [3] Clader, B. D., Trout, C. J., Barnes, J. P., Schultz, K., Quiroz, G., & Titum, P. (2021). Impact of correlations and heavy-tails on quantum error correction. Physical Review A 103, 052428. Available as an arXiv preprint [arXiv:2101.11631](https://arxiv.org/abs/2101.11631). 47 | 48 | The zero noise extrapolation examples are from 49 | 50 | [4] Schultz, K., LaRose, R., Mari, A.,Quiroz, G., Shammah, N., Clader, B. D., and Zeng, W. J. (2022) Reducing the impact of time-correlated noise on zero-noise extrapolation. arXiv preprint[arXiv:2201.11792](https://arxiv.org/abs/2201.11792) 51 | 52 | ## Tensorflow Quantum Branch 53 | 54 | Note that most of the TensorFlow Quantum-based tools are now in the main branch, and tfq will only be for developing capabilities 55 | 56 | To use the SchWARMA tools implemented using [TensorFlow Quantum](https://www.tensorflow.org/quantum) and [Cirq](https://github.com/quantumlib/Cirq): 57 | 58 | * Install TensorFlow Quantum using the instructions [here](https://www.tensorflow.org/quantum/install) 59 | * Fetch remote branches - `git fetch` 60 | * Checkout the `tfq` branch of mezze - `git checkout tfq` 61 | * Install mezze - `pip install -e .` (or similar) 62 | 63 | This will resolve issues with dependencies that occur by using `pip` only 64 | -------------------------------------------------------------------------------- /tests/test_basis.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import scipy.linalg as la 25 | import mezze.core as core 26 | import numpy as np 27 | from mezze.channel import * 28 | from mezze.channel import _vec as vec 29 | 30 | class TestBasis(unittest.TestCase): 31 | 32 | def test_pauli_1(self): 33 | 34 | pb = PauliBasis() 35 | 36 | for i,b in enumerate([core.s_i, core.s_x, core.s_y, core.s_z]): 37 | self.assertEqual(la.norm(b-pb.basis_list[i]),0) 38 | self.assertEqual(type(pb.basis_list[i]),type(np.array([]))) 39 | self.assertEqual(pb.basis_list[i].dtype, np.complex128) 40 | 41 | def test_pauli_2(self): 42 | 43 | pb = PauliBasis(2) 44 | 45 | self.assertEqual(len(pb.basis_list),16) 46 | self.assertTrue([b.shape==(16,16) for b in pb.basis_list]) 47 | self.assertTrue([type(b)==type(np.array([])) for b in pb.basis_list]) #Changed Type 48 | 49 | idx = 0 50 | 51 | for b1 in [core.s_i, core.s_x, core.s_y, core.s_z]: 52 | for b2 in [core.s_i, core.s_x, core.s_y, core.s_z]: 53 | self.assertEqual(la.norm(np.kron(b1,b2)-pb.basis_list[idx]),0) 54 | idx+=1 55 | 56 | def test_pauli_xform_matrix_1(self): 57 | 58 | pb = PauliBasis() 59 | 60 | A = pb.transform_matrix(False,False) 61 | 62 | for i in range(A.shape[1]): 63 | self.assertEqual(la.norm(A[:,i,np.newaxis] - vec(pb.basis_list[i])),0) 64 | 65 | self.assertEqual(type(A),type(np.array([]))) 66 | self.assertEqual(A.dtype,np.complex128) #Changed Type 67 | self.assertEqual(la.norm(A.conj().T@A-2*np.eye(4)),0) 68 | 69 | A,c = pb.transform_matrix(False,True) 70 | self.assertEqual(c,.5) 71 | self.assertEqual(la.norm(c*A.conj().T@A-np.eye(4)),0) 72 | 73 | A = pb.transform_matrix(True,False) 74 | self.assertAlmostEqual(la.norm(A.conj().T@A-np.eye(4)),0,15) 75 | 76 | 77 | def test_pauli_xform_matrix_2(self): 78 | 79 | pb = PauliBasis(2) 80 | 81 | A = pb.transform_matrix(False,False) 82 | 83 | for i in range(A.shape[1]): 84 | self.assertEqual(la.norm(A[:,i,np.newaxis] - vec(pb.basis_list[i])),0) 85 | 86 | self.assertEqual(type(A),type(np.array([]))) #Changed Type 87 | self.assertEqual(A.dtype, np.complex128) 88 | self.assertEqual(la.norm(A.conj().T@A-4*np.eye(16)),0) 89 | 90 | A,c = pb.transform_matrix(False,True) 91 | self.assertEqual(c,.25) 92 | self.assertEqual(la.norm(c*A.conj().T@A-np.eye(16)),0) 93 | 94 | A = pb.transform_matrix(True,False) 95 | self.assertAlmostEqual(la.norm(A.conj().T@A-np.eye(16)),0,15) 96 | 97 | def test_gm_1(self): 98 | 99 | gm = GellMannBasis() 100 | for b in gm.basis_list: 101 | self.assertTrue(type(b), type(np.array([]))) #Changed Type 102 | self.assertEqual(b.dtype, np.complex128) 103 | 104 | def test_gm_xform_matrix_1(self): 105 | 106 | gm = GellMannBasis() 107 | 108 | A = gm.transform_matrix(False,False) 109 | 110 | for i in range(A.shape[1]): 111 | self.assertEqual(la.norm(A[:,i,np.newaxis] - vec(gm.basis_list[i])),0) 112 | 113 | A,c = gm.transform_matrix(False,True) 114 | 115 | self.assertEqual(c,1./3.) 116 | self.assertAlmostEqual(la.norm(c*A@A.conj().T-np.eye(9)),0,14) 117 | 118 | def test_gm_xform_matrix_2(self): 119 | 120 | gm = GellMannBasis(2) 121 | 122 | A = gm.transform_matrix(False,False) 123 | 124 | for i in range(A.shape[1]): 125 | self.assertEqual(la.norm(A[:,i,np.newaxis] - vec(gm.basis_list[i])),0) 126 | 127 | A,c = gm.transform_matrix(False,True) 128 | 129 | self.assertEqual(c,1./9.) 130 | self.assertAlmostEqual(la.norm(c*A@A.conj().T-np.eye(81)),0,14) 131 | 132 | if __name__ == '__main__': 133 | unittest.main() 134 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/circuit.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Dec 21 09:32:35 2015 4 | 5 | @author: dclader 6 | """ 7 | 8 | import numpy as np 9 | import mezze 10 | 11 | class UARCircuitSimulator(object): 12 | """ 13 | Class to build a circuit and simulate it using the UAR simulator code 14 | """ 15 | def __init__(self, pmd, config, gate_defs=None): 16 | self._pmd=pmd 17 | self._config=config 18 | self._gate_defs=gate_defs 19 | 20 | # Example of how to define gate 21 | #if self._gate_defs is None : 22 | #self._gate_defs = {'I': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((0.0,),)}, 23 | #'X': {'Control': ((0,),), 'Time': (1.0,), 'Theta': ((np.pi/2.0,),)}, 24 | #'Y': {'Control': ((1,),), 'Time': (1.0,), 'Theta': ((np.pi/2.0,),)}, 25 | #'Z': {'Control': ((2,),), 'Time': (1.0,), 'Theta': ((np.pi/2.0,),)}, 26 | #'Ypiover4': {'Control': ((1,),), 'Time': (1.0,), 'Theta': ((np.pi/4.0,),)}, 27 | #'H': {'Control': ((1,),(0,)), 'Time': (0.5,0.5), 'Theta': ((np.pi/4.0,),(np.pi/2.0,))}} 28 | 29 | 30 | def define_gates(self, gate_defs): 31 | if isinstance(gate_defs,dict): 32 | self._gate_defs.update(gate_defs) 33 | else: 34 | raise ValueError("The argument must be a dictionary.") 35 | 36 | def get_defined_gates(self): 37 | return self._gate_defs 38 | 39 | 40 | def generate_circuit_controls(self, circuit): 41 | 42 | # First check that all gates are defined. If not raise an exception. 43 | for gate in circuit : 44 | if gate not in self._gate_defs : 45 | raise ValueError("Circuit has undefined gates.") 46 | 47 | # Check that there are enough time steps to integrate 48 | num_gates = len(circuit) 49 | num_steps = self._config.num_steps # for typing ease 50 | if num_gates > num_steps : 51 | raise ValueError("The number of integration steps must be greater than the number of gates.") 52 | 53 | # Get total circuit time 54 | total_circuit_time = 0 55 | for gate in circuit : 56 | for ctrl_time in self._gate_defs[gate]['Time'] : 57 | total_circuit_time += ctrl_time 58 | 59 | #zero_field = mezze.controls.get_zero_control(zero_field = mezze.controls.get_zero_control(gate_length)) 60 | controls = [[] for _ in range(self._pmd.control_dim)] 61 | # Run through the circuit and generate primitive controls 62 | for gate_idx, gate in enumerate(circuit) : 63 | # Loop over the number of sequential controls in the gate 64 | for i_ctrls in range(len(self._gate_defs[gate]['Control'])) : 65 | controls_not_used = [x for x in range(self._pmd.control_dim) if x not in self._gate_defs[gate]['Control'][i_ctrls]] 66 | gate_length=0 67 | # Now loop over the individual controls being used at this time sequence 68 | for ctrl in range(len(self._gate_defs[gate]['Control'][i_ctrls])) : 69 | # Set control length 70 | control_length=int(np.round(self._config.num_steps*self._gate_defs[gate]['Time'][i_ctrls]/total_circuit_time)) 71 | control_time=self._config.time_length*self._gate_defs[gate]['Time'][i_ctrls]/total_circuit_time 72 | 73 | # If the gate times cannot be broken up correctly into equal size chunks, correct the time argument 74 | # to make sure the integral works correctly 75 | ratio = float(control_length)/(self._config.num_steps*self._gate_defs[gate]['Time'][i_ctrls]/total_circuit_time) 76 | 77 | # Check if we need to interpolate the last control to extend to the number of integration steps 78 | control_length_new = control_length 79 | if (gate_idx == len(circuit)-1) and (i_ctrls == len(self._gate_defs[gate]['Control'])-1) : 80 | total_circuit_steps = len(controls[self._gate_defs[gate]['Control'][i_ctrls][ctrl]]) + control_length 81 | if total_circuit_steps is not self._config.num_steps : 82 | extension_size = self._config.num_steps - total_circuit_steps 83 | control_length_new = control_length + extension_size 84 | 85 | # Get the field for the current control 86 | field = mezze.controls.get_theta_pulse_control(control_length_new, control_time*ratio, self._gate_defs[gate]["Theta"][i_ctrls][ctrl]) 87 | 88 | # Add this control onto the control list 89 | controls[self._gate_defs[gate]['Control'][i_ctrls][ctrl]].extend(field.tolist()) 90 | 91 | 92 | # Now set the controls not used to zero field 93 | zero_field = mezze.controls.get_zero_control(control_length_new) 94 | for i in controls_not_used : 95 | #controls_init[i]=np.concatenate((controls_init[i],zero_field)) 96 | controls[i].extend(zero_field.tolist()) 97 | 98 | 99 | return controls 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /tests/test_simulation_outputs.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.simulation as simul 25 | import mezze.hamiltonian as hamil 26 | import mezze.channel as ch 27 | from mezze.pmd import PMD 28 | import numpy as np 29 | 30 | class TestPMD(PMD): 31 | def __init__(self): 32 | control_dim = 0 33 | noise_dim = 0 34 | num_lindblad = 0 35 | PMD.__init__(self,control_dim,noise_dim,num_lindblad,1) 36 | 37 | class TestSimOutputs(unittest.TestCase): 38 | 39 | def test_sequential(self): 40 | config = simul.SimulationConfig(1., 10) 41 | config.parallel = False 42 | config.num_runs = 3 43 | config.time_sampling = False 44 | config.realization_sampling = False 45 | 46 | pmd = TestPMD() 47 | ham = hamil.HamiltonianFunction(pmd) 48 | ctrls = np.zeros((10,0)) 49 | pham = hamil.PrecomputedHamiltonian(pmd,ctrls,config,ham.get_function()) 50 | sim = simul.Simulation(config,pmd,pham) 51 | report = sim.run() 52 | 53 | self.assertIsInstance(report.channel,ch.QuantumChannel) 54 | self.assertIs(report.liouvillian_samples,None) 55 | self.assertIs(report.time_samples,None) 56 | 57 | def test_sequential_time(self): 58 | config = simul.SimulationConfig(1., 10) 59 | config.parallel = False 60 | config.num_runs = 3 61 | config.time_sampling = True 62 | config.sampling_interval = 5 63 | config.realization_sampling = False 64 | 65 | pmd = TestPMD() 66 | ham = hamil.HamiltonianFunction(pmd) 67 | ctrls = np.zeros((10,0)) 68 | pham = hamil.PrecomputedHamiltonian(pmd,ctrls,config,ham.get_function()) 69 | sim = simul.Simulation(config,pmd,pham) 70 | report = sim.run() 71 | 72 | self.assertIsInstance(report.channel,ch.QuantumChannel) 73 | self.assertIs(report.liouvillian_samples,None) 74 | self.assertIsInstance(report.time_samples,list) 75 | self.assertEqual(len(report.time_samples),2) 76 | self.assertTrue(all([type(c) == ch.QuantumChannel for c in report.time_samples])) 77 | 78 | def test_sequential_real(self): 79 | config = simul.SimulationConfig(1., 10) 80 | config.parallel = False 81 | config.num_runs = 3 82 | config.time_sampling = False 83 | config.realization_sampling = True 84 | 85 | pmd = TestPMD() 86 | ham = hamil.HamiltonianFunction(pmd) 87 | ctrls = np.zeros((10,0)) 88 | pham = hamil.PrecomputedHamiltonian(pmd,ctrls,config,ham.get_function()) 89 | sim = simul.Simulation(config,pmd,pham) 90 | report = sim.run() 91 | 92 | self.assertIsInstance(report.channel,ch.QuantumChannel) 93 | self.assertIsInstance(report.liouvillian_samples,list) 94 | self.assertIs(report.time_samples,None) 95 | self.assertEqual(len(report.liouvillian_samples), 3) 96 | self.assertTrue(all([type(c) == ch.QuantumChannel for c in report.liouvillian_samples])) 97 | 98 | def test_sequential_real_time(self): 99 | config = simul.SimulationConfig(1., 10) 100 | config.parallel = False 101 | config.num_runs = 3 102 | config.time_sampling = True 103 | config.sampling_interval = 5 104 | config.realization_sampling = True 105 | 106 | pmd = TestPMD() 107 | ham = hamil.HamiltonianFunction(pmd) 108 | ctrls = np.zeros((10,0)) 109 | pham = hamil.PrecomputedHamiltonian(pmd,ctrls,config,ham.get_function()) 110 | sim = simul.Simulation(config,pmd,pham) 111 | report = sim.run() 112 | 113 | self.assertIsInstance(report.channel,ch.QuantumChannel) 114 | self.assertIsInstance(report.liouvillian_samples,list) 115 | self.assertIsInstance(report.time_samples,list) 116 | self.assertEqual(len(report.liouvillian_samples), 3) 117 | self.assertTrue(all([type(c) == ch.QuantumChannel for c in report.liouvillian_samples])) 118 | self.assertEqual(len(report.liouvillian_samples), 3) 119 | self.assertTrue(all([len(row) ==2 for row in report.time_samples])) 120 | self.assertTrue(all([all([type(c) == ch.QuantumChannel for c in row]) for row in report.time_samples])) 121 | 122 | if __name__ == '__main__': 123 | unittest.main() 124 | -------------------------------------------------------------------------------- /tests/test_SchWMA.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | from mezze.random import SchWARMA 25 | import numpy as np 26 | import scipy.linalg as la 27 | import copy 28 | import scipy.special as sp 29 | import mezze.channel as ch 30 | 31 | s_i = np.array([[1,0],[0,1]],dtype=complex) 32 | s_x = np.array([[0,1],[1,0]],dtype=complex) 33 | s_y = np.array([[0,-1j],[1j,0]],dtype=complex) 34 | s_z = np.array([[1,0],[0,-1]],dtype=complex) 35 | 36 | 37 | 38 | class TestSchMA(unittest.TestCase): 39 | 40 | def test_init(self): 41 | 42 | ARMAS = [SchWARMA.ARMA([], np.random.randn(np.random.randint(5))+2) for _ in range(3)] 43 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 44 | MA = SchWARMA.SchWMA(ARMAS, [s_x, s_y, s_z], D) 45 | 46 | def test_bad_init(self): 47 | ARMAS = [SchWARMA.ARMA(np.random.randn(1), np.random.randn(np.random.randint(5))+2) for _ in range(3)] 48 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 49 | self.assertRaises(AssertionError, SchWARMA.SchWMA, 50 | *[ARMAS, [s_x, s_y, s_z], D]) 51 | 52 | 53 | def test_1d_fit(self): 54 | 55 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 56 | MA = SchWARMA.SchWMA([], [s_z], D) 57 | 58 | alpha = np.sqrt(.00001) 59 | sigma = 1.#1./2. 60 | 61 | arg = lambda t: alpha**2*sigma*(np.sqrt(np.pi)*t*sp.erf(t/sigma)+sigma*(np.exp(-t**2/sigma**2)-1)) 62 | args = np.exp(-2*np.array([arg(t) for t in range(100)])) 63 | args = (1.-args)/2. 64 | 65 | MA.fit([args], 5) 66 | self.assertEqual(5,len(MA.models[0].b)) 67 | self.assertEqual(0,len(MA.models[0].a)) 68 | MA.init_ARMAs() 69 | MA['I'] 70 | 71 | 72 | #Note now I have brackets on the second argument 73 | MA.fit([args], [7]) 74 | self.assertEqual(7,len(MA.models[0].b)) 75 | self.assertEqual(0,len(MA.models[0].a)) 76 | MA.init_ARMAs() 77 | L = MA['I'].liouvillian() 78 | 79 | #Known structure of \sigma_z arma 80 | self.assertEqual(la.norm(L-np.diag(np.diag(L))),0.0) 81 | self.assertEqual(L[0,0], L[3,3]) 82 | self.assertAlmostEqual(L[0,0], 1.,9) 83 | self.assertEqual(L[1,1], np.conj(L[2,2])) 84 | 85 | def test_avg(self): 86 | 87 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 88 | MA = SchWARMA.SchWMA([], [s_z], D) 89 | 90 | alpha = np.sqrt(.00001) 91 | sigma = 1.#1./2. 92 | 93 | arg = lambda t: alpha**2*sigma*(np.sqrt(np.pi)*t*sp.erf(t/sigma)+sigma*(np.exp(-t**2/sigma**2)-1)) 94 | args = np.exp(-2*np.array([arg(t) for t in range(100)])) 95 | #args = (1.-args)/2. 96 | 97 | MA.fit([(1.-args)/2.], 5) 98 | self.assertEqual(5,len(MA.models[0].b)) 99 | self.assertEqual(0,len(MA.models[0].a)) 100 | MA.init_ARMAs() 101 | MA['I'] 102 | 103 | L1 = MA.avg(1,[ch.QuantumChannel(s_z,'unitary').choi()]).liouvillian() 104 | tL1 = np.array(np.eye(4,dtype=complex)) 105 | tL1[1,1] = args[1] 106 | tL1[2,2] = args[1] 107 | 108 | self.assertAlmostEqual(la.norm(L1-tL1), 0.0, 6) 109 | 110 | L2 = MA.avg(10,[ch.QuantumChannel(s_z,'unitary').choi()]).liouvillian() 111 | tL2 = np.eye(4,dtype=complex) 112 | tL2[1,1] = args[10] 113 | tL2[2,2] = args[10] 114 | 115 | self.assertAlmostEqual(la.norm(L2 - tL2), 0.0, 5) 116 | #Not a great test, but should be true 117 | self.assertLess(la.norm(L2-tL2), la.norm(tL1**10-L2)) 118 | 119 | def test_3d_fit(self): 120 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 121 | MA = SchWARMA.SchWMA([], [s_z], D) 122 | 123 | alpha = np.sqrt(.00001) 124 | sigma = 1.#1./2. 125 | 126 | arg = lambda t: alpha**2*sigma*(np.sqrt(np.pi)*t*sp.erf(t/sigma)+sigma*(np.exp(-t**2/sigma**2)-1)) 127 | args = np.exp(-2*np.array([arg(t) for t in range(100)])) 128 | args = (1.-args)/2. 129 | 130 | #Note now I have brackets on the second argument 131 | MA.fit([args, args, args], [3,5,7]) 132 | self.assertEqual(3,len(MA.models[0].b)) 133 | self.assertEqual(5,len(MA.models[1].b)) 134 | self.assertEqual(7,len(MA.models[2].b)) 135 | MA.init_ARMAs() 136 | L = MA['I'] 137 | 138 | 139 | if __name__ == '__main__': 140 | unittest.main() 141 | -------------------------------------------------------------------------------- /tests/test_SchWARMA.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.random.SchWARMA as SchWARMA 25 | import mezze.channel as ch 26 | import numpy as np 27 | import scipy.linalg as la 28 | import copy 29 | 30 | 31 | s_i = np.array([[1,0],[0,1]],dtype=complex) 32 | s_x = np.array([[0,1],[1,0]],dtype=complex) 33 | s_y = np.array([[0,-1j],[1j,0]],dtype=complex) 34 | s_z = np.array([[1,0],[0,-1]],dtype=complex) 35 | 36 | 37 | 38 | class TestSchWARMA(unittest.TestCase): 39 | 40 | def test_init(self): 41 | 42 | ARMAs = [SchWARMA.ARMA([.5,.25],[1])] 43 | ARMAs.append(SchWARMA.ARMA([],[1])) 44 | ARMAs.append(SchWARMA.ARMA([],[1,1,1])) 45 | 46 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 47 | 48 | sch = SchWARMA.SchWARMA(ARMAs, [s_x,s_y,s_z], D) 49 | 50 | xs = [copy.copy(model.x) for model in sch.models] 51 | ys = [copy.copy(model.y) for model in sch.models] 52 | 53 | sch.init_ARMAs() 54 | 55 | xs2 = [copy.copy(model.x) for model in sch.models] 56 | ys2 = [copy.copy(model.y) for model in sch.models] 57 | 58 | xdiff = np.array([la.norm(x-xx) for x,xx in zip(xs,xs2)]) 59 | ydiff = np.array([la.norm(yy) for y,yy in zip(ys,ys2)]) 60 | 61 | self.assertTrue(np.all(xdiff>0)) 62 | self.assertTrue(np.all(ydiff==0)) 63 | 64 | 65 | def test_no_SchWARMA(self): 66 | 67 | ARMAs = [SchWARMA.ARMA([],[0])] 68 | ARMAs.append(SchWARMA.ARMA([],[0])) 69 | ARMAs.append(SchWARMA.ARMA([],[0])) 70 | 71 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex))), 72 | 'X': ch.QuantumChannel(np.kron(s_x.conj(),s_x))} 73 | 74 | sch = SchWARMA.SchWARMA(ARMAs, [s_x,s_y,s_z], D) 75 | 76 | sch.init_ARMAs 77 | 78 | self.assertEqual(la.norm(D['I'].choi()-sch['I'].choi()),0) 79 | self.assertEqual(la.norm(D['X'].choi()-sch['X'].choi()),0) 80 | 81 | def test_hamiltonian_basis(self): 82 | 83 | ARMAs = [SchWARMA.ARMA([.5,.25],[1])] 84 | ARMAs.append(SchWARMA.ARMA([],[1])) 85 | ARMAs.append(SchWARMA.ARMA([],[1,1,1])) 86 | 87 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 88 | 89 | sch = SchWARMA.SchWARMA(ARMAs, [s_x,s_y,s_z], D) 90 | 91 | self.assertTrue(all([la.norm(b+b.conj().T<1e-9)for b in sch.basis])) 92 | 93 | def test_zero_basis(self): 94 | 95 | ARMAs = [SchWARMA.ARMA([.5,.25],[1])] 96 | ARMAs.append(SchWARMA.ARMA([],[1])) 97 | 98 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 99 | 100 | sch = SchWARMA.SchWARMA(ARMAs, [np.zeros((8,2)),np.zeros((2,2))],D) 101 | 102 | self.assertEqual(sch.N,2) 103 | self.assertTrue(all([b.shape==(8,8) for b in sch.basis])) 104 | 105 | self.assertEqual(la.norm(sch['I'].liouvillian()-np.eye(4)),0) 106 | 107 | def test_mixed_basis(self): 108 | ARMAs = [SchWARMA.ARMA([.5,.25],[1])] 109 | ARMAs.append(SchWARMA.ARMA([],[1])) 110 | ARMAs.append(SchWARMA.ARMA([],[1,1,1])) 111 | 112 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex))), 113 | 'X': ch.QuantumChannel(np.kron(s_x.conj(),s_x))} 114 | 115 | ad = np.zeros((4,2),dtype=complex) 116 | ad[2,1]=.1 117 | sch = SchWARMA.SchWARMA(ARMAs, [s_x,1j*s_y,ad], D) 118 | 119 | self.assertEqual(sch.N, 2) 120 | self.assertTrue(all([la.norm(b + b.conj().T < 1e-9) for b in sch.basis])) 121 | 122 | def test_zero_basis(self): 123 | 124 | ARMAs = [SchWARMA.ARMA([.5,.25],[1])] 125 | ARMAs.append(SchWARMA.ARMA([],[1])) 126 | 127 | D = {'I': ch.QuantumChannel(np.array(np.eye(4,dtype=complex)))} 128 | 129 | sch = SchWARMA.SchWARMA(ARMAs, [s_z, np.zeros((8,2))],D) 130 | 131 | self.assertEqual(sch.N,2) 132 | self.assertTrue(all([b.shape==(8,8) for b in sch.basis])) 133 | self.assertEqual(la.norm(1j*s_z-sch.basis[0][:2,:2]),0) 134 | self.assertEqual(la.norm(sch.basis[0][2:,:]),0) 135 | self.assertEqual(la.norm(sch.basis[0][:,2:]),0) 136 | 137 | out = sch['I'] 138 | self.assertEqual(out.rank(),1) 139 | self.assertEqual(out.chi()[1,1],0) 140 | self.assertEqual(out.chi()[2,2],0) 141 | 142 | avg = ch.QuantumChannel(np.mean([sch['I'].choi() for _ in range(3)],0),'choi') 143 | self.assertEqual(avg.rank(),2) 144 | self.assertEqual(avg.chi()[1,1],0) 145 | self.assertEqual(avg.chi()[2,2],0) 146 | 147 | if __name__ == '__main__': 148 | unittest.main() 149 | -------------------------------------------------------------------------------- /examples/1_StateAndChannelDemo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import mezze.channel as ch" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "Quantum states can be specified in a number of forms in mezze, for example by specifying a density matrix." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "zero = ch.QuantumState([[1,0],[0,0]])\n", 26 | "print('|0> as density matrix ( |0><0| ):')\n", 27 | "print(zero.density_matrix())" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "States can be converted between representations by the `density_matrix()`, `density_vector()`, `bloch_vector()` and `state_mixture()` methods. These methods return numpy primitives, and if desired, the outputs of these can be used to generate new `QuantumState` objects, although this is generally not needed since all conversions are stored within the original `QuantumState` object." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "print('|0> as a density vector ( |(|0><0|)>> )')\n", 44 | "print(zero.density_vector())\n", 45 | "print('\\n|0> as a bloch vector')\n", 46 | "print(zero.bloch_vector())\n", 47 | "print('\\n|0> decomposed into weights and pure states')\n", 48 | "w,b = zero.state_mixture()\n", 49 | "print('\\tweights: {0}'.format(w))\n", 50 | "print('\\tpure states: {0},{1}'.format(b[0],b[1]))" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "`QuantumChannel` operates on a similar formalism. Channels can be defined by matrices that represent Liouvillians, unitary operations, Choi matrices, $\\chi$-matrices, and Stiefel matrices by specifying `type` in the constructor as `liou`, `unitary`, `choi`, `chi`, and `stiefel` respectively. Giving a list of matrices and `type=kraus` will specify a channel from Kraus operators. The current version does not perform consistency checking on the inputs but will be implemented in a future release." 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "X = ch.QuantumChannel([[0,1],[1,0]],'unitary')\n", 67 | "print('Chi matrix of X created from a unitary represenation')\n", 68 | "print(X.chi())\n", 69 | "\n", 70 | "#note the extra set of []\n", 71 | "Xkraus = ch.QuantumChannel([ [[0,1],[1,0]] ],'kraus')\n", 72 | "print('\\nChi matrix of X created from a set of kraus operators')\n", 73 | "print(Xkraus.chi())" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "In mezze, the `*` operator is defined on `QuantumChannel` and is used to map an in input state to an output state. You can also use the `QuantumChannel.map` function as well." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "print('X*zero as a Bloch Vector')\n", 90 | "print((X*zero).bloch_vector())\n", 91 | "print(\"\")\n", 92 | "print('X*zero as a density matrix')\n", 93 | "print((X*zero).density_matrix())" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "The `*` operation is also defined between channel objects, and corresponds to standard multiplication of Liouvillians as matrices. One can also use `dot()`." 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "I = X*X\n", 110 | "print('X*X is the identity channel')\n", 111 | "print(I.chi())" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "Tensor product of states is accomplished through the `^` operator or `kron()` function" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "composite_state = zero^zero\n", 128 | "print('|0>|0> = |00>')\n", 129 | "print(composite_state.density_matrix())" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "Tensor product is defined similarly for `QuantumChannel`, as are partial traces (currently only implemented for composite systems of equal dimension)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "composite_state_out = (I^X)*composite_state\n", 146 | "print('(I^X)*|00> = |01>')\n", 147 | "print(composite_state_out.density_matrix())\n", 148 | "\n", 149 | "print('\\n Tr_B(|01>) = |0>')\n", 150 | "print(composite_state_out.TrB().density_matrix())\n", 151 | "\n", 152 | "print('\\n Tr_A(|01>) = |1>')\n", 153 | "print(composite_state_out.TrA().density_matrix())" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": {}, 160 | "outputs": [], 161 | "source": [] 162 | } 163 | ], 164 | "metadata": { 165 | "kernelspec": { 166 | "display_name": "mezzeexport", 167 | "language": "python", 168 | "name": "mezzeexport" 169 | }, 170 | "language_info": { 171 | "codemirror_mode": { 172 | "name": "ipython", 173 | "version": 3 174 | }, 175 | "file_extension": ".py", 176 | "mimetype": "text/x-python", 177 | "name": "python", 178 | "nbconvert_exporter": "python", 179 | "pygments_lexer": "ipython3", 180 | "version": "3.7.3" 181 | } 182 | }, 183 | "nbformat": 4, 184 | "nbformat_minor": 4 185 | } 186 | -------------------------------------------------------------------------------- /tests/test_SchWARMA_conversion.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.random.SchWARMA as SchWARMA 25 | from mezze.random.SchWARMA import acv_from_b, acv_2_var, var_2_fid, extract_and_downconvert_from_sim, make_gauss_approximation 26 | import mezze 27 | import numpy as np 28 | import scipy.signal as si 29 | 30 | 31 | class TestSchWARMAConversion(unittest.TestCase): 32 | 33 | def test_fits_gauss(self): 34 | 35 | T_max = 100 # Doing 100 gates 36 | trotter_ratio = 50 # mezze trotter time steps per unit of time (small so I can do a lot of MC) 37 | 38 | NN_spec = 10 39 | corr_time = 10.0 40 | 41 | amp = .002 42 | 43 | config_specs = {'T_end': T_max, 'steps': T_max * trotter_ratio, 'Δsteps': 10, 'num_runs': 10, 44 | 'shsteps': NN_spec} 45 | # steps : the time step for simulations, Δsteps: recording interval, shteps: the number of SchWARMA time steps 46 | noise_specs = {'type': 'gauss', 'amp': amp, 'corr_time': corr_time} # noise parameters. 47 | 48 | # First define config, that determines the simulation parameters for the time of evolution and timesteps 49 | config = mezze.simulation.SimulationConfig(time_length=config_specs['T_end'], num_steps=config_specs['steps']) 50 | config.parallel = True # parallelizes over available cpu cores 51 | config.num_runs = config_specs['num_runs'] # number of monte-carlo runs 52 | config.num_cpus = 4 # number of cpus to parallelize over 53 | # config.get_unitary = True #report unitary 54 | config.time_sampling = True # set to true to get the channel at intermediate times 55 | config.sampling_interval = config_specs['Δsteps'] # records the channel after every 10 time-steps 56 | config.realization_sampling = False # set true if you want to record every noise(monte-carlo) realization 57 | 58 | # # Setup PMD 59 | pmd0 = mezze.pmd.PMD(control_dim=0, noise_dim=1, num_qubits=1, num_lindblad=0) 60 | pmd0.single_qubit_noise[3] = lambda c, gamma: gamma[ 61 | 0] # sets single_qubit noise along z direction. [3] corresponds to σz pauli basis 62 | pmd0.noise_hints[0] = noise_specs 63 | # build Hamiltonian and simulation 64 | ham = mezze.hamiltonian.HamiltonianFunction(pmd0) 65 | ctrls = np.zeros( 66 | (config_specs['steps'], 1)) # ctrls matrix as a function of time is zero since there is no control 67 | pham = mezze.hamiltonian.PrecomputedHamiltonian(pmd0, ctrls, config, ham.get_function()) 68 | 69 | sim = mezze.simulation.Simulation(config, pmd0, pham) 70 | 71 | rx = SchWARMA.extract_sim_autocorrs(sim, 1. / sim.config.dt)[0] 72 | 73 | Tgate = 1.0 74 | Tgate2 = 2.5 75 | b_fit = extract_and_downconvert_from_sim(sim, Tgate)[0] 76 | b_fit2 = extract_and_downconvert_from_sim(sim, Tgate2)[0] 77 | 78 | Tgauss = 1.5 79 | b_gauss = make_gauss_approximation(sim, Tgauss)[0] 80 | 81 | # print(np.max(np.abs(b_fit-b_fit2)),np.max(b_fit)) 82 | 83 | fids_fast = var_2_fid(acv_2_var(rx, ks=np.arange(T_max / sim.config.dt))) 84 | fids_slow = var_2_fid(acv_2_var(acv_from_b(b_fit), np.arange(T_max / Tgate))) 85 | fids_slow2 = var_2_fid(acv_2_var(acv_from_b(b_fit2), np.arange(T_max / Tgate2))) 86 | fids_gauss = var_2_fid(acv_2_var(acv_from_b(b_gauss), np.arange(T_max / Tgauss))) 87 | 88 | self.assertEqual(fids_fast[0], 1.0) 89 | self.assertEqual(fids_fast[0], fids_slow[0]) 90 | self.assertEqual(fids_fast[0], fids_slow2[0]) 91 | self.assertEqual(fids_fast[0], fids_gauss[0]) 92 | 93 | ff = fids_fast[::int(Tgate/sim.config.dt)] 94 | fs = fids_slow 95 | self.assertAlmostEqual(ff[1], fs[1]) 96 | self.assertLess(np.max(np.abs(ff-fs)), 1e-4) 97 | 98 | ff = fids_fast[::int(Tgate2/sim.config.dt)] 99 | fs = fids_slow2 100 | self.assertAlmostEqual(ff[1], fs[1]) 101 | self.assertLess(np.max(np.abs(ff-fs)), 1e-4) 102 | 103 | ff = fids_fast[::int(Tgauss/sim.config.dt)] 104 | fs = fids_gauss 105 | self.assertAlmostEqual(ff[1], fs[1], 6) 106 | self.assertLess(np.max(np.abs(ff-fs)), 1e-4) 107 | 108 | def test_downconvert_from_SchWARMA(self): 109 | 110 | b = si.firwin(128, .2) 111 | b2 = SchWARMA.downconvert_from_SchWARMA(b, 2) 112 | 113 | fb = var_2_fid(acv_2_var(acv_from_b(b), np.arange(100)))[::2] 114 | fb2 = var_2_fid(acv_2_var(acv_from_b(b2), np.arange(100)))[:50] 115 | 116 | self.assertEqual(fb[0], 1.0) 117 | self.assertEqual(fb2[0], 1.0) 118 | 119 | self.assertLess(np.max(np.abs(fb-fb2)),1e-3) 120 | 121 | if __name__ == '__main__': 122 | unittest.main() 123 | -------------------------------------------------------------------------------- /tests/test_random_uniform.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.channel as ch 25 | import numpy as np 26 | import scipy.linalg as la 27 | from mezze.random import uniform 28 | 29 | class TestRandomUniformQuantumObjects(unittest.TestCase): 30 | 31 | def test_unitary_as_channel(self): 32 | u = uniform.unitary(2) 33 | 34 | self.assertTrue(len(u.kraus())==1) 35 | self.assertTrue(u.kraus()[0].shape == (2,2)) 36 | 37 | u = uniform.unitary(5) 38 | 39 | self.assertTrue(len(u.kraus())==1) 40 | self.assertTrue(u.kraus()[0].shape == (5,5)) 41 | 42 | def test_unitary_as_matrix(self): 43 | u = uniform.unitary(3,as_channel=False) 44 | 45 | self.assertAlmostEqual(la.norm(u@u.conj().T - np.eye(3)),0,14) 46 | self.assertAlmostEqual(np.abs(la.det(u)),1,14) 47 | self.assertEqual(type(u),np.ndarray) 48 | 49 | def test_choi_as_channel(self): 50 | choi = uniform.choi(2) 51 | 52 | self.assertTrue(choi.is_valid()) 53 | 54 | def test_choi_as_matrix(self): 55 | choi = uniform.choi(3,as_channel=False) 56 | 57 | self.assertTrue(choi.shape == (9,9)) 58 | self.assertEqual(type(choi),np.ndarray) 59 | self.assertEqual(choi.dtype, np.complex128) 60 | 61 | self.assertTrue(ch.QuantumChannel(choi,'choi').is_valid()) 62 | 63 | def test_stiefel_as_channel(self): 64 | stiefel = uniform.stiefel(2) 65 | 66 | self.assertTrue(stiefel.is_valid()) 67 | 68 | def test_stiefel_as_matrix(self): 69 | stiefel = uniform.stiefel(3,as_channel=False) 70 | 71 | self.assertTrue(stiefel.shape == (27,3)) 72 | self.assertEqual(type(stiefel),np.ndarray) 73 | self.assertEqual(stiefel.dtype, np.complex128) 74 | 75 | self.assertTrue(ch.QuantumChannel(stiefel,'stiefel').is_valid()) 76 | 77 | def test_bloch_vector_as_state(self): 78 | bv = uniform.bloch_vector(3) 79 | 80 | self.assertTrue(bv.is_valid()) 81 | 82 | def test_bloch_vector_as_matrix(self): 83 | bv = uniform.bloch_vector(4,as_state=False) 84 | 85 | self.assertTrue(bv.shape == (15,1)) 86 | self.assertLessEqual(la.norm(bv),1) 87 | self.assertEqual(type(bv),np.ndarray) 88 | self.assertTrue(ch.QuantumState(bv,'bv').is_valid()) 89 | 90 | def test_pure_bloch_vector(self): 91 | bv = uniform.bloch_vector(2,pure=True) 92 | 93 | self.assertTrue(bv.is_valid() and bv.is_pure()) 94 | 95 | def test_density_matrix_as_state(self): 96 | dm = uniform.density_matrix(3) 97 | 98 | self.assertTrue(dm.is_valid()) 99 | 100 | def test_density_matrix_as_matrix(self): 101 | dm = uniform.density_matrix(4,as_state=False) 102 | 103 | self.assertTrue(dm.shape == (4,4)) 104 | self.assertTrue(type(dm), np.ndarray) 105 | self.assertTrue(dm.dtype == np.complex128) 106 | self.assertTrue(ch.QuantumState(dm).is_valid()) 107 | 108 | def test_rank_choi(self): 109 | 110 | for i in range(1,10): 111 | choi = uniform.choi(3,i) 112 | 113 | self.assertTrue(choi.rank()==i) 114 | 115 | def test_rank_stiefel(self): 116 | 117 | for i in range(1,10): 118 | s = uniform.stiefel(3,i) 119 | 120 | self.assertTrue(s.rank()==i) 121 | 122 | def test_rank_density_matrix(self): 123 | 124 | for i in range(1,10): 125 | dm = uniform.density_matrix(9,i) 126 | 127 | self.assertTrue(dm.rank()==i) 128 | 129 | def test_unitary_seed(self): 130 | 131 | rgen1 = np.random.RandomState(1) 132 | U1 = uniform.unitary(2,False,rgen1) 133 | 134 | rgen2 = np.random.RandomState(1) 135 | U2 = uniform.unitary(2,False,rgen2) 136 | 137 | self.assertEqual(la.norm(U1-U2),0) 138 | 139 | def test_choi_seed(self): 140 | 141 | rgen1 = np.random.RandomState(1) 142 | choi1 = uniform.choi(2,4,False,rgen1) 143 | 144 | rgen2 = np.random.RandomState(1) 145 | choi2 = uniform.choi(2,4,False,rgen2) 146 | 147 | self.assertEqual(la.norm(choi1-choi2),0) 148 | 149 | def test_stiefel_seed(self): 150 | 151 | rgen1 = np.random.RandomState(1) 152 | s1 = uniform.stiefel(2,4,False,rgen1) 153 | 154 | rgen2 = np.random.RandomState(1) 155 | s2 = uniform.stiefel(2,4,False,rgen2) 156 | 157 | self.assertEqual(la.norm(s1-s2),0) 158 | 159 | def test_density_matrix_seed(self): 160 | 161 | rgen1 = np.random.RandomState(1) 162 | dm1 = uniform.density_matrix(2,2,False,rgen1) 163 | 164 | rgen2 = np.random.RandomState(1) 165 | dm2 = uniform.density_matrix(2,2,False,rgen2) 166 | 167 | self.assertEqual(la.norm(dm1-dm2),0) 168 | 169 | def test_bloch_vector_seed(self): 170 | 171 | rgen1 = np.random.RandomState(1) 172 | bv1 = uniform.bloch_vector(2,False,False,rgen1) 173 | 174 | rgen2 = np.random.RandomState(1) 175 | bv2 = uniform.bloch_vector(2,False,False,rgen2) 176 | 177 | self.assertEqual(la.norm(bv1-bv2),0) 178 | 179 | if __name__ == '__main__': 180 | unittest.main() 181 | -------------------------------------------------------------------------------- /tests/test_quantum_channel_ops.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.channel as ch 25 | import numpy as np 26 | import scipy.linalg as la 27 | import mezze.random.uniform as uni 28 | 29 | class TestQuantumChannelOps(unittest.TestCase): 30 | 31 | def test_map_X0(self): 32 | 33 | zero = np.zeros((2,2)) 34 | zero[1,1] = 0 35 | p = ch.QuantumState(zero,'dm') 36 | 37 | X = ch.QuantumChannel(ch._sigmaX,'unitary') 38 | 39 | out = X.map(p) 40 | out2 = X*p 41 | 42 | one = np.zeros((2,2)) 43 | one[0,0] = 0 44 | 45 | self.assertEqual(la.norm(out.density_matrix()-one),0) 46 | self.assertEqual(la.norm(out2.density_matrix()-one),0) 47 | 48 | def test_map_concatenation(self): 49 | 50 | zero = np.zeros((2,2)) 51 | zero[1,1] = 0 52 | p = ch.QuantumState(zero,'dm') 53 | 54 | X = ch.QuantumChannel(ch._sigmaX,'unitary') 55 | 56 | out = X*X*p 57 | out2 = (X*X)*p 58 | out3 = X*(X*p) 59 | 60 | self.assertEqual(la.norm(out.density_matrix()-zero),0) 61 | self.assertEqual(la.norm(out2.density_matrix()-zero),0) 62 | self.assertEqual(la.norm(out3.density_matrix()-zero),0) 63 | 64 | def test_kron_I(self): 65 | 66 | a = ch.QuantumChannel(np.eye(2),'unitary') 67 | b = ch.QuantumChannel(np.eye(2),'unitary') 68 | #a = ch.QuantumChannel(np.eye(4),'liou') 69 | #b = ch.QuantumChannel(np.eye(4),'liou') 70 | 71 | c1 = a.kron(b) 72 | c2 = a^b 73 | 74 | L1 = c1.liouvillian() 75 | L2 = c2.liouvillian() 76 | 77 | self.assertEqual(la.norm(L1-np.eye(16)),0) 78 | self.assertEqual(la.norm(L2-np.eye(16)),0) 79 | 80 | def test_kron_n(self): 81 | 82 | X = uni.choi(2) 83 | X3_a = X.kron(3) 84 | X3_b = X^X^X 85 | 86 | self.assertEqual(la.norm(X3_a.choi()-X3_b.choi()),0) 87 | 88 | def test_composite_map(self): 89 | 90 | X = ch.QuantumChannel(ch._sigmaX,'unitary') 91 | I = ch.QuantumChannel(ch._sigmaX,'unitary') 92 | 93 | tot = (X^X)*(I^X) 94 | 95 | zero = np.zeros((2,2)) 96 | zero[1,1] = 0 97 | pz = ch.QuantumState(zero,'dm') 98 | 99 | one = np.zeros((2,2)) 100 | one[1,1] = 0 101 | po = ch.QuantumState(one,'dm') 102 | 103 | out = np.kron(one,one) 104 | out1 = tot*(pz^po) 105 | out2 = (X*I*pz)^(X*X*po) 106 | out3 = po^po 107 | 108 | err1 = la.norm(out1.density_matrix()-out) 109 | err2 = la.norm(out2.density_matrix()-out) 110 | err3 = la.norm(out3.density_matrix()-out) 111 | 112 | self.assertEqual(err1,0) 113 | self.assertEqual(err2,0) 114 | self.assertEqual(err3,0) 115 | 116 | def test_CNOT(self): 117 | 118 | cnot_mat = np.array([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]], dtype=complex) 119 | 120 | CNOT = ch.QuantumChannel(cnot_mat,'unitary') 121 | 122 | zero = np.zeros((2,2)) 123 | zero[1,1] = 0 124 | pz = ch.QuantumState(zero,'dm') 125 | 126 | one = np.zeros((2,2)) 127 | one[1,1] = 0 128 | po = ch.QuantumState(one,'dm') 129 | 130 | out00 = CNOT*(pz^pz) 131 | out01 = CNOT*(pz^po) 132 | out10 = CNOT*(po^pz) 133 | out11 = CNOT*(po^po) 134 | 135 | err1 = out00.density_matrix() - (pz^pz).density_matrix() 136 | err2 = out01.density_matrix() - (pz^po).density_matrix() 137 | err3 = out10.density_matrix() - (po^po).density_matrix() 138 | err4 = out11.density_matrix() - (po^pz).density_matrix() 139 | 140 | self.assertEqual(la.norm(err1),0) 141 | self.assertEqual(la.norm(err2),0) 142 | self.assertEqual(la.norm(err3),0) 143 | self.assertEqual(la.norm(err4),0) 144 | 145 | def test_partial_trace(self): 146 | 147 | LX = np.kron(ch._sigmaX.conj(),ch._sigmaX) 148 | LY = np.kron(ch._sigmaY.conj(),ch._sigmaY) 149 | 150 | tot = ch.QuantumChannel(LX)^ch.QuantumChannel(LY) 151 | 152 | #outA = tot.TrB() 153 | outB = tot.TrA() 154 | 155 | #self.assertEqual(la.norm(outA.liouvillian()-LX),0) 156 | self.assertAlmostEqual(la.norm(outB-np.eye(4)),0,12) 157 | 158 | def test_jamiliokowski(self): 159 | 160 | phi = ch.QuantumChannel(np.eye(4),'choi') 161 | 162 | rho = phi.Jamiliokowski() 163 | 164 | self.assertEqual(la.norm(rho.density_matrix()-.25*np.eye(4)),0) 165 | 166 | 167 | def test_dual(self): 168 | 169 | D = uni.choi(N=3) 170 | DD = D.dual() 171 | DDD = DD.dual() 172 | 173 | self.assertEqual(la.norm(D.choi()-DDD.choi()),0) 174 | 175 | P = ch.QuantumChannel(D.ptm(),'ptm') 176 | PP = P.dual() 177 | PPP = PP.dual() 178 | 179 | self.assertEqual(la.norm(P.ptm()-PPP.ptm()),0) 180 | 181 | K = ch.QuantumChannel(D.kraus(),'kraus') 182 | KK = K.dual() 183 | KKK = KK.dual() 184 | 185 | self.assertEqual(la.norm(K.stiefel()-KKK.stiefel()),0) 186 | 187 | self.assertAlmostEqual(la.norm(DD.choi()-KK.choi()),0) 188 | self.assertAlmostEqual(la.norm(DD.choi()-PP.choi()),0) 189 | 190 | if __name__ == '__main__': 191 | unittest.main() 192 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 3/src/qecc.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from scipy import stats 3 | import qutip as qt 4 | 5 | class SurfaceSyndrome(): 6 | def __init__(self, num_qubits=5): 7 | self.num_qubits = num_qubits 8 | self.build_ctrl_list(num_qubits) 9 | 10 | def build_ctrl_list(self, num_qubits): 11 | self.ctrl_list = [[] for i in range(int(num_qubits + 1. / 2 * num_qubits * (num_qubits - 1)))] 12 | 13 | def generate_xsyndrome_controls(self): 14 | self.add_h2(exceptions=list(range(1, 15))) 15 | self.cnot_gate(0, 2) 16 | self.cnot_gate(0, 1) 17 | self.cnot_gate(0, 4) 18 | self.cnot_gate(0, 3) 19 | self.add_h(exceptions=list(range(1, 15))) 20 | # Hack to push the first and last Hadamards into the first and last CNOT gates 21 | del (self.ctrl_list[0][1]) 22 | del (self.ctrl_list[0][-2]) 23 | return self.ctrl_list 24 | 25 | def generate_zsyndrome_controls(self): 26 | self.add_h2(exceptions=list(range(1, 15))) 27 | self.add_identity(exceptions=[0]) 28 | self.zz_gate(2, 0) 29 | self.zz_gate(1, 0) 30 | self.zz_gate(4, 0) 31 | self.zz_gate(3, 0) 32 | self.add_h(exceptions=list(range(1, 15))) 33 | self.add_identity(exceptions=[0]) 34 | return self.ctrl_list 35 | 36 | def cnot_gate(self, ctrl, target): 37 | if ctrl > target: 38 | temp = ctrl 39 | tqctrl = target 40 | tqtarget = temp 41 | else: 42 | tqctrl = ctrl 43 | tqtarget = target 44 | 45 | sq_ctrl = self.ctrl_list[ctrl] 46 | sq_target = self.ctrl_list[target] 47 | tq_idx = self.num_qubits + self.num_qubits * tqctrl + tqtarget - (tqctrl * (tqctrl + 1) * 1 // 2 + tqctrl + 1) 48 | tq_ctrl = self.ctrl_list[tq_idx] 49 | # U_CNOT = H2.Exp(i*Pi/4).Z1(pi/4).Z2(pi/4).ZZ(-pi/4).H2 50 | ctrl_gates = ['I', 'I4', 'I'] 51 | targ_gates = ['H2', 'I4', 'Z90H'] 52 | tq_gates = ['I', 'ZZ90', 'I'] 53 | for i in range(len(ctrl_gates)): 54 | sq_ctrl.append(ctrl_gates[i]) 55 | sq_target.append(targ_gates[i]) 56 | tq_ctrl.append(tq_gates[i]) 57 | self.ctrl_list[ctrl] = sq_ctrl 58 | self.ctrl_list[target] = sq_target 59 | self.ctrl_list[tq_idx] = tq_ctrl 60 | 61 | self.add_identity(exceptions=[ctrl, target, tq_idx]) 62 | self.add_identity(exceptions=[ctrl, target, tq_idx], key="I4") 63 | #self.add_xy4(exceptions=[ctrl, target, tq_idx]) 64 | #self.add_identity(exceptions=[ctrl, target, tq_idx]) 65 | self.add_identity(exceptions=[ctrl, target, tq_idx]) 66 | 67 | def zz_gate(self, ctrl, target): 68 | if ctrl > target: 69 | temp = ctrl 70 | tqctrl = target 71 | tqtarget = temp 72 | else: 73 | tqctrl = ctrl 74 | tqtarget = target 75 | 76 | sq_ctrl = self.ctrl_list[ctrl] 77 | sq_target = self.ctrl_list[target] 78 | tq_idx = self.num_qubits + self.num_qubits * tqctrl + tqtarget - (tqctrl * (tqctrl + 1) * 1 // 2 + tqctrl + 1) 79 | tq_ctrl = self.ctrl_list[tq_idx] 80 | # U_CNOT = H2.Exp(i*Pi/4).Z1(pi/4).Z2(pi/4).ZZ(-pi/4).H2 81 | ctrl_gates = ['I4'] 82 | targ_gates = ['I4'] 83 | tq_gates = ['ZZ90'] 84 | for i in range(len(ctrl_gates)): 85 | sq_ctrl.append(ctrl_gates[i]) 86 | sq_target.append(targ_gates[i]) 87 | tq_ctrl.append(tq_gates[i]) 88 | self.ctrl_list[ctrl] = sq_ctrl 89 | self.ctrl_list[target] = sq_target 90 | self.ctrl_list[tq_idx] = tq_ctrl 91 | 92 | self.add_identity(exceptions=[ctrl, target, tq_idx], key="I4") 93 | 94 | def add_identity(self, exceptions=[], key="I"): 95 | for i in range(len(self.ctrl_list)): 96 | ctrl = self.ctrl_list[i] 97 | if i not in exceptions: 98 | ctrl.append(key) 99 | self.ctrl_list[i] = ctrl 100 | 101 | def add_xy4(self, exceptions=[]): 102 | for i in range(self.num_qubits): 103 | ctrl = self.ctrl_list[i] 104 | if i not in exceptions: 105 | ctrl.append("X") 106 | ctrl.append("Y") 107 | ctrl.append("X") 108 | ctrl.append("Y") 109 | self.ctrl_list[i] = ctrl 110 | 111 | def add_xi(self, exceptions=[]): 112 | for i in range(len(self.ctrl_list)): 113 | ctrl = self.ctrl_list[i] 114 | if i not in exceptions: 115 | ctrl.append('XI') 116 | self.ctrl_list[i] = ctrl 117 | 118 | def add_x(self, exceptions=[]): 119 | for i in range(len(self.ctrl_list)): 120 | ctrl = self.ctrl_list[i] 121 | if i not in exceptions: 122 | ctrl.append('X') 123 | self.ctrl_list[i] = ctrl 124 | 125 | def add_h(self, exceptions=[]): 126 | for i in range(len(self.ctrl_list)): 127 | ctrl = self.ctrl_list[i] 128 | if i not in exceptions: 129 | ctrl.append('H') 130 | self.ctrl_list[i] = ctrl 131 | 132 | def add_h2(self, exceptions=[]): 133 | for i in range(len(self.ctrl_list)): 134 | ctrl = self.ctrl_list[i] 135 | if i not in exceptions: 136 | ctrl.append('H2') 137 | self.ctrl_list[i] = ctrl 138 | 139 | def reset_ctrl_list(self): 140 | self.build_ctrl_list(5) 141 | 142 | def add_random_bitflip(self, debug=False): 143 | rand_q = np.random.randint(5) 144 | sq_list = self.ctrl_list[rand_q] 145 | rand_gate = np.random.randint(len(sq_list)) 146 | while ((sq_list[rand_gate] != 'I') or self.check_for_two_qubit_gate(rand_q, rand_gate)): 147 | rand_gate = np.random.randint(len(sq_list)) 148 | sq_list[rand_gate] = 'X' 149 | if debug == True: 150 | print(sq_list) 151 | self.ctrl_list[rand_q] = sq_list 152 | self.error_location = [rand_q, rand_gate] 153 | 154 | def check_for_two_qubit_gate(self, q_idx, gate_idx): 155 | # Checks for two qubit gate in ctrl_list 156 | # True: Gate present 157 | gates = [] 158 | for i in range(self.num_qubits): 159 | if q_idx != i: 160 | ctrl, target = np.sort([q_idx, i]) 161 | tq_idx = self.num_qubits + self.num_qubits * ctrl + target - (ctrl * (ctrl + 1) * 1 // 2 + ctrl + 1) 162 | tq_list = self.ctrl_list[tq_idx] 163 | gates.append(tq_list[gate_idx]) 164 | gate_present = False 165 | for gate in gates: 166 | if gate != 'I': 167 | gate_present = True 168 | break 169 | return gate_present 170 | -------------------------------------------------------------------------------- /tests/test_quantum_state_dtype.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.channel as ch 25 | import numpy as np 26 | 27 | 28 | class TestQuantumStateDtype(unittest.TestCase): 29 | 30 | def test_dm_dtype(self): 31 | 32 | D = ch.QuantumState(np.eye(2,dtype=np.complex128)*.5,'dm') 33 | self.assertEqual(type(D._dm.density_matrix),type(np.array([]))) #Changed Type 34 | self.assertEqual(D._dm.density_matrix.dtype,np.complex128) 35 | 36 | D = ch.QuantumState(np.eye(2)*.5,'dm') 37 | self.assertEqual(type(D._dm.density_matrix),type(np.array([]))) #Changed Type 38 | self.assertEqual(D._dm.density_matrix.dtype,np.complex128) 39 | 40 | self.assertEqual(type(D.density_matrix()),type(np.array([]))) #Changed Type 41 | self.assertEqual(D.density_matrix().dtype,np.complex128) 42 | 43 | self.assertEqual(type(D.density_vector()),type(np.array([]))) #Changed Type 44 | self.assertEqual(D.density_vector().dtype,np.complex128) 45 | 46 | self.assertEqual(type(D.bloch_vector()),type(np.array([]))) #Changed Type 47 | self.assertEqual(D.bloch_vector().dtype,np.float64) 48 | 49 | w,b = D.state_mixture() 50 | self.assertEqual(type(w),np.ndarray) 51 | self.assertEqual(w.dtype,np.float64) 52 | self.assertTrue(all([type(bb)==type(np.array([])) for bb in b])) #Changed Type 53 | self.assertTrue(all([bb.dtype==np.complex128 for bb in b])) 54 | 55 | def test_dv_dtype(self): 56 | 57 | D = ch.QuantumState(ch._vec(np.eye(2,dtype=np.complex128)*.5),'dv') 58 | self.assertEqual(type(D._dv.density_vector),type(np.array([]))) #Changed Type 59 | self.assertEqual(D._dv.density_vector.dtype,np.complex128) 60 | 61 | D = ch.QuantumState(ch._vec(np.eye(2)*.5),'dv') 62 | self.assertEqual(type(D._dv.density_vector),type(np.array([]))) #Changed Type 63 | self.assertEqual(D._dv.density_vector.dtype,np.complex128) 64 | 65 | self.assertEqual(type(D.density_vector()),type(np.array([]))) #Changed Type 66 | self.assertEqual(D.density_vector().dtype,np.complex128) 67 | 68 | self.assertEqual(type(D.density_matrix()),type(np.array([]))) #Changed Type 69 | self.assertEqual(D.density_matrix().dtype,np.complex128) 70 | 71 | self.assertEqual(type(D.bloch_vector()),type(np.array([]))) #Changed Type 72 | self.assertEqual(D.bloch_vector().dtype,np.float64) 73 | 74 | w,b = D.state_mixture() 75 | self.assertEqual(type(w),np.ndarray) 76 | self.assertEqual(w.dtype,np.float64) 77 | self.assertTrue(all([type(bb)==type(np.array([])) for bb in b])) #Changed Type 78 | self.assertTrue(all([bb.dtype==np.complex128 for bb in b])) 79 | 80 | def test_bv_dtype(self): 81 | 82 | D = ch.QuantumState(np.eye(3)[:,0],'bv') 83 | self.assertEqual(type(D._bv.bloch_vector),type(np.array([]))) #Changed Type 84 | self.assertEqual(D._bv.bloch_vector.dtype,np.float64) 85 | 86 | D = ch.QuantumState(np.eye(3,dtype=np.complex128)[:,0],'bv') 87 | self.assertEqual(type(D._bv.bloch_vector),type(np.array([]))) #Changed Type 88 | self.assertEqual(D._bv.bloch_vector.dtype,np.float64) 89 | 90 | self.assertEqual(type(D.bloch_vector()),type(np.array([]))) #Changed Type 91 | self.assertEqual(D.bloch_vector().dtype,np.float64) 92 | 93 | self.assertEqual(type(D.density_vector()),type(np.array([]))) #Changed Type 94 | self.assertEqual(D.density_vector().dtype,np.complex128) 95 | 96 | self.assertEqual(type(D.density_matrix()),type(np.array([]))) #Changed Type 97 | self.assertEqual(D.density_matrix().dtype,np.complex128) 98 | 99 | w,b = D.state_mixture() 100 | self.assertEqual(type(w),np.ndarray) 101 | self.assertEqual(w.dtype,np.float64) 102 | self.assertTrue(all([type(bb)==type(np.array([])) for bb in b])) #Changed Type 103 | self.assertTrue(all([bb.dtype==np.complex128 for bb in b])) 104 | 105 | def test_sm_dtype(self): 106 | 107 | D = ch.QuantumState((1.,[np.eye(2,dtype=np.complex128)[:,0]]),'sm') 108 | self.assertEqual(type(D._sm.weights),np.ndarray) 109 | self.assertEqual(D._sm.weights.dtype,np.float64) 110 | self.assertTrue(all([type(b)==type(np.array([])) for b in D._sm.basis])) #Changed Type 111 | self.assertTrue(all([b.dtype==np.complex128 for b in D._sm.basis])) 112 | 113 | D = ch.QuantumState((1.,[np.eye(2)[:,0]]),'sm') 114 | self.assertEqual(type(D._sm.weights),np.ndarray) 115 | self.assertEqual(D._sm.weights.dtype,np.float64) 116 | self.assertTrue(all([type(b)==type(np.array([])) for b in D._sm.basis])) #Changed Type 117 | self.assertTrue(all([b.dtype==np.complex128 for b in D._sm.basis])) 118 | 119 | w,b = D.state_mixture() 120 | self.assertEqual(type(w),np.ndarray) 121 | self.assertEqual(w.dtype,np.float64) 122 | self.assertTrue(all([type(bb)==type(np.array([])) for bb in b])) #Changed Type 123 | self.assertTrue(all([bb.dtype==np.complex128 for bb in b])) 124 | 125 | self.assertEqual(type(D.bloch_vector()),type(np.array([]))) #Changed Type 126 | self.assertEqual(D.bloch_vector().dtype,np.float64) 127 | 128 | self.assertEqual(type(D.density_vector()),type(np.array([]))) #Changed Type 129 | self.assertEqual(D.density_vector().dtype,np.complex128) 130 | 131 | self.assertEqual(type(D.density_matrix()),type(np.array([]))) #Changed Type 132 | self.assertEqual(D.density_matrix().dtype,np.complex128) 133 | 134 | 135 | if __name__ == '__main__': 136 | unittest.main() 137 | -------------------------------------------------------------------------------- /examples/3_PMDExample.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "The basic PMD specification essentially boils down to defining a time-invariant \"basis\" matrices $\\{s_i\\}$ and a set of interaction functions $f_i$. The $f_i$ are functions of a control vector $\\vec{c}(t)$ and a noise vector $\\vec{\\Gamma}(t)$. The total system hamiltonian is then defined by $H(t)=\\sum f_i(\\vec{c}(t),\\vec{\\Gamma}(t))s_i$. Lindblad rates and operators can be defined as well to complete the master equation.\n", 8 | "\n", 9 | "The set $\\{s_i\\}$ need not define an actual basis for some matrix space, but all the $s_i$ need to be of the same dimension. It defaults to the Pauli matrices for qubit operations. The interaction functions $f_i$ are essentially limited only by the ability to code them in Python, and can for example, include nonlinearities. \n", 10 | "\n", 11 | "Other than the basis and the interaction functions, the other key component is a set of parameters for each noise source in $\\Gamma$, which are stored in a ``list`` of Python ``dict`` elements, one per noise source.\n" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import mezze\n", 21 | "from mezze import PMD\n", 22 | "from mezze.core import is_multi_qubit\n", 23 | "from numpy import pi, sin, cos\n", 24 | "\n", 25 | "class ExamplePMD(PMD):\n", 26 | " \"\"\"\n", 27 | " This creates a PMD where there is multiplicative noise in the \\sigma_x direction,\n", 28 | " additive noise in the \\sigma_z direction, and two qubit coupling is achieved through\n", 29 | " \\sigma_z\\otimes\\sigma_z, also with additive (telegraph) noise. Specifying more than \n", 30 | " two qubits generates a Hamiltonian that is defined through one and two qubit interactions.\n", 31 | " \"\"\"\n", 32 | " def __init__(self, num_qubits=1):\n", 33 | " control_dim = 3\n", 34 | " noise_dim = 2\n", 35 | " num_lindblad = 1\n", 36 | " \n", 37 | " if is_multi_qubit(num_qubits):\n", 38 | " #Number of interaction control dimensions and additional noises\n", 39 | " two_control_dim = 1\n", 40 | " two_noise_dim = 1\n", 41 | " PMD.__init__(self, control_dim, noise_dim, num_lindblad, num_qubits, two_control_dim, two_noise_dim)\n", 42 | " else:\n", 43 | " PMD.__init__(self, control_dim, noise_dim, num_lindblad, num_qubits) \n", 44 | " \n", 45 | "\n", 46 | " #The first index \"[0]\" is legacy, but the second \"[1]\" and \"[3]\" correspond\n", 47 | " #to \\sigma_x and \\sigma_z respectively. \n", 48 | " #Note the factor of 1/2 that is basis dependent\n", 49 | " self.single_qubit_control[0][1] = lambda c, gamma: (1+gamma[0])*c[0]*cos(c[1])/2.0\n", 50 | " self.single_qubit_control[0][2] = lambda c, gamma: (1+gamma[0])*c[0]*sin(c[1])/2.0\n", 51 | " \n", 52 | " #If desired, could split additive noise term into single_qubit_noise[3]\n", 53 | " self.single_qubit_control[0][3] = lambda c, gamma: (gamma[1]+c[2])/2.0\n", 54 | " \n", 55 | " #noise_hints contains the relevant parameters for each noise in the PMD\n", 56 | " self.noise_hints[0]={'type':'pink','amp':1.0e-5,'omega_min':2*pi, 'omega_max':2*pi*1e6, 'ctrl': True}\n", 57 | " self.noise_hints[1]={'type':'exp','amp':.25, 'corr_time': 1.0, 'ctrl': False}\n", 58 | " \n", 59 | " #Some made up loss terms, can add more in list\n", 60 | " #Are kronned up for multi-qubit case\n", 61 | " self.lindblad_rates = [.25]# T1 = 4 sec\n", 62 | " self.linblad_operators = [[0.0,0.5,0.5*1j,0]]\n", 63 | " \n", 64 | " #The only \"relevant\" remaining term is self.xtalk, a matrix of crosstalk coefficients\n", 65 | " \n", 66 | " #Terms that can be defined but are essentially ignored are:\n", 67 | " #1. Matrices of (cross-)correlations and (cross-)spectral densities\n", 68 | " #2. Control constraint functions for one and two qubit controls (c_const and two_c_const)\n", 69 | " #3. Default self.basis is Pauli matrices and can be overwritten to e.g., qudit or multi-qudit\n", 70 | " \n", 71 | " if is_multi_qubit(num_qubits):\n", 72 | "\n", 73 | " #For legacy QCS reasons, need to repeat single qubit noise terms\n", 74 | " self.noise_hints[2]={'type':'pink','amp':1.0e-5,'omega_min':2*pi, 'omega_max':2*pi*1e6, 'ctrl': True}\n", 75 | " self.noise_hints[3]={'type':'exp','amp':.25, 'corr_time': 1.0, 'ctrl': False}\n", 76 | " \n", 77 | " #Two qubit control defined as \\sigma_z\\otimes\\sigma_z term\n", 78 | " self.two_qubit_control[0][3][3] = lambda c, gamma: (1+gamma[0])*c[0]/2.0\n", 79 | " \n", 80 | " #Two qubit noise parameters\n", 81 | " self.noise_hints[4]={'type':'telegraph', 'vals':[-.01,.01], 'taus':[1,1], 'ctrl': False}\n", 82 | " \n", 83 | " #If desired could define two_lindblad_rates and two_lindblad_operators\n" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "import numpy as np\n", 93 | "\n", 94 | "#Duration and number of samples for control pulses\n", 95 | "gate_duration = 1.0\n", 96 | "n_steps = 1000\n", 97 | "\n", 98 | "#Identity fields for single qubit gates\n", 99 | "zero_field = mezze.get_zero_control(n_steps)\n", 100 | "\n", 101 | "#Pi-pulse in sigma_{zz} direction\n", 102 | "zz_field = mezze.get_pi_pulse_control(n_steps, gate_duration)\n", 103 | "\n", 104 | "#[Amp1, Phase1, Z1, Amp2, Phase2, Z2, ZZ]\n", 105 | "ctrls = np.transpose(np.array([zero_field, zero_field, zero_field, zero_field, zero_field, zero_field, zz_field]))\n", 106 | "\n", 107 | "\n", 108 | "config = mezze.SimulationConfig(time_length=gate_duration, num_steps=n_steps)\n", 109 | "config.num_runs = 1\n", 110 | "\n", 111 | "pmd = ExamplePMD(2)\n", 112 | "\n", 113 | "ham_func = mezze.HamiltonianFunction(pmd)\n", 114 | "ham = mezze.PrecomputedHamiltonian(pmd, ctrls, config, ham_func.get_function())\n", 115 | "sim = mezze.Simulation(config, pmd, ham)\n", 116 | "\n", 117 | "report = sim.run()\n", 118 | "\n", 119 | "liou = report.channel.liouvillian()" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "mezzeexport", 126 | "language": "python", 127 | "name": "mezzeexport" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.7.3" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 4 144 | } 145 | -------------------------------------------------------------------------------- /examples/6_DynamicalDecouplingExample.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import mezze\n", 10 | "import numpy as np\n", 11 | "import pickle\n", 12 | "import sys" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": null, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "def get_free_evol_trajectories(config_specs, noise_specs):\n", 22 | " '''\n", 23 | " Creates free evolution trajectories based on the simulations configuration specifications and noise specifications\n", 24 | " \n", 25 | " noise_specs: assumes dephasing noise only, further flexibility can be obtained by changing the pmd\n", 26 | " '''\n", 27 | " print('Generating noisy qubit trajectories...')\n", 28 | " noise_amp = noise_specs['amp']\n", 29 | " corr_time = noise_specs['corr_time'] # This does nothing for this white noise model (it is effectively set to 0)\n", 30 | " noise_type = noise_specs['type']\n", 31 | " \n", 32 | " # Set the simulation parameters\n", 33 | " config = mezze.SimulationConfig() # Get the config structure (class)\n", 34 | " mezze.Noise.seed(1000) # Set the rng seed (doesn't work if parallel is set to true below)\n", 35 | " config.num_steps = config_specs['steps'] # Number of time steps to use in the simulation (larger numbers are more accurate)\n", 36 | " config.time_length = config_specs['T'] # Set the time length of the integration\n", 37 | " config.dt = float(config.time_length) / float(config.num_steps) # Set the time-step size\n", 38 | " config.parallel = False # Set to true for parallel Monte Carlo, False otherwise\n", 39 | " config.num_runs = 1 # This sets the number of Monte Carlo trials to use to compute the average superoperator\n", 40 | " config.sample_time(1) # This flag tells the code to report out the superoperator at every time step.\n", 41 | " config.get_unitary = True # Report unitary as opposed to Liouvillian\n", 42 | " time_axis=np.linspace(0., config.time_length, config.num_steps)\n", 43 | "\n", 44 | " # Instantiate the pmd object\n", 45 | " pmd = mezze.implementations.Z_noise_X_control_qubit()\n", 46 | " pmd.noise_hints[0]['corr_time'] = noise_amp\n", 47 | " pmd.noise_hints[0]['amp'] = corr_time\n", 48 | " pmd.noise_hints[0]['type'] = noise_type\n", 49 | "\n", 50 | " # Use the circuit class to generate primitive controls\n", 51 | " x_ctrl = np.zeros(config.num_steps)\n", 52 | " controls = [x_ctrl]\n", 53 | " \n", 54 | " u_targ = np.array([[1.0,0.0],[0.0,1.0]])\n", 55 | " realization_list = []\n", 56 | " for r in range(config_specs['num_runs']):\n", 57 | " # Create the Hamiltonian iterator\n", 58 | " ham_iterator = mezze.PrecomputedHamiltonian.create(pmd, controls, config)\n", 59 | " # Setup the Monte Carlo simulation\n", 60 | " mc = mezze.Simulation(config, pmd, ham_iterator)\n", 61 | " \n", 62 | " report = mc.run()\n", 63 | " realization_list.append(report)\n", 64 | " return realization_list" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "def compute_dd_propagator(sequence, u_list, dt):\n", 74 | " '''\n", 75 | " Computes dynamical decoupling propagator assuming instantaneous pulses\n", 76 | " \n", 77 | " sequence: specifications for the dynamical decoupling sequence\n", 78 | " u_list: list of free evolution trajectories generated by the mezze simulator\n", 79 | " dt: simulation time step size\n", 80 | " '''\n", 81 | " U_tot = np.eye(2)\n", 82 | " U_prev = U_tot\n", 83 | " Px = -1.0j*np.array([[0.0,1.0],[1.0,0.0]])\n", 84 | " Py = -1.0j*np.array([[0.0,-1.0j],[1.0j,0.0]])\n", 85 | " Pz = -1.0j*np.array([[1.0,0.0],[0.0,-1.0]])\n", 86 | " T = 0.0\n", 87 | " for elem in sequence:\n", 88 | " if type(elem) == str:\n", 89 | " if elem == 'X':\n", 90 | " U_tot = Px*U_tot\n", 91 | " elif elem == 'Y':\n", 92 | " U_tot = Py*U_tot\n", 93 | " elif elem == 'Z':\n", 94 | " U_tot = Pz*U_tot\n", 95 | " else:\n", 96 | " T += float(elem)\n", 97 | " n_val = int(T/dt)-1\n", 98 | " U_tot = (u_list.time_samples[n_val].liouvillian()*U_prev.conj().T)*U_tot\n", 99 | " U_prev = u_list.time_samples[n_val].liouvillian()\n", 100 | " return U_tot" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "# CPMG Example" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "def cpmg(cycles, time, pulse):\n", 117 | " '''\n", 118 | " Generates a CPMG sequence for Mezze simulation\n", 119 | " \n", 120 | " cycles: number of sequence repetitions\n", 121 | " time: total cycle time\n", 122 | " pulse: pulse operator specification, either 'X', 'Y', or 'Z'\n", 123 | " '''\n", 124 | " base = [0.25, pulse, 0.5, pulse, 0.25]\n", 125 | " seq = base\n", 126 | " for i in range(cycles-1):\n", 127 | " seq = base + seq\n", 128 | " seq = [float(elem)*(time/cycles) if elem != pulse else elem for elem in seq ]\n", 129 | " return seq" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "total_t = 1\n", 139 | "config_specs = {'steps': 1000, 'T': total_t, 'num_runs': 100}\n", 140 | "dt = float(total_t/config_specs['steps'])\n", 141 | "noise_specs = {'amp': 0.001, 'corr_time': 5, 'type': 'gauss'}\n", 142 | "\n", 143 | "u_realz = get_free_evol_trajectories(config_specs, noise_specs)\n", 144 | "\n", 145 | "u_targ = np.array([[1.0,0.0],[0.0,1.0]])\n", 146 | "F = 0.0\n", 147 | "for uf in u_realz:\n", 148 | " seq = cpmg(cycles=3, time=total_t, pulse='X')\n", 149 | " utot = compute_dd_propagator(seq, uf, dt)\n", 150 | " F += 1.0/4.0*(1.0/config_specs['num_runs'])*abs(np.trace(np.dot(u_targ,utot)))**2.0\n", 151 | "print('Average Gate Fidelity: %2.5f' % F)" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [] 160 | } 161 | ], 162 | "metadata": { 163 | "kernelspec": { 164 | "display_name": "mezze_staging", 165 | "language": "python", 166 | "name": "mezze_staging" 167 | }, 168 | "language_info": { 169 | "codemirror_mode": { 170 | "name": "ipython", 171 | "version": 3 172 | }, 173 | "file_extension": ".py", 174 | "mimetype": "text/x-python", 175 | "name": "python", 176 | "nbconvert_exporter": "python", 177 | "pygments_lexer": "ipython3", 178 | "version": "3.8.2" 179 | } 180 | }, 181 | "nbformat": 4, 182 | "nbformat_minor": 4 183 | } 184 | -------------------------------------------------------------------------------- /tests/test_channel_multi_qudit_xforms.py: -------------------------------------------------------------------------------- 1 | # Copyright: 2015-2017 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). 2 | # All Rights Reserved. 3 | # 4 | # This material may be only be used, modified, or reproduced by or for the U.S. 5 | # Government pursuant to the license rights granted under the clauses at DFARS 6 | # 252.227-7013/7014 or FAR 52.227-14. For any other permission, please contact 7 | # the Office of Technology Transfer at JHU/APL: Telephone: 443-778-2792, 8 | # Email: techtransfer@jhuapl.edu, Website: http://www.jhuapl.edu/ott/ 9 | # 10 | # NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL MAKES 11 | # NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE 12 | # MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL VIABILITY, 13 | # AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER EXPRESS OR IMPLIED, 14 | # INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED WARRANTIES OF PERFORMANCE, 15 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF 16 | # INTELLECTUAL PROPERTY OR OTHER THIRD PARTY RIGHTS. ANY USER OF THE MATERIAL 17 | # ASSUMES THE ENTIRE RISK AND LIABILITY FOR USING THE MATERIAL. IN NO EVENT 18 | # SHALL JHU/APL BE LIABLE TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, 19 | # CONSEQUENTIAL, SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY 20 | # TO USE, THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST 21 | # PROFITS. 22 | 23 | import unittest 24 | import mezze.channel as ch 25 | import numpy as np 26 | import scipy.linalg as la 27 | import mezze.random.uniform as uniform 28 | 29 | class TestMultiXforms(unittest.TestCase): 30 | 31 | def test_2_qubit_bv(self): 32 | 33 | zero = ch.QuantumState([[1,0],[0,0]],'dm') 34 | zz = zero^zero 35 | 36 | #test = np.zeros((15,1)) 37 | #test[0] = 1 38 | #self.assertEqual(la.norm(test-zz.bloch_vector()),0) 39 | self.assertEqual(la.norm(zz.bloch_vector()),1) 40 | 41 | def test_2_qubit_bv_random(self): 42 | 43 | bv = uniform.bloch_vector(4,pure=True) 44 | 45 | self.assertAlmostEqual(np.trace(bv.density_matrix()),1,12) 46 | 47 | dm = uniform.density_matrix(4,rank=1) 48 | 49 | self.assertAlmostEqual(la.norm(dm.bloch_vector()),1,12) 50 | 51 | bv2 = ch.QuantumState(dm.bloch_vector(),'bv') 52 | 53 | dv1 = dm.density_vector() 54 | dv2 = bv2.density_vector() 55 | 56 | self.assertAlmostEqual(la.norm(dm.density_matrix()-bv2.density_matrix()),0,15) 57 | 58 | def test_2_qubit_chi(self): 59 | 60 | I = ch.QuantumChannel(np.eye(2),'unitary') 61 | X = ch.QuantumChannel([[0,1],[1,0]],'unitary') 62 | 63 | comp = I^X 64 | 65 | out_chi = np.zeros((16,16)) 66 | out_chi[1,1] = 1. 67 | 68 | self.assertEqual(la.norm(out_chi-comp.chi()),0) 69 | 70 | def test_2_qubit_ptm(self): 71 | 72 | I2 = ch.QuantumChannel(np.eye(4),'unitary') 73 | 74 | self.assertEqual(la.norm(np.eye(16)-I2.ptm()),0) 75 | 76 | def test_2_qubit_ptm_O(self): 77 | 78 | U = uniform.choi(N=4,rank=1) 79 | 80 | self.assertAlmostEqual(np.abs(la.det(U.ptm()[1:,1:])),1.0,12) 81 | 82 | def test_1_qutrit_ptm_O(self): 83 | 84 | U = uniform.choi(N=3,rank=1) 85 | 86 | self.assertAlmostEqual(np.abs(la.det(U.ptm()[1:,1:])),1.0,12) 87 | 88 | def test_2_qutrit_ptm_O(self): 89 | 90 | U = uniform.choi(N=9,rank=1) 91 | 92 | self.assertAlmostEqual(np.abs(la.det(U.ptm()[1:,1:])),1.0,10) 93 | 94 | def test_2_qubit_chi_rand(self): 95 | 96 | chi1 = np.random.rand(4) 97 | chi1 = chi1/np.sum(chi1) 98 | g1 = ch.QuantumChannel(np.diag(chi1),'chi') 99 | 100 | chi2 = np.random.rand(4) 101 | chi2 = chi1/np.sum(chi2) 102 | g2 = ch.QuantumChannel(np.diag(chi2),'chi') 103 | 104 | g = g1^g2 105 | 106 | self.assertAlmostEqual(la.norm(np.diag(np.kron(chi1,chi2))-g.chi()),0,15) 107 | 108 | def test_2_qutrit_chi(self): 109 | I = ch.QuantumChannel(np.eye(3),'unitary') 110 | 111 | 112 | def test_2_qutrit_chi_rand(self): 113 | 114 | chi1 = np.random.rand(9) 115 | chi1 = chi1/np.sum(chi1) 116 | g1 = ch.QuantumChannel(np.diag(chi1),'chi') 117 | 118 | chi2 = np.random.rand(9) 119 | chi2 = chi1/np.sum(chi2) 120 | g2 = ch.QuantumChannel(np.diag(chi2),'chi') 121 | 122 | g = g1^g2 123 | 124 | self.assertAlmostEqual(la.norm(np.diag(np.kron(chi1,chi2))-g.chi()),0,14) 125 | 126 | def test_2_qubit_random_op(self): 127 | 128 | state = uniform.density_matrix(4) 129 | op = uniform.choi(4) 130 | 131 | out = op*state 132 | 133 | op2 = ch.QuantumChannel(op.ptm(),'ptm') 134 | 135 | self.assertAlmostEqual(la.norm(op.choi()-op2.choi()),0,14) 136 | 137 | #This illustrates the ugliness of wanting a unit sphere 138 | bvout = op.ptm()[1:,1:]@state.bloch_vector()+op.ptm()[1:,0,np.newaxis]*1./np.sqrt(3) 139 | bvout2 = ch.QuantumState(bvout,'bv') 140 | 141 | self.assertAlmostEqual(la.norm(out.bloch_vector()-bvout),0,15) 142 | 143 | self.assertAlmostEqual(la.norm(out.density_matrix()-bvout2.density_matrix()),0,14) 144 | 145 | 146 | def test_1_gubit_random_op(self): 147 | 148 | state = uniform.density_matrix(2) 149 | op = uniform.choi(2) 150 | 151 | out = op*state 152 | 153 | op2 = ch.QuantumChannel(op.ptm(),'ptm') 154 | 155 | self.assertAlmostEqual(la.norm(op.choi()-op2.choi()),0,14) 156 | 157 | bvout = op.ptm()[1:,1:]@state.bloch_vector()+op.ptm()[1:,0,np.newaxis] 158 | bvout2 = ch.QuantumState(bvout,'bv') 159 | 160 | self.assertAlmostEqual(la.norm(out.bloch_vector()-bvout),0,14) 161 | 162 | self.assertAlmostEqual(la.norm(out.density_matrix()-bvout2.density_matrix()),0,14) 163 | 164 | 165 | def test_1_qutrit_random_op(self): 166 | 167 | state = uniform.density_matrix(3) 168 | op = uniform.choi(3) 169 | 170 | out = op*state 171 | 172 | op2 = ch.QuantumChannel(op.ptm(),'ptm') 173 | 174 | self.assertAlmostEqual(la.norm(op.choi()-op2.choi()),0,14) 175 | 176 | bvout = op.ptm()[1:,1:]@state.bloch_vector()+op.ptm()[1:,0,np.newaxis]*1./np.sqrt(2) 177 | bvout2 = ch.QuantumState(bvout,'bv') 178 | 179 | self.assertAlmostEqual(la.norm(out.bloch_vector()-bvout),0,14) 180 | 181 | self.assertAlmostEqual(la.norm(out.density_matrix()-bvout2.density_matrix()),0,14) 182 | 183 | 184 | def test_2_qutrit_random_op(self): 185 | 186 | state = uniform.density_matrix(9) 187 | op = uniform.choi(9) 188 | 189 | out = op*state 190 | 191 | op2 = ch.QuantumChannel(op.ptm(),'ptm') 192 | 193 | self.assertAlmostEqual(la.norm(op.choi()-op2.choi()),0,14) 194 | 195 | #This illustrates the ugliness of wanting a unit sphere 196 | bvout = op.ptm()[1:,1:]@state.bloch_vector()+op.ptm()[1:,0,np.newaxis]*1./np.sqrt(8) 197 | bvout2 = ch.QuantumState(bvout,'bv') 198 | 199 | self.assertAlmostEqual(la.norm(out.bloch_vector()-bvout),0,15) 200 | 201 | self.assertAlmostEqual(la.norm(out.density_matrix()-bvout2.density_matrix()),0,14) 202 | 203 | if __name__ == '__main__': 204 | unittest.main() 205 | -------------------------------------------------------------------------------- /examples/2_SimulationDemo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import mezze\n", 10 | "import numpy as np" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "The first use case considered is to execute a simulation of 1 second simulation time with 1000 time steps, i.e. $\\Delta T$=0.001 sec. 100 Monte Carlo runs are performed in a parallel fashion. For purposes of this demonstration, zero-valued controls are used, creating a (very) noisy identity channel." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "config = mezze.simulation.SimulationConfig(time_length=1.,num_steps=1000)\n", 27 | "config.parallel = True\n", 28 | "config.num_runs = 100\n", 29 | "pmd = mezze.implementations.XYZ_noise_XY_control_Qubit()\n", 30 | "ham = mezze.hamiltonian.HamiltonianFunction(pmd)\n", 31 | "ctrls = np.zeros((1000,3))\n", 32 | "pham = mezze.hamiltonian.PrecomputedHamiltonian(pmd, ctrls, config, ham.get_function())\n", 33 | "sim = mezze.simulation.Simulation(config,pmd,pham)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "The following block actually executes the simulation and returns a report containing the output." 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "report = sim.run()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "The key element of this report is a `QuantumChannel` object that is the Monte Carlo estimate of the specified PMD and input control." 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "report.channel.liouvillian()" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "report.channel.chi()" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "The next example is similar to the first, except that we have configured the simulation to store *both* each monte carlo realization, as well as to include incremental data taken every 500 time steps. These can be used independently. For illustration purposes, only 3 Monte Carlo runs will be performed." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "config = mezze.simulation.SimulationConfig(time_length=1.,num_steps=1000)\n", 91 | "config.parallel = True\n", 92 | "config.num_runs = 3\n", 93 | "\n", 94 | "# Store all the samples being averaged over\n", 95 | "config.realization_sampling = True\n", 96 | "\n", 97 | "# Also keep intermediate realizations every 500 time steps\n", 98 | "config.time_sampling = True\n", 99 | "config.sampling_interval = 500\n", 100 | "\n", 101 | "pmd = mezze.implementations.XYZ_noise_XY_control_Qubit()\n", 102 | "ham = mezze.hamiltonian.HamiltonianFunction(pmd)\n", 103 | "ctrls = np.zeros((1000,2))\n", 104 | "pham = mezze.hamiltonian.PrecomputedHamiltonian(pmd, ctrls, config, ham.get_function())\n", 105 | "sim = mezze.simulation.Simulation(config,pmd,pham)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "report = sim.run()" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "`report.channel` still contains the Monte Carlo estimate of the gate at the specified end time of the simulation." 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "report.channel" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "The individual samples that are averaged in to `report.channel` are in `report.liouvillian_samples`. Note there are 3, as specified in `config.num_runs`" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "report.liouvillian_samples" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "The sub-sampled trajectories are stored in `report.time_samples`. Since the sampling interval was set to 500, each of the 3 Monte Carlo trajectories is sampled 1000/500=2 times. If `config.realization_sampling` were set to false, a list containing the average channel each increment would be reported." 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": {}, 160 | "outputs": [], 161 | "source": [ 162 | "report.time_samples" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "As a final example, this time we set a convergence tolerance (far too high for real usage), rather than a fixed number of runs. While this mode is compatible with `realization_sampling` the number of runs required for a small convergence criterion will likely result in too many samples to comfortably store." 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "config = mezze.simulation.SimulationConfig(time_length=1.,num_steps=1000)\n", 179 | "config.parallel = True\n", 180 | "\n", 181 | "#Do blocks of runs until convergence tolerance reached\n", 182 | "config.num_runs = 4# Set to number of cpus you want to use\n", 183 | "config.run_to_convergence = True\n", 184 | "config.convergence_tolerance = 1e-3\n", 185 | "config.num_runs_below_tolerance = 1\n", 186 | "\n", 187 | "pmd = mezze.implementations.XYZ_noise_XY_control_Qubit()\n", 188 | "ham = mezze.hamiltonian.HamiltonianFunction(pmd)\n", 189 | "ctrls = np.zeros((1000,2))\n", 190 | "pham = mezze.hamiltonian.PrecomputedHamiltonian(pmd, ctrls, config, ham.get_function())\n", 191 | "sim = mezze.simulation.Simulation(config,pmd,pham)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": {}, 198 | "outputs": [], 199 | "source": [ 200 | "report = sim.run()" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "`report.num_runs` keeps track of the total number of Monte Carlo runs performed, which is really only informative when a convergence tolerance is used." 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [ 216 | "print(report.num_runs)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [] 225 | } 226 | ], 227 | "metadata": { 228 | "kernelspec": { 229 | "display_name": "mezzeexport", 230 | "language": "python", 231 | "name": "mezzeexport" 232 | }, 233 | "language_info": { 234 | "codemirror_mode": { 235 | "name": "ipython", 236 | "version": 3 237 | }, 238 | "file_extension": ".py", 239 | "mimetype": "text/x-python", 240 | "name": "python", 241 | "nbconvert_exporter": "python", 242 | "pygments_lexer": "ipython3", 243 | "version": "3.7.3" 244 | } 245 | }, 246 | "nbformat": 4, 247 | "nbformat_minor": 4 248 | } 249 | -------------------------------------------------------------------------------- /examples/4_ExpandedChannelDemo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "This is a follow up to `StateAndChannelDemo.ipynb` that delves in to the different forms of CPTP maps included in the `QuantumChannel` class." 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import mezze.channel as ch\n", 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Representations Supported\n", 25 | "\n", 26 | "`QuantumChannel` support a number of different representations of CPTP maps on which are given in the first argument (`rep`) to the constructor, and the type is specififed by the second argumeny (`in_type`). These representations currently supported are (in terms of qudit dimension $N$):\n", 27 | "\n", 28 | "* Liouvillian: `rep` = $N^2\\times N^2$ matrix, `in_type` = `liou`\n", 29 | "* Choi matrix: `rep` = $N^2\\times N^2$ matrix, `in_type` = `choi`\n", 30 | "* $\\chi$ matrix: `rep` = $N^2\\times N^2$ matrix, `in_type` = `chi` \n", 31 | " * `basis` = `list` of $N\\times N$ matrices (optional) -- Defaults to standard Pauli\n", 32 | "* Kraus operators: `rep` = `list` of $N\\times N$ matrices, `in_type`=`kraus`\n", 33 | "* Unitary operation: `rep` = $N\\times N$ matrix, `in_type`=`unitary`\n", 34 | "* Pauli transfer matrix: `rep`= $N^2\\times N^2$ matrix, `in_type`=`ptm`\n", 35 | "\n", 36 | "Additionally, two specific representations of the Stinespring form are included that have a relationship to random CPTP maps. These are unlikely to be outside of development of random CPTP map code:\n", 37 | "\n", 38 | "* Stiefel form: `\\rep` = $KN\\times N$ matrix, `in_type`=`stiefel`\n", 39 | "* Stiefel-2 form: `\\rep` = $KN\\times N$ matrix, `in_type`=`stiefel2`\n", 40 | "\n", 41 | "Duck-typing is permitted, so that essentially any 2-dimensional array-like structure will work in place as a matrix representation, e.g., `numpy.array`, `numpy.matrix`, and `list` of `list`. Currently, there is no input checking (other than type and size), so specific constraints that ensure CPTP-ness are not. That said, the method `QuantumChannel.is_valid()` can be used to check the validity of the input. Note that this allows for some \"abuse\" of the methods of `QuantumChannel` to perform matrix transforms." 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "# Changing Representations\n", 49 | "\n", 50 | "`QuantumChannel` objects are created using one of the above CPTP map representations, and it will automatically create interneal (`numpy.matrix`-based) representations of a given form when requested, or when they are needed to perform another operation, such as composition. The `QuantumChannel` methods to retrieve this concrete representations are\n", 51 | "\n", 52 | "* `liouvillian()`: returns $N^2\\times N^2$ `numpy.matrix`\n", 53 | "* `choi()`: returns $N^2\\times N^2$ `numpy.matrix`\n", 54 | "* `chi()`: returns $N^2\\times N^2$ `numpy.matrix`\n", 55 | "* `kraus()`: returns `list` of $N\\times N$ `numpy.matrix`\n", 56 | "* `ptm()`: returns $N^2\\times N^2$ `numpy.matrix`\n", 57 | "* `stiefel()`: returns $N^3\\times N$ `numpy.matrix`\n", 58 | "* `stiefel2()`: returns $N^3\\times N$ `numpy.matrix`\n", 59 | "\n", 60 | "The exception to this is the `unitary` `in_type`, which cannot be recovered directly. Instead `QuantumChannel.kraus()[0]` will return the unitary matrix representation of a unitary operation." 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "# Example 1: Unitary Operations\n", 68 | "\n", 69 | "The easiest way to define unitary operations is through the `unitary` `in_type`" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "I = ch.QuantumChannel(np.eye(2),'unitary')\n", 79 | "X = ch.QuantumChannel([[0,1],[1,0]],'unitary')\n", 80 | "Y = ch.QuantumChannel(np.matrix([[0,-1j],[1j,0]]),'unitary')\n", 81 | "Z = ch.QuantumChannel(np.array([[1,0],[0,-1]]),'unitary')\n", 82 | "H = ch.QuantumChannel(1/np.sqrt(2)*np.array([[1,1],[1,-1]]),'unitary')\n", 83 | "CNOT = ch.QuantumChannel([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]],'unitary')" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "# Example 2: Pauli Channels\n", 91 | "\n", 92 | "By default $\\chi$ matrices and Pauli transfer matrices are expressions in the Pauli basis of the Choi and Liouvillian forms, respectively, thus Pauli channels are expressed as diagonal matrices in these forms." 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "Z_depol = ch.QuantumChannel(np.diag([.99,0,0,.01]),'chi')\n", 102 | "Z_depol2 = ch.QuantumChannel(np.diag([1,.98,.98,1]),'ptm')\n", 103 | "\n", 104 | "print('Z_depol in chi-matrix form:')\n", 105 | "print(Z_depol.chi())\n", 106 | "\n", 107 | "print('\\n Z_depol2 in chi-matrix form (same as Z_depol)')\n", 108 | "print(Z_depol2.chi())\n", 109 | "\n", 110 | "uniform_depolarizing = ch.QuantumChannel(np.diag([.97,.01,.01,.01]),'chi')\n", 111 | "non_uniform_depolarizing = ch.QuantumChannel(np.diag([1,.7,.8,.9]),'ptm')\n", 112 | "\n", 113 | "print('\\nUniform depolarizing chi->ptm')\n", 114 | "\n", 115 | "print(uniform_depolarizing.ptm())\n", 116 | "\n", 117 | "print('\\n Non-uniform depolarizing ptm->chi')\n", 118 | "print(np.round(non_uniform_depolarizing.chi(),2))" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "# Example 3: Amplitude Damping\n", 126 | "\n", 127 | "Amplitude damping is expressed in Kraus form (in terms of decay $\\gamma$) via $$A_1=\\begin{bmatrix}1&0\\\\0&\\sqrt{1-\\gamma}\\end{bmatrix}$$ $$A_2=\\begin{bmatrix}0&\\sqrt{\\gamma}\\\\0&0\\end{bmatrix}$$\n", 128 | "\n", 129 | "In Pauli transfer matrix form, this is $$\\begin{bmatrix}1&0&0&0\\\\0&\\sqrt{1-\\gamma}&0&0\\\\0&0&\\sqrt{1-\\gamma}&0\\\\\\gamma&0&0&1-\\gamma\\end{bmatrix}$$" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "gamma = .1**2\n", 139 | "A1 = [[1,0],[0,np.sqrt(1-gamma)]]\n", 140 | "A2 = [[0,np.sqrt(gamma)],[0,0]]\n", 141 | "amp_damp_kraus = ch.QuantumChannel([A1,A2],'kraus')\n", 142 | "\n", 143 | "print('sqrt(1-\\gamma): {0}'.format(np.sqrt(1-gamma)))\n", 144 | "\n", 145 | "print('\\nKraus definition agrees with PTM version:')\n", 146 | "amp_damp_kraus.ptm()" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "# Other Operations\n", 154 | "\n", 155 | "* `is_valid()` checks CP and TP conditions based on `in_type`\n", 156 | "* `rank()` returns the Kraus rank of the CPTP map\n", 157 | "* `is_unital()` returns unitality of CPTP map\n", 158 | "* `is_extremal()` returns `True` if CPTP map is an extremal element of the convex set of CPTP maps\n", 159 | "* `stiefel_tangent()` returns the tangent space element of Stiefel manifold to the CPTP map in Stiefel form." 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": null, 165 | "metadata": {}, 166 | "outputs": [], 167 | "source": [] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "mezzeexport", 173 | "language": "python", 174 | "name": "mezzeexport" 175 | }, 176 | "language_info": { 177 | "codemirror_mode": { 178 | "name": "ipython", 179 | "version": 3 180 | }, 181 | "file_extension": ".py", 182 | "mimetype": "text/x-python", 183 | "name": "python", 184 | "nbconvert_exporter": "python", 185 | "pygments_lexer": "ipython3", 186 | "version": "3.7.3" 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 4 191 | } 192 | -------------------------------------------------------------------------------- /examples/SchWARMAPaperExamples/Figure 2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Simulating Decoupling Protocols\n", 8 | "\n", 9 | "In this notebook we first perform a series of simulated quantum noise spectroscopy experiment. The single-qubit semi-classical noisy Hamiltonian model is\n", 10 | "\n", 11 | "$$H(t) = \\sum_{i=x,y,z}\\eta_i\\sigma_i+\\Omega(t)(\\cos(\\phi(t))\\sigma_x+\\sin(\\phi(t))\\sigma_y)\\,.$$\n", 12 | "\n", 13 | "\n", 14 | "We simulate this via a discrete SchWARMA model with discrete time Hamiltonian\n", 15 | "\n", 16 | "$$H_k = \\sum_{\\ell=x,y,z}y^{(\\ell)}_k\\sigma_\\ell+\\Omega_k(\\cos(phi_k)\\sigma_x+\\sin(\\phi_k)\\sigma_y)\\,.$$\n", 17 | "\n", 18 | "\n", 19 | "Additionally, we also simulate amplitude damping (T1) processes driven via SchWARMA models." 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "%matplotlib inline\n", 29 | "import numpy as np\n", 30 | "import matplotlib.pyplot as pl\n", 31 | "from mezze.random.SchWARMA import correlated_error #Helper function for squared exponential PSD driven models\n", 32 | "import mezze.channel as ch" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "#All noise will have average fixed average fidelity at first time step (replaces amplitude of underyling squared exponential spectrum)\n", 42 | "fid = .99\n", 43 | "\n", 44 | "#correlation time \n", 45 | "corr_time = 3\n", 46 | "num_gates = 100\n", 47 | "num_MC = 10000\n", 48 | "\n", 49 | "#doing stochastic coherent z rotations, multi-axis coherent rotations, and damping\n", 50 | "noise_types=['zrot','xyzrot','amp_damping']\n", 51 | "\n", 52 | "#White and correlated with squared exponential spectrum\n", 53 | "noise_corr={'white':1e-9,'corr':corr_time}\n", 54 | "\n", 55 | "#Control schemes (defined below)\n", 56 | "ctrl=['none','dd','xy4','pfr']" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "# Define Pauli gates in QuantumChannel class\n", 66 | "I = ch.QuantumChannel(ch._sigmaI,'unitary')\n", 67 | "X = ch.QuantumChannel(ch._sigmaX,'unitary')\n", 68 | "Y = ch.QuantumChannel(ch._sigmaY,'unitary')\n", 69 | "Z = ch.QuantumChannel(ch._sigmaZ,'unitary')\n", 70 | "\n", 71 | "# Defines simple control sequences b\n", 72 | "# key: none - no control, identities only\n", 73 | "# dd - repeated X gates at each time step\n", 74 | "# xy4 - alternate between X and Y gates at each time step\n", 75 | "# pfr - pauli frame randomization, random X,Y,Z at each step (not used in paper)\n", 76 | "def ctrl_gate(key,gate_num):\n", 77 | " if key=='none':\n", 78 | " return I\n", 79 | " elif key == 'dd':\n", 80 | " return X\n", 81 | " elif key == 'xy4':\n", 82 | " if gate_num % 2==0:\n", 83 | " return X\n", 84 | " else:\n", 85 | " return Y\n", 86 | " elif key == 'pfr':\n", 87 | " p = np.random.rand()\n", 88 | " if p<0:\n", 89 | " return I\n", 90 | " elif p<1./3:\n", 91 | " return X\n", 92 | " elif p<2./3:\n", 93 | " return Y\n", 94 | " else:\n", 95 | " return Z\n", 96 | " " 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "#Initialize all the various data structures so that they can be accesses as dictionaries\n", 106 | "\n", 107 | "schwarmas ={}\n", 108 | "fids = {}\n", 109 | "unitality={}\n", 110 | "ptms = {}\n", 111 | "for key in noise_types:\n", 112 | " schwarmas[key]={}\n", 113 | " fids[key]={}\n", 114 | " unitality[key]={}\n", 115 | " ptms[key]={}\n", 116 | " for key2 in noise_corr.keys():\n", 117 | " schwarmas[key][key2]=correlated_error(key,noise_corr[key2],fid)\n", 118 | " fids[key][key2]={key3:np.ones((num_MC,num_gates+1))for key3 in ctrl}\n", 119 | " unitality[key][key2]={key3:np.ones((num_MC,num_gates+1))for key3 in ctrl}\n", 120 | " ptms[key][key2]={key3:[] for key3 in ctrl}" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "#Actually run the Monte Carlo simulations and compute the various metrics\n", 130 | "for mc in range(num_MC):\n", 131 | " for key in noise_types:\n", 132 | " for key2 in noise_corr.keys():\n", 133 | " for key3 in ctrl:\n", 134 | " prop = ch.QuantumChannel(np.eye(4),'liou')\n", 135 | " ideal = ch.QuantumChannel(np.eye(4),'liou')\n", 136 | " errs = schwarmas[key][key2].error_stream(num_gates)\n", 137 | " ptms[key][key2][key3].append([prop.ptm()])\n", 138 | " for lcv, gate in enumerate(errs):\n", 139 | " ctrl_g = ctrl_gate(key3,lcv)\n", 140 | " prop = gate*ctrl_g*prop\n", 141 | " ideal = ctrl_g*ideal\n", 142 | " fids[key][key2][key3][mc,lcv+1] = np.real(np.trace(prop.choi().dot(ideal.choi())))/4\n", 143 | " unitality[key][key2][key3][mc,lcv+1]=1.0-np.linalg.norm(np.real(prop.ptm()[1:,0]))\n", 144 | " ptms[key][key2][key3][-1].append(prop.ptm())" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "pl.figure()\n", 154 | "pl.plot(np.mean(fids['xyzrot']['white']['none'],0),'k',label='Mark. Depol.')\n", 155 | "pl.plot(np.mean(fids['xyzrot']['white']['dd'],0),'-xk',markevery=5,label='XX Mark. Depol.')\n", 156 | "pl.plot(np.mean(fids['xyzrot']['white']['xy4'],0),'-ok',markevery=7,label='XY4 Mark. Depol.')\n", 157 | "pl.plot(np.mean(fids['xyzrot']['corr']['none'],0), '--r', label='Corr. Depol.')\n", 158 | "pl.plot(np.mean(fids['xyzrot']['corr']['dd'],0), '--xr', markevery=5,label='XX Corr. Depol.')\n", 159 | "pl.plot(np.mean(fids['xyzrot']['corr']['xy4'],0) ,'--or', markevery=7,label='XY4 Corr. Depol')\n", 160 | "pl.ylabel('Process Fidelity',fontsize=14)\n", 161 | "pl.xlabel('Time, in Gate Lengths',fontsize=14)\n", 162 | "pl.title('Decoupling Multi-Axis Coherent Noise',fontsize=16)\n", 163 | "pl.legend()\n", 164 | "#pl.savefig('schwarma_ctrl_depol.eps',bbox_inches='tight')\n", 165 | "pl.show()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [ 174 | "pl.figure()\n", 175 | "pl.plot(np.mean(unitality['amp_damping']['white']['none'],0),'k',label='Mark. Damp')\n", 176 | "pl.plot(np.mean(unitality['amp_damping']['corr']['none'],0),'--r',label='Corr. Damp')\n", 177 | "pl.plot(np.mean(unitality['amp_damping']['white']['dd'],0),'-xk',markevery=5,label='XX Mark. Damp')\n", 178 | "pl.plot(np.mean(unitality['amp_damping']['corr']['dd'],0),'--xr',markevery=7,label='XX Corr. Damp')\n", 179 | " \n", 180 | "pl.legend()\n", 181 | "pl.ylabel(r'Unitality, 1-$||\\beta||$',fontsize=14)\n", 182 | "pl.xlabel('Time, in Gate Lengths',fontsize=14)\n", 183 | "pl.title('Decoupling Amplitude Damping',fontsize=16)\n", 184 | "#pl.savefig('schwarma_ctrl_damp.eps',bbox_inches='tight')\n", 185 | "pl.show()" 186 | ] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "Python 3", 192 | "language": "python", 193 | "name": "python3" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 3 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython3", 205 | "version": "3.7.5" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 4 210 | } 211 | -------------------------------------------------------------------------------- /examples/5_CorrelatedNoiseExamples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np\n", 10 | "import scipy.linalg as la\n", 11 | "import scipy.signal as si\n", 12 | "import mezze.channel as ch\n", 13 | "import matplotlib.pyplot as pl\n", 14 | "from mezze.random.SchWARMA import ARMA,correlated_error\n", 15 | "#from scipy.misc import factorial\n", 16 | "import scipy.optimize as op\n", 17 | "%matplotlib inline" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "# This just checks that the fidelity numbers work regardless of the correlation time\n", 27 | "err = correlated_error('zrot',corr_time=0,fidelity=.99)\n", 28 | "fs = np.mean([np.real(c.chi()[0,0]) for c in err.error_stream(10000, as_channel=True)])\n", 29 | "print(fs)\n", 30 | "\n", 31 | "err = correlated_error('zdephasing',corr_time=5,fidelity=.96)\n", 32 | "fs = np.mean([np.real(c.chi()[0,0]) for c in err.error_stream(10000, as_channel=True)])\n", 33 | "print(fs)\n", 34 | "\n", 35 | "\n", 36 | "err = correlated_error('depolarizing',corr_time=3,fidelity=.975)\n", 37 | "fs = np.mean([np.real(c.chi()[0,0]) for c in err.error_stream(10000, as_channel=True)])\n", 38 | "print(fs)\n", 39 | "\n", 40 | "err = correlated_error('amp_damping',corr_time=7,fidelity=.999)\n", 41 | "fs = np.mean([np.real(c.chi()[0,0]) for c in err.error_stream(10000, as_channel=True)])\n", 42 | "print(fs)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "While you can get e.g. PTMs by using `QuantumChannel` objects, the easiest way to interface would be to get parameters directly by setting `as_channel=False` in the `next_err` or `error_stream` methods. The below cells shows how to translate the parameter output of the error to a PTM (c.f. `quantumsim.ptm`). Note that I use the `rgen` parameter with a constant seed so that you can see that the PTMs generated the two ways are the same." 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "err = correlated_error('zrot',corr_time=0,fidelity=.99, rgen=np.random.RandomState(0))\n", 59 | "param = err.next_err(as_channel=False)\n", 60 | "print(param)\n", 61 | "print(param, np.cos(np.arccos(np.real(param))*2), np.sin(np.arccos(np.real(param))*2))\n", 62 | "zrot_ptm = np.diag([1,np.cos(np.arccos(np.real(param))*2),np.cos(np.arccos(np.real(param))*2),1])\n", 63 | "zrot_ptm[1,2] = np.sin(np.arccos(np.real(param))*2)\n", 64 | "zrot_ptm[2,1] = -np.sin(np.arccos(np.real(param))*2)\n", 65 | "#c.f. quantumsim.ptm.rotate_z_ptm(np.arccos(np.real(param))*2)\n", 66 | "print(zrot_ptm)\n", 67 | "same_err = correlated_error('zrot',corr_time=0,fidelity=.99, rgen=np.random.RandomState(0))\n", 68 | "print(same_err.next_err(as_channel=True).ptm())" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "err = correlated_error('zdephasing',corr_time=0,fidelity=.99, rgen=np.random.RandomState(0))\n", 78 | "dephase_param = err.next_err(as_channel=False)\n", 79 | "print(dephase_param, 2*dephase_param -1)\n", 80 | "#c.f. quantumsim.ptm.dephasing_ptm(1-(2*dephase_param-1),1-(2*dephase_param-1),0)\n", 81 | "dephase_ptm = np.diag([1,2*dephase_param-1,2*dephase_param-1,1])\n", 82 | "print(dephase_ptm)\n", 83 | "same_err = correlated_error('zdephasing',corr_time=0,fidelity=.99, rgen=np.random.RandomState(0))\n", 84 | "print(same_err.next_err(as_channel=True).ptm())" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "#Depolarizing case\n", 94 | "err = correlated_error('depolarizing',corr_time=3,fidelity=.975, rgen=np.random.RandomState(0))\n", 95 | "depol_param = err.next_err(as_channel=False)\n", 96 | "print(depol_param, depol_param-(1-depol_param)/3)\n", 97 | "#c.f. quantumsim.ptm.dephasing_ptm(1-(depol_param-(1-depol_param))/3,1-(depol_param-(1-depol_param)/3),1-(depol_param-(1-depol_param)/3))\n", 98 | "depol_ptm = np.diag([1,depol_param-(1-depol_param)/3,depol_param-(1-depol_param)/3,depol_param-(1-depol_param)/3])\n", 99 | "print(depol_ptm)\n", 100 | "same_err = correlated_error('depolarizing',corr_time=3,fidelity=.975, rgen=np.random.RandomState(0))\n", 101 | "print(same_err.next_err(as_channel=True).ptm())" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "#Damping Case\n", 111 | "#Depolarizing case\n", 112 | "err = correlated_error('amp_damping',corr_time=3,fidelity=.975, rgen=np.random.RandomState(0))\n", 113 | "gamma = err.next_err(as_channel=False)\n", 114 | "print(gamma, np.sqrt(1-gamma), 1-gamma)\n", 115 | "damp_ptm = np.diag([1, np.sqrt(1-gamma), np.sqrt(1-gamma), 1-gamma])\n", 116 | "damp_ptm[3,0] = gamma\n", 117 | "#c.f. quantumsim.ptm.amp_ph_damping_ptm(gamma,0)\n", 118 | "print(damp_ptm)\n", 119 | "same_err = correlated_error('amp_damping',corr_time=3,fidelity=.975, rgen=np.random.RandomState(0))\n", 120 | "print(same_err.next_err(as_channel=True).ptm())" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "For `zrot` this returns $exp(i2\\theta)$, for `depolarzing` and `zdephasing` this returns the probability $\\chi_{1,1}$ coefficient, i.e., the probability that the error is the identity map (no error). The errors for the other Paulis can be computed accordingly. Thus, `zdephasing` and `zrot` can effectively be used to compute dephasing/coherent rotation errors in other dimensions. For `amp_damping`, the decay parameter $\\gamma$ is returned." 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "# Everything Below Here Is Check/Backup for Posterity" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "The below cell proves out the correlation time, defined here using a Gaussian window, such that the correlation time is apprximately the time where the autocorrelation function is equal to $\\exp(-4)$, a standard convention in signal processing." 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "#Initialize Filters\n", 151 | "b0 = .02 #markovian\n", 152 | "corr_times = list(range(1,21))\n", 153 | "filter_orders = 2*np.array(corr_times)+1\n", 154 | "\n", 155 | "bs = [np.array([1.])]+[si.gaussian(fo,std=ct/4.) for ct,fo in zip(corr_times,filter_orders)]\n", 156 | "bs = [b/np.sqrt(np.sum(b**2))*b0 for b in bs]\n", 157 | "\n", 158 | "# for b in bs:\n", 159 | "# w, h = si.freqz(b=b, a =[1])\n", 160 | "# pl.plot(w/(2*np.pi), 10*np.log10(abs(h)))\n", 161 | "# pl.legend([1]+cut_offs)\n", 162 | "# pl.show()\n", 163 | "\n", 164 | "max_order = 1000\n", 165 | "acv = np.zeros((len(bs),max_order))\n", 166 | "for i,b in enumerate(bs):\n", 167 | " bb = np.zeros(max_order)\n", 168 | " bb[:len(b)] = b\n", 169 | " for tau in range(max_order):\n", 170 | " acv[i,tau] = np.sum(bb[:max_order-tau]*bb[tau:])\n", 171 | "\n", 172 | "pl.figure()\n", 173 | "pl.plot(acv.T/acv.T[0])\n", 174 | "pl.legend([0]+corr_times,)\n", 175 | "#pl.xscale('log')\n", 176 | "pl.xlim(0,2*np.max(corr_times))\n", 177 | "pl.plot([0,2*np.max(corr_times)],[np.exp(-4),np.exp(-4)],'--')\n", 178 | "pl.yscale('log')\n", 179 | "pl.ylim([.001,1])\n", 180 | "pl.grid()\n", 181 | "pl.ylabel('Autocorrelation')\n", 182 | "pl.xlabel('Time')\n", 183 | "pl.show()" 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "kernelspec": { 189 | "display_name": "mezzeexport", 190 | "language": "python", 191 | "name": "mezzeexport" 192 | }, 193 | "language_info": { 194 | "codemirror_mode": { 195 | "name": "ipython", 196 | "version": 3 197 | }, 198 | "file_extension": ".py", 199 | "mimetype": "text/x-python", 200 | "name": "python", 201 | "nbconvert_exporter": "python", 202 | "pygments_lexer": "ipython3", 203 | "version": "3.7.3" 204 | } 205 | }, 206 | "nbformat": 4, 207 | "nbformat_minor": 4 208 | } 209 | --------------------------------------------------------------------------------