<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts | Kartik Singhal</title><link>https://k4rtik.github.io/post/</link><atom:link href="https://k4rtik.github.io/post/index.xml" rel="self" type="application/rss+xml"/><description>Posts</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>© 2018-2026</copyright><lastBuildDate>Sun, 01 Jan 2017 00:00:00 +0000</lastBuildDate><image><url>https://k4rtik.github.io/media/icon_hu95bcf4001b8c3a9b9433f24a55ec28ef_13239_512x512_fill_box_center_3.png</url><title>Posts</title><link>https://k4rtik.github.io/post/</link></image><item><title>Q# Programming Language</title><link>https://k4rtik.github.io/post/qsharp/</link><pubDate>Tue, 23 Aug 2022 10:51:00 -0500</pubDate><guid>https://k4rtik.github.io/post/qsharp/</guid><description>&lt;p>This post summarizes the features of Microsoft&amp;rsquo;s &lt;a href="https://github.com/microsoft/qsharp-language/tree/main/Specifications/Language#q-language" target="_blank" rel="noopener">Q# Language Specification&lt;/a>. It is derived from §2.1 of &lt;a href="https://k4rtik.github.io/files/thesis-proposal.pdf">my thesis proposal&lt;/a>. I also created a &lt;a href="https://k4rtik.github.io/files/qsharp-spec.pdf">PDF version&lt;/a> of the Q# language specification.&lt;/p>
&lt;hr>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>Q# is a standalone domain-specific programming language from Microsoft for
writing and running quantum programs. It lets one seamlessly combine
classical and quantum computation while providing a separation between
pure classical &lt;code>function&lt;/code>s and effectful quantum &lt;code>operation&lt;/code>s, collectively known as
&lt;em>callables&lt;/em>. The programming model assumes a high level of abstraction
with no notion of quantum circuits or quantum states.&lt;/p>
&lt;p>Q# organizes programs using &lt;code>namespace&lt;/code>s that contain &lt;code>open&lt;/code> directives, declaration of
callables, and type declarations for user-defined types. Namespaces are
not hierarchical, however; i.e., there is no relation between two
namespaces even if they have a common prefix.&lt;/p>
&lt;p>User-defined types declared using &lt;code>newtype&lt;/code> are essentially records. Callables, as
mentioned earlier, include &lt;code>function&lt;/code>s and &lt;code>operation&lt;/code>s. Operations may carry &lt;em>operation
characteristics&lt;/em>, &lt;code>Adj&lt;/code> and &lt;code>Ctl&lt;/code>, to declare support for &lt;em>functors&lt;/em>&amp;mdash; &lt;code>Adjoint&lt;/code>
and &lt;code>Controlled&lt;/code> &amp;mdash;to
enable metaprogramming. They may also include additional
&lt;em>specializations&lt;/em> for their &lt;code>adjoint&lt;/code> and &lt;code>controlled&lt;/code> variants, but the reference
implementation does not check these specializations for correctness. The
default specification is the &lt;code>body&lt;/code> of the operation.&lt;/p>
&lt;p>Instead of providing a custom specialization, the user can also ask the
compiler to auto-generate a specialization using directives such as &lt;code>self&lt;/code>, &lt;code>invert&lt;/code>,
and &lt;code>distribute&lt;/code>. Auto-generation is not possible in all cases, such as when
&lt;code>mutable&lt;/code> variables are involved. If the programmer provides no specialization or
generation directive, the directive &lt;code>auto&lt;/code> applies by default. For example, the
following &lt;code>operation&lt;/code>s are equivalent:&lt;/p>
&lt;pre>&lt;code class="language-csharp">operation Trivial() : Unit
is Adj + Ctl { }
operation Trivial() : Unit {
body (...) { } // dots indicate same arguments as declaration
adjoint auto;
controlled auto;
controlled adjoint auto;
}
&lt;/code>&lt;/pre>
&lt;p>Q# supports single-line comments that start with double forward slash
characters (&lt;code>//&lt;/code>). There is also support for documentation comments that
start with triple slashes (&lt;code>///&lt;/code>), which may include headers such as
&lt;em>Description&lt;/em>, &lt;em>Input&lt;/em>, &lt;em>Output&lt;/em>, &lt;em>Type Parameters&lt;/em>, &lt;em>Example&lt;/em>, among
others.&lt;/p>
&lt;h2 id="statements">Statements&lt;/h2>
&lt;p>Statements familiar from classical programming include &lt;code>return&lt;/code>,
&lt;code>fail&lt;/code>, &lt;code>let&lt;/code> &amp;amp; &lt;code>mutable&lt;/code> for
variable declaration, &lt;code>set&lt;/code> for rebinding mutable variables, an iterator-based
&lt;code>for&lt;/code> loop, a conditional &lt;code>while&lt;/code> loop, and a branching &lt;code>if&lt;/code>-&lt;code>elif&lt;/code>-&lt;code>else&lt;/code> conditional. Quantum-specific
statements include &lt;code>use&lt;/code> &amp;amp; &lt;code>borrow&lt;/code> for qubit allocation, a &lt;code>repeat&lt;/code>-&lt;code>until&lt;/code>-&lt;code>fixup&lt;/code> loop for expressing the
&lt;em>repeat-until-success&lt;/em> pattern, and a &lt;code>within&lt;/code>-&lt;code>apply&lt;/code> statement for
expressing the (automatic) &lt;em>uncomputation&lt;/em> pattern. Statements also
include calls to any callable returning &lt;code>Unit&lt;/code>.&lt;/p>
&lt;p>Note that any classical statements may appear in &lt;code>operation&lt;/code>s but not vice versa
for quantum-specific statements and &lt;code>function&lt;/code>s&amp;mdash;a consequence of this
restriction is that &lt;code>function&lt;/code>s can never call &lt;code>operation&lt;/code>s. Further, the &lt;code>while&lt;/code> loop is currently
not supported inside an &lt;code>operation&lt;/code>.&lt;/p>
&lt;p>The &lt;code>use&lt;/code> statement provides access to freshly allocated qubits corresponding
to state |0⟩, while the &lt;code>borrow&lt;/code> statement allows access to previously allocated
(and potentially entangled) qubits. Q# assumes that a program always
starts with no qubits, &lt;code>operation&lt;/code>s allocate qubits as needed, and they get
automatically deallocated at the end of lexical scope, i.e., the
lifetime of a qubit variable is equal to its lexical scope.&lt;/p>
&lt;h2 id="expressions">Expressions&lt;/h2>
&lt;p>Q# expressions are values (literals) and identifiers. They can be combined
using &lt;em>operators&lt;/em>, &lt;em>modifiers&lt;/em>, and &lt;em>combinators&lt;/em>. Since all compound
data types in Q# are immutable, it includes a notion of a &lt;em>copy-and-update&lt;/em>
operator (&lt;code>w/ &amp;lt;-&lt;/code>) apart from several familiar operators such as a ternary
conditional (&lt;code>? |&lt;/code>), logical, comparison, bitwise, and arithmetic operators.
There is also a concatenation operator (&lt;code>+&lt;/code>) for &lt;code>String&lt;/code>s and arrays.&lt;/p>
&lt;p>Modifiers include the &lt;code>Adjoint&lt;/code> and &lt;code>Controlled&lt;/code> functor applications and the unwrap modifier
(&lt;code>!&lt;/code>) that deconstructs a user-defined type (UDT). Combinators include call
(&lt;code>()&lt;/code>), named item access (&lt;code>::&lt;/code>) for UDTs, and array item access (&lt;code>[]&lt;/code>).&lt;/p>
&lt;p>Literals include values for most data types: &lt;code>Unit&lt;/code> (&lt;code>()&lt;/code>), &lt;code>Int&lt;/code>, &lt;code>BigInt&lt;/code>, &lt;code>Double&lt;/code>,
&lt;code>Bool&lt;/code> (&lt;code>true&lt;/code> and &lt;code>false&lt;/code>), &lt;code>String&lt;/code>, &lt;code>Result&lt;/code> (&lt;code>Zero&lt;/code> and &lt;code>One&lt;/code>), &lt;code>Pauli&lt;/code> (&lt;code>PauliI&lt;/code>, &lt;code>PauliX&lt;/code>,
&lt;code>PauliY&lt;/code>, and &lt;code>PauliZ&lt;/code>), &lt;code>Range&lt;/code>, arrays, and tuples. &lt;code>Qubit&lt;/code> type is opaque and has no
literal.&lt;/p>
&lt;p>For &lt;code>function&lt;/code>s and &lt;code>operation&lt;/code>s, there is support for creating &lt;em>closures&lt;/em> using &lt;em>lambda
expressions&lt;/em> (&lt;code>-&amp;gt;&lt;/code> and &lt;code>=&amp;gt;&lt;/code>, respectively) and &lt;em>partial applications&lt;/em>.&lt;/p>
&lt;h2 id="type-system">Type System&lt;/h2>
&lt;p>Q# currently features a fairly simple type system. Apart from the primitive
data types listed in the preceding section, there is support for
compound data types such as arrays, tuples, user-defined types, and
callables. Callables are first-class values, and hence, Q# supports
higher-order programming. The type of an &lt;code>operation&lt;/code> follows the schema &lt;code>&amp;lt;TIn&amp;gt; =&amp;gt; &amp;lt;TOut&amp;gt; is &amp;lt;Char&amp;gt;&lt;/code> where &lt;code>Char&lt;/code>, the
operation characteristics (&lt;code>Adj&lt;/code>, &lt;code>Ctl&lt;/code>, or both), may be omitted if unneeded.
Similarly, the type schema of a &lt;code>function&lt;/code> is &lt;code>&amp;lt;TIn&amp;gt; -&amp;gt; &amp;lt;TOut&amp;gt;&lt;/code>. Further, callables allow type
parameterization to support generic programming.&lt;/p>
&lt;p>There is limited support for subtyping. Specifically, an operation that
supports more functors (declared using the operation&amp;rsquo;s characteristics)
than needed at the call site may be substituted. Callables require
explicit type declarations, but most types in callable bodies are
inferable by Q#&amp;rsquo;s Hindley-Milner-style type inference algorithm.&lt;/p>
&lt;h2 id="remarks">Remarks&lt;/h2>
&lt;p>In essence, a Q# program describes quantum computation at a high
abstraction level without adherence to the circuit model. With choices
such as immutability by default and a clean separation between
operations that perform (quantum) side effects and functions that
perform pure classical computation, Q# represents a safe synthesis of
functional and imperative programming styles in the design space of
programming languages for quantum computation. This synthesis is
reminiscent of Algol-like languages in the classical PL literature. However,
there are limitations. Q# allows uncontrolled aliasing of qubits that,
like in classical programming languages, can lead to unsafe computation.
Even though the quantum memory model in Q# is to allocate and deallocate
qubits in a stack-like manner, the compiler does not enforce this stack
discipline. See our paper &lt;a href="https://k4rtik.github.io/publication/q-algol/">Q# as a Quantum Algorithmic Language&lt;/a> (QAlgol) for early solutions toward these problems.&lt;/p></description></item><item><title>Photo Website Archive</title><link>https://k4rtik.github.io/post/photo-website-archive/</link><pubDate>Sat, 27 Oct 2018 16:05:38 -0500</pubDate><guid>https://k4rtik.github.io/post/photo-website-archive/</guid><description>
&lt;figure id="figure-the-four-albums">
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://k4rtik.github.io/img/exposure-featured.png" alt="The four albums" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;figcaption>
The four albums
&lt;/figcaption>&lt;/figure>
&lt;p>&lt;em>Before clicking on any of the archive links below, see the latest update at the bottom.&lt;/em>&lt;/p>
&lt;p>I did a photo project over the past year in which I used my &lt;a href="https://en.wikipedia.org/wiki/Pixel_2" target="_blank" rel="noopener">Pixel 2&lt;/a> to capture photographs, mostly candid portraits. The free &lt;a href="https://exposure.co/" target="_blank" rel="noopener">Exposure&lt;/a> subscription, where I posted the photos from that project, is expiring, so I created an archive here.&lt;/p>
&lt;ul>
&lt;li>Homepage: &lt;a href="https://k4rtik.github.io/exposure/home.png">PNG&lt;/a> / &lt;a href="https://k4rtik.github.io/exposure/home.pdf">PDF&lt;/a>&lt;/li>
&lt;li>Grad Faces of UChicago (An Adventure in Portraits)
&lt;ul>
&lt;li>Week 1: &lt;a href="https://k4rtik.github.io/exposure/week1.png">PNG&lt;/a> / &lt;a href="https://k4rtik.github.io/exposure/week1.pdf">PDF&lt;/a>&lt;/li>
&lt;li>Week 2 (Halloween Edition): &lt;a href="https://k4rtik.github.io/exposure/week2.png">PNG&lt;/a> / &lt;a href="https://k4rtik.github.io/exposure/week2.pdf">PDF&lt;/a>&lt;/li>
&lt;li>Week 3 (Diwali Edition): &lt;a href="https://k4rtik.github.io/exposure/week3.png">PNG&lt;/a> / &lt;a href="https://k4rtik.github.io/exposure/week3.pdf">PDF&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>An Indian Wedding (in Stills): &lt;a href="https://k4rtik.github.io/exposure/wedding1.png">PNG1&lt;/a>, &lt;a href="https://k4rtik.github.io/exposure/wedding2.png">PNG2&lt;/a> / &lt;a href="https://k4rtik.github.io/exposure/wedding.pdf">PDF&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Update (Sun Dec 30, 2018):&lt;/strong> Turns out Wayback Machine of the Internet Archive has much better-preserved versions of my albums. See:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://web.archive.org/web/20181012164942/https://www.k4rtik.me/" target="_blank" rel="noopener">Homepage&lt;/a>&lt;/li>
&lt;li>Grad Faces of UChicago (An Adventure in Portraits)
&lt;ul>
&lt;li>&lt;a href="https://web.archive.org/web/20180320154759/https://www.k4rtik.me/grad-faces-of-uchicago" target="_blank" rel="noopener">Week 1&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://web.archive.org/web/20180320154911/https://www.k4rtik.me/grad-faces-of-uchicago-1" target="_blank" rel="noopener">Week 2 (Halloween Edition)&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://web.archive.org/web/20180320154953/https://www.k4rtik.me/grad-faces-of-uchicago-2" target="_blank" rel="noopener">Week 3 (Diwali Edition)&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="https://web.archive.org/web/20181024144142/https://www.k4rtik.me/an-indian-wedding" target="_blank" rel="noopener">An Indian Wedding (in Stills)&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Update (Tue Feb 12, 2019):&lt;/strong> Turns out I was completely wrong about my Exposure subscription, all of the photos are still browsable at &lt;a href="https://k4rtik.exposure.co/" target="_blank" rel="noopener">k4rtik.exposure.co&lt;/a>. So much for my pessimism in free services and lack of due diligence. Sigh.&lt;/p></description></item><item><title>Grad School Admissions Resources</title><link>https://k4rtik.github.io/post/grad-school/</link><pubDate>Tue, 18 Sep 2018 14:04:24 -0500</pubDate><guid>https://k4rtik.github.io/post/grad-school/</guid><description>&lt;p>I often get asked by students from India about how does the graduate admission
process work for both MS and PhD programs in the US. After sharing advice
from my own limited experience, I generally end up sharing a bunch of links with
the students. I thought of collecting them in a single place for easy sharing
and posterity. Note that most of these are relevant only to Computer Science
programs.&lt;/p>
&lt;h2 id="general-resources">General Resources&lt;/h2>
&lt;h3 id="advice-for-applicants">Advice for Applicants&lt;/h3>
&lt;ul>
&lt;li>&lt;a href="http://precog.iiitd.edu.in/graduate-school-faqs.html" target="_blank" rel="noopener">FAQs - Preparing, Applying and Deciding on Graduate Schools&lt;/a> &amp;ndash; an FAQ maintained by Prof. Ponnurangam Kumaraguru &amp;ldquo;PK&amp;rdquo; of IIIT-Delhi&lt;/li>
&lt;li>&lt;a href="https://decomposition.al/blog/2017/03/30/should-you-do-an-ms-before-doing-a-phd/" target="_blank" rel="noopener">Should you do an MS before doing a Ph.D.?&lt;/a> &amp;ndash; a blog post by Prof. Lindsey Kuper of UC Santa Cruz&lt;/li>
&lt;li>&lt;a href="https://twitter.com/vj_chidambaram/status/933388419589459969" target="_blank" rel="noopener">PhD/MS applications writing SOP/research statements, here is a series of tweets on what to avoid, and what to mention in your SOP. Targeted especially at international students. 1/n&lt;/a> &amp;ndash; a tweet thread by Prof. Vijay Chidambaram of UT Austin&lt;/li>
&lt;/ul>
&lt;h3 id="misc">Misc&lt;/h3>
&lt;ul>
&lt;li>&lt;a href="https://jeffhuang.com/finding_computer_science_phd/" target="_blank" rel="noopener">Finding Advisors+Departments for your Computer Science Ph.D.&lt;/a> &amp;ndash; a collection of data-based resources to help one narrown down professors and departments maintained by Prof. Jeff Huang of Brown University&lt;/li>
&lt;li>&lt;a href="http://csrankings.org/" target="_blank" rel="noopener">CSRankings: Computer Science Rankings&lt;/a> &amp;ndash; &amp;ldquo;a metrics-based ranking of top computer science institutions around the world&amp;rdquo; maintained by Prof. Emery Berger of UMass Amherst&lt;/li>
&lt;li>&lt;a href="http://cs.brown.edu/~sk/Memos/Grad-School-Recos/" target="_blank" rel="noopener">Advice to Graduate School Recommendation Letter Writers&lt;/a> &amp;ndash; a memo for letter writers by Prof. Shriram Krishnamurthi of Brown University&lt;/li>
&lt;/ul>
&lt;h2 id="masters-specific">Master&amp;rsquo;s specific&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://cs.brown.edu/~sk/Memos/Funding-CS-Grad-School/" target="_blank" rel="noopener">How CS Master&amp;rsquo;s Funding Works (and Why You Can&amp;rsquo;t Seem to Get Any)&lt;/a> &amp;ndash; another memo by Shriram&lt;/li>
&lt;li>&lt;a href="https://cs.stanford.edu/~rkarthik/admissions.html#pac" target="_blank" rel="noopener">Personal Admissions Counseling&lt;/a> program run by NIT Calicut and Stanford University alumnus Karthik Raghunathan (ktick)&lt;/li>
&lt;/ul>
&lt;h2 id="phd-specific">PhD specific&lt;/h2>
&lt;ul>
&lt;li>🆕 &lt;a href="http://mycsphd.org/" target="_blank" rel="noopener">Whether, Why, and How to Get a Ph.D. in Computer Science&lt;/a> &amp;ndash; maintained by the Dept. of CSE at UC San Diego.&lt;/li>
&lt;li>&lt;a href="https://felleisen.org/matthias/Thoughts/Why_How_do_I_get_a_PhD.html" target="_blank" rel="noopener">Why/How do I get a PhD&lt;/a> &amp;ndash; advice from Prof. Matthias Felleisen.&lt;/li>
&lt;/ul>
&lt;!-- * [The Ph.D. Grind](http://pgbovine.net/PhD-memoir.htm) -- A 115-page PhD Student Memoir ebook by Prof. Philip J Guo. Goes into nitty gritty details of the PhD life, good read if you are trying to figure out what doing a PhD is like. [Archive link (PDF)](https://web.archive.org/web/20200505035810/http://pgbovine.net/PhD-memoir/pguo-PhD-grind.pdf). -->
&lt;ul>
&lt;li>Prof. Jean Yang of CMU maintains a list of her blog posts on useful advice on &lt;a href="https://www.cs.cmu.edu/~jyang2/join.html" target="_blank" rel="noopener">Applying to Graduate School on her webpage&lt;/a>:
&lt;ol>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-1-deciding-to-apply.html" target="_blank" rel="noopener">Deciding to Apply&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-2-standardized.html" target="_blank" rel="noopener">Standardized Tests&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-3-fellowships.html" target="_blank" rel="noopener">Fellowships&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-4-applications.html" target="_blank" rel="noopener">Applications&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-5-school-visits.html" target="_blank" rel="noopener">School Visits&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2009/02/some-notes-on-picking-grad.html" target="_blank" rel="noopener">Some notes on picking grad schools/advisors&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://jxyzabc.blogspot.com/2012/10/faq-applying-to-graduate-school-for.html" target="_blank" rel="noopener">FAQ: Applying to Graduate School for Computer Science&lt;/a>&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;p>I will try and maintain this page over time.&lt;/p></description></item><item><title>Address Autocompletion in Thunderbird using UChicago LDAP Directory Server</title><link>https://k4rtik.github.io/post/cs-ldap/</link><pubDate>Fri, 27 Apr 2018 15:42:41 -0500</pubDate><guid>https://k4rtik.github.io/post/cs-ldap/</guid><description>&lt;p>I use Thunderbird for all my UChicago CS related email, one of the major pain
points for me until recently was that there was no address autocompletion
available there. Not that it is available on UChicago GMail either, but somehow
that is tolerable.&lt;/p>
&lt;p>In this HOWTO, I document how to add LDAP directory search to Thunderbird (or
any other desktop email client).&lt;/p>
&lt;p>Here are all the settings that you need for Thunderbird (Preferences → Composition → Addressing → Edit Directories&amp;hellip; → Add Server):&lt;/p>
&lt;h2 id="general">General&lt;/h2>
&lt;ul>
&lt;li>Host: ldap.uchicago.edu&lt;/li>
&lt;li>Base DN: dc=uchicago,dc=edu&lt;/li>
&lt;li>Port number: 636 (along with Use secure connection (SSL) checked)&lt;/li>
&lt;li>Bind DN: uid=&amp;lt;&lt;em>CNET ID&lt;/em>&amp;gt;,ou=people,dc=uchicago,dc=edu&lt;/li>
&lt;/ul>
&lt;h2 id="advanced">Advanced&lt;/h2>
&lt;ul>
&lt;li>Scope: Subtree&lt;/li>
&lt;li>Search Filter: (&amp;amp;(objectclass=inetOrgPerson))&lt;/li>
&lt;li>Login method: Simple&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="acknowledgements">Acknowledgements&lt;/h3>
&lt;ul>
&lt;li>The amazing and always helpful &lt;a href="https://www.cs.uchicago.edu/directory/bob-bartlett" target="_blank" rel="noopener">Bob&lt;/a>&lt;/li>
&lt;li>UChicago ITS doc page on &lt;a href="https://uchicago.service-now.com/it?id=kb_article&amp;amp;kb=KB00015284" target="_blank" rel="noopener">LDAP Authentication&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>