Ejemplo n.º 1
0
        public static QuantumSimulator WithJupyterDisplay(this QuantumSimulator simulator, IChannel channel, IConfigurationSource configurationSource)
        {
            simulator.DisableLogToConsole();
            simulator.OnLog += channel.Stdout;

            simulator.Register(
                typeof(Diagnostics.DumpMachine <>), typeof(JupyterDumpMachine <>),
                signature: typeof(ICallable)
                );

            var op         = ((GenericCallable)simulator.GetInstance(typeof(Microsoft.Quantum.Diagnostics.DumpMachine <>)));
            var concreteOp = op.FindCallable(typeof(QVoid), typeof(QVoid));

            ((JupyterDumpMachine <QVoid>)concreteOp).Channel             = channel;
            ((JupyterDumpMachine <QVoid>)concreteOp).ConfigurationSource = configurationSource;
            concreteOp = op.FindCallable(typeof(string), typeof(QVoid));
            ((JupyterDumpMachine <string>)concreteOp).Channel             = channel;
            ((JupyterDumpMachine <string>)concreteOp).ConfigurationSource = configurationSource;

            simulator.Register(
                typeof(Diagnostics.DumpRegister <>), typeof(JupyterDumpRegister <>),
                signature: typeof(ICallable)
                );

            op         = ((GenericCallable)simulator.GetInstance(typeof(Microsoft.Quantum.Diagnostics.DumpRegister <>)));
            concreteOp = op.FindCallable(typeof(QVoid), typeof(QVoid));
            ((JupyterDumpRegister <QVoid>)concreteOp).Channel             = channel;
            ((JupyterDumpRegister <QVoid>)concreteOp).ConfigurationSource = configurationSource;
            concreteOp = op.FindCallable(typeof(string), typeof(QVoid));
            ((JupyterDumpRegister <string>)concreteOp).Channel             = channel;
            ((JupyterDumpRegister <string>)concreteOp).ConfigurationSource = configurationSource;

            return(simulator);
        }
Ejemplo n.º 2
0
        public void QSimVerifyPrimitivesCompleteness()
        {
            using (var sim = new QuantumSimulator())
            {
                var ops =
                    from op in typeof(Intrinsic.X).Assembly.GetExportedTypes()
                    where op.IsSubclassOf(typeof(AbstractCallable))
                    where !op.IsNested
                    select op;

                var missing = new List <Type>();

                foreach (var op in ops)
                {
                    try
                    {
                        var i = sim.GetInstance(op);
                        Assert.NotNull(i);
                    }
                    catch (Exception)
                    {
                        missing.Add(op);
                    }
                }

                Assert.Empty(missing);
            }
        }