Exemplo n.º 1
0
        public SimulateNoiseMagic(IExecutionEngine engine, ISymbolResolver resolver, IConfigurationSource configurationSource, INoiseModelSource noiseModelSource, ILogger <SimulateNoiseMagic> logger) : base(
                "experimental.simulate_noise",
                new Microsoft.Jupyter.Core.Documentation
        {
            Summary     = "Runs a given function or operation on the OpenSystemsSimulator target machine.",
            Description = $@"
                    > **⚠ WARNING:** This magic command is **experimental**,
                    > is not supported, and may be removed from future versions without notice.

                    This magic command allows executing a given function or operation
                    on the OpenSystemsSimulator target, simulating how that function or operation
                    will perform when run on noisy quantum hardware.

                    #### See also

                    - [`%config`]({KnownUris.ReferenceForMagicCommand("config")})
                    - [`%experimental.noise_model`]({KnownUris.ReferenceForMagicCommand("experimental.noise_model")})

                    #### Required parameters

                    - Q# operation or function name. This must be the first parameter, and must be a valid Q# operation
                    or function name that has been defined either in the notebook or in a Q# file in the same folder.
                    - Arguments for the Q# operation or function must also be specified as `key=value` pairs.

                    #### Remarks

                    The behavior of this magic command can be controlled through the `%experimental.noise_model` magic command,
                    and the `opensim.nQubits` and `opensim.representation` configuration settings.
                ".Dedent(),
            Examples    = new string[]
            {
                @"
                        Simulate a Q# operation defined as `operation MyOperation() : Result`:
                        ```
                        In []: %simulate MyOperation
                        Out[]: <return value of the operation>
                        ```
                    ".Dedent(),
                @"
                        Simulate a Q# operation defined as `operation MyOperation(a : Int, b : Int) : Result`:
                        ```
                        In []: %simulate MyOperation a=5 b=10
                        Out[]: <return value of the operation>
                        ```
                    ".Dedent(),
            }
        })
        {
            this.SymbolResolver      = resolver;
            this.ConfigurationSource = configurationSource;
            this.Logger           = logger;
            this.NoiseModelSource = noiseModelSource;

            if (engine is IQSharpEngine iQSharpEngine)
            {
                iQSharpEngine.RegisterDisplayEncoder(new MixedStateToHtmlDisplayEncoder());
                iQSharpEngine.RegisterDisplayEncoder(new StabilizerStateToHtmlDisplayEncoder(configurationSource));
            }
        }
Exemplo n.º 2
0
        public NoiseModelMagic(IExecutionEngine engine, INoiseModelSource noiseModelSource, ILogger <NoiseModelMagic> logger) : base(
                "experimental.noise_model",
                new Microsoft.Jupyter.Core.Documentation
        {
            Summary     = "Gets, sets, saves, or loads a noise model used in simulating quantum operations.",
            Description = @"
                    > **⚠ WARNING:** This magic command is **experimental**,
                    > is not supported, and may be removed from future versions without notice.

                    This magic command allows accessing or modifying the noise model used by
                    the `%experimental.simulate_noise` magic command.
                ".Dedent(),
            Examples    = new string[]
            {
                @"
                        Return the currently set noise model:
                        ```
                        In []: %experimental.noise_model
                        ```
                    ".Dedent(),
                @"
                        Return the built-in noise model with a given name:
                        ```
                        In []: %experimental.noise_model --get-by-name ideal
                        ```
                    ",
                @"
                        Sets the noise model to a built-in named noise model:
                        ```
                        In []: %experimental.noise_model --load-by-name ideal_stabilizer
                        ```
                    ".Dedent(),
                @"
                        Set the noise model to a noise model given as JSON:
                        ```
                        In []: %experimental.noise_model { ... }
                        ```
                    ".Dedent(),
                @"
                        Save the current noise model to a JSON file named
                        `noise-model.json`:
                        ```
                        In []: %experimental.noise_model --save noise-model.json
                        ```
                    ".Dedent(),
                @"
                        Load the noise model stored in `noise-model.json`,
                        making it the active noise model:
                        ```
                        In []: %experimental.noise_model --load noise-model.json
                        ```
                    ".Dedent()
            }
        })
        {
            this.NoiseModelSource = noiseModelSource;
            if (engine is IQSharpEngine iQSharpEngine)
            {
                iQSharpEngine.RegisterDisplayEncoder(new NoiseModelToHtmlDisplayEncoder());
            }
        }