Learn Quantum Computing with Python and Q#: A hands-on approach 1st Edition Sarah C. Kaiser instant download
Learn Quantum Computing with Python and Q#: A hands-on approach 1st Edition Sarah C. Kaiser instant download
https://ebookmeta.com/product/learn-quantum-computing-with-
python-and-q-a-hands-on-approach-1st-edition-sarah-c-kaiser/
https://ebookmeta.com/product/hands-on-matplotlib-learn-plotting-
and-visualizations-with-python-3-ashwin-pajankar/
https://ebookmeta.com/product/dancing-with-python-learn-python-
software-development-from-scratch-and-get-started-with-quantum-
computing-1st-edition-robert-s-sutor/
https://ebookmeta.com/product/hands-on-machine-learning-with-
python-implement-neural-network-solutions-with-scikit-learn-and-
pytorch-1st-edition-ashwin-pajankar/
https://ebookmeta.com/product/narratives-of-place-in-literature-
and-film-1st-edition-steven-allen/
New Literacies and Teacher Learning Professional
Development and the Digital Turn New Literacies and
Digital Epistemologies Michele Knobel (Editor)
https://ebookmeta.com/product/new-literacies-and-teacher-
learning-professional-development-and-the-digital-turn-new-
literacies-and-digital-epistemologies-michele-knobel-editor/
https://ebookmeta.com/product/production-design-the-cinematic-
home-1st-edition-jane-barnwell/
https://ebookmeta.com/product/the-law-of-higher-education-
student-version-student-version-6th-edition-william-a-kaplin-2/
https://ebookmeta.com/product/principles-of-california-real-
estate-19th-edition-kathryn-j-haupt/
https://ebookmeta.com/product/yorkie-doodle-dandy-8th-edition-
william-a-wynne/
T Helper Cells Francesco Annunziato Laura Maggi Alessio
Mazzoni
https://ebookmeta.com/product/t-helper-cells-francesco-
annunziato-laura-maggi-alessio-mazzoni/
A hands-on approach
Sarah Kaiser
Christopher Granade
MANNING
Description Code (Q# and QuTiP) Unitary matrix Mathematical examples
qtops.cnot() # QuTiP
SARAH KAISER
AND CHRIS GRANADE
MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning Publications
was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
ISBN: 9781617296130
Printed in the United States of America
We dedicate this book to the next generation of quantum developers who are working
to make this field a safer and more inclusive space.
brief contents
PART 1 GETTING STARTED WITH QUANTUM . ..............................1
1 ■ Introducing quantum computing 3
2 ■ Qubits: The building blocks 17
3 ■ Sharing secrets with quantum key distribution 54
4 ■ Nonlocal games: Working with multiple qubits 75
5 ■ Nonlocal games: Implementing a multi-qubit simulator 90
6 ■ Teleportation and entanglement: Moving
quantum data around 108
vii
contents
foreword xv
preface xvii
acknowledgments xix
about this book xxi
about the authors xxv
about the cover illustration xxvi
ix
x CONTENTS
algorithm 296
12.5 Putting it all together 299
"I did not hear you, Hume," answered Gowrie, in a grave tone.
"In truth, my friend, my heart is very sad, and my outward faculties
have little communication with the spirit within. But what makes you
look so joyful?"
"I wrote to him from Perth," said Gowrie, "beseeching him to give
me an answer to the suit, which I told you I had preferred, and he
has never replied my letter."
"He does consent," replied his friend, "and all your troubles on
that score, Gowrie, are at an end. So smoothe your wrinkled brow,
my noble lord, and give cold care to the wind."
"Are you quite sure?" demanded the earl, hardly believing the
joyful tidings.
"I am a bad dissembler, John," replied the earl, "and I fear that
the joy in my heart will shine out on my face, do what I will.
However, I will do my best to look sad; but is not this a strange
person for a king--a strange scene for a court?"
"You would have thought it stranger still, had you but seen the
whole," answered Hume. "All the time he was speaking, he held the
hawk I have told you of on his hand, and kept stroking it down the
back, at which it screamed, and then his gracious majesty called it
sometimes greedy gled, and sometimes courtier, till Herries, who
thinks he can venture anything, asked why he called it courtier."
"What did he answer?" inquired Gowrie.
Both Gowrie and Hume laughed gaily at this sally, the one in
hearing and the other in telling; for the young earl's heart was
lightened, and such creatures of circumstance are we, that, with a
mind relieved, a reply seemed to him full of humour, which a minute
or two before he would have thought nought but a coarse and
vulgar jest.
"How did Herries bear the rebuke?" asked Gowrie; "for to him it
must have been a severe one."
"Oh, with his own bitter humour," answered the knight. "He said,
'Ay, sir, it is sad how we are led by example. Every one, man and
beast, follows his master.' To which the king replied, good naturedly
enough, 'Haud yer peace, ye doited auld carle! If you followed your
master I'se warrant you'd no pluck but be plucked--you'd be the doo
and no the gled.' However, I think that Herries is not so great a
favourite as he once was; and I am not sorry for it, for he was ever
an enemy to both your house and mine, Gowrie, and is one of those
cold-blooded, ever-ready men, who never miss an opportunity to do
ill to another by a quiet insinuation pointed by a jest."
"For the present I do not think you need fear him in any way,"
replied Sir John Hume; "but go early to-morrow, Gowrie, and take
advantage of the tide of favour at the flow."
The conversation then took a more general turn. The various
characters of the personages of the court of King James were
discussed by the earl and his friend, and the prospects of the
country generally were spoken of in a lighter and a gayer spirit than
the earl could have shared in an hour before. Some little word--one
of those accidental expressions which often set the mind galloping in
a different direction from that which it was previously pursuing--led
the earl's thoughts suddenly to his brother; and he said, "By the
way, Hume, Beatrice seems to think that Alex is even in less favour
than myself with his majesty, and I could not induce her to explain
the matter fully. She referred me to you, saying you would be able to
inform me what was the cause of James's dislike."
"But is there any cause for this suspicion?" asked Gowrie, very
gravely. "Can Alex have been mad enough, wicked enough, to have
afforded any just grounds for such jealousy?"
"Well, well," answered his friend, "he is still a very young man,
but right at heart, I am sure; and I trust he will see that these
gallantries with the queen, however innocent, are, at the least,
improper."
"I must make him see it," said Gowrie, and turned the
conversation, which ended soon after by Hume leaving him to his
own thoughts.
"You see, my lord," said James, with a very serious air, "this is a
matter of much importance, and which requires full consideration
and deliberation on our part. Now I'll warrant that you're for wanting
to cut the matter short, and to be married to the lady directly;" and
he looked up slily in the earl's face.
"She's a very discreet young lady," said the king. "Feggs! most
lasses would be all agog to be a married woman, and Countess of
Gowrie. Well, my lord, we'll consider of it."
Gowrie now felt alarmed and mortified. Whether the king had
changed his mind since the preceding night, or whether he was
merely sporting with his feelings for his own amusement, the young
lover felt a degree of impatience which he was afraid would break
forth in some angry words if he stayed longer; and therefore, with a
silent bow, but a heated cheek and disappointed air, he retired
towards the door.
James let him reach it and lay his hand upon the lock, but then
stopped him, exclaiming, "Hoot, man, come hither--don't go away in
the dorts, like a petted bairn. Come hither to your king, who is
willing to act as a good and kind father to you and to all his leal
subjects, if they will let him."
"I'm thinking you're a false chiel," said James, laughing; "and you
think that a fine fleeching speech, about my countenance, as you
call it; but I'll tell you what, earl, if I thought my face would tell what
I'm thinking of when I didn't want it, I'd claw the skin off it with my
own ten fingers; for let me inform you, sir, it's a principal point of
kingcraft to be able to speak with a sober and demure countenance,
whatever the matter in hand may be, whether merry and jocose, or
sad and serious. Men should never be able to tell, by the looks of a
sovereign, whether he be thinking of a burial or a marriage, a birth
or a death."
"But wise kings, sire," answered Gowrie, "are ever apt to double
the value of the favours they confer by gracious looks and words."
"That's well said," said the king, with an inclination of his head.
"That's spoken like a prudent and well-nurtured lad; and we do
intend graciously towards you, and will give you proof thereof. We
will consent to your marriage with this lady in the month of
September next, as you suppose; and, moreover, we will give you
that consent in writing, for there are certain conditions which, as you
know well, you yourself agreed to, and which we have embodied
here in this paper, as a sort of proviso, qualifying our consent."
James caught readily at this idea; and being fond of showing his
skill in such matters, he at once drew up, with his own hand, the
form of undertaking which was proposed, and to which Gowrie
willingly put his hand, on receiving the written consent of the king to
his marriage.
"Bring him in--bring him in," cried James. "Stay a little, my good
lord; this is a man from the country you know so well, bringing
wares to show us, and we will have your judgment upon his bonny
toys."
Gowrie would fain have escaped, but there was no resource; and
the Italian merchant, as he was called, though in fact he might have
ranked better as a pedlar, was brought into the king's presence. The
young earl instantly recognised a man from whom he himself had
occasionally purchased wares in Padua, which was at that time
famous for its manufactories of silk; and the merchant himself, after
saluting the king, made him a low bow.
"Ah, you two have met before, I suppose," said the king. "But
come, open your chest, man, and let us see what you've brought."
CHAPTER XXXIV.
"Can you tell me where I shall find my sister, Ballough?" said the
Earl of Gowrie, addressing the usher of the queen's chambers, after
he left the king.
"She's gone out with her brother, my lord," replied the officer;
"and I think they took their way to your lordship's lodgings."
"I do not think it, Ballough," said the earl. "I must have met
them; or at least they must have seen my horses at the gate."
"They went the other way, my lord," said the man. "I saw them
go towards the physic garden. I heard the Lady Beatrice say that
that would be the quietest road, as they were on foot."
"Not through this passage, my lord," replied the man, "but if you
go round by the portico, you'll find the little gate open, and that will
lead you straight."
The earl accordingly dismissed his horses and servants, and took
his way through a part of the gardens of Holyrood, or "the abbey,"
as it was frequently called in those days, issuing forth into the more
busy part of the town by a gate at some distance from the palace.
The door itself was closed but not locked; and, as he was
approaching it, he heard a voice saying, "We have not starved your
horse, you foul-tongued southron! Now, ride away as fast as you can
go; and mind, if you say one word, you will be put into one of the
dungeons at Stirling, and treated to a taste of the boot you saw the
other day. There, away with you!" And these words were followed by
the loud crack of a whip.
"A whole skin is the best coat that ever was made," said a voice
which Gowrie thought he knew well, and passing through the door
at the same moment, he looked eagerly up the street, his eye
guided by the clattering of a horse's feet at a rapid pace. On that
side appeared no other than the figure of his own man, Austin Jute,
mounted on the very horse which he had ridden to Trochrie; and
turning sharply round, the earl saw on the other hand, walking away
towards the palace, the stout form and club foot of Dr. Herries, and
another gentleman attached to the king's household, named
Graham.
"We thought to catch you before you set out, Gowrie," said
Beatrice, as soon as she saw him, "for Hume wrote me word this
morning that he had seen you. However, I trust, from your look, that
all is safe and right, and that the king's good humour, which waxes
and wanes like the moon, has not decreased since yesterday."
Gowrie sat down by her side, and told her all that had occurred,
the whole account being tinged with the joyful hopes of his own
heart. Beatrice looked pleased, but less so than he expected; and
she asked, somewhat abruptly, "And now, Gowrie, what do you
intend to do?"
"If you will come with me, Alex," replied his brother.
"What! and have they poisoned your mind, too, Gowrie?" cried
the other, impetuously. "I will not go; for by so doing I should only
confirm the falsehoods they have spread. I will not abandon my own
cause, or show a shame of my own conduct, whatever my friends
and relations may do."
"You speak too warmly, Alex," said the young earl. "Your relations
have no inclination to abandon your cause; and I trust and believe
you would never give them occasion to feel ashamed of your
conduct; but I only advise you for your own good. Suspicion is a
dangerous thing in the mind of a king, and, whether justly or
unjustly founded, is to be avoided by all reasonable means. Besides,
were your royal master and lady entirely out of the question, no man
has a right to furnish cause for dissension in any family."
"I would have it any other object than yourself, Alex," replied his
brother. "However, I have given you my advice, and you may take it
or not, as you please."
"I shall certainly not withdraw from the court," replied Alexander
Ruthven, in an impatient tone. "I should consider that I was doing
wrong to the character of another whom I am bound to love and
respect. Therefore, to give me that advice, Gowrie, is but talking to
the winds, for in this case I am sure I am right."
"I much doubt it," replied the earl, and there dropped the subject,
for he saw that it would be of no avail to pursue it farther.
Beatrice had remained silent during this brief conversation
between the two brothers, with her eyes bent down on the ground
and her cheek somewhat pale, but the moment it was concluded,
she looked up, recurring at once to what had been passing before.
"I would offer to go with you, Gowrie," she said, "and cheer your
dear Julia in her solitude; but I think I may be more useful to you
both where I am; for, both on your account and on Alex's, my task
must be to watch narrowly everything that occurs, and give you the
first intimation of danger. Whether Alex will receive a warning I do
not know; but you, Gowrie, I am sure, will listen to the very first hint
that I give you. I may not be able to speak plainly. I may be obliged
to write but a few words; but watch and understand, my dear
brother, and if I say, fly, then lose not a moment."
"How can I suppose you will take a warning," asked his sister,
"when you will take no advice?"
"You see he suspects every one as well as me," said her young
brother, determined to make out a case in his own favour; "and I am
sure Gowrie is as little a favourite as I am myself. Besides, I do
believe from his conduct yesterday, that James is now convinced his
previous suspicions were unjust, and that he desires to make
atonement."
Then bidding her elder brother adieu, the lady left him, and,
accompanied by Alexander, walked back almost in silence to
Holyrood; for she herself was full of doubts and anxieties, and
Alexander Ruthven was in that state of irritation which is often
produced, especially in a young mind, by a conflict between a wish
to do right and strong temptations to do wrong.
I need not pause to detail the passing of the day with Gowrie.
The law's delay is proverbial as one of the banes of human existence
in the blessed land wherein we live.--It was so even in his time; and
he found, on consulting with those who had to deal with such
matters, that the drawing up of the renunciation, simple as it
seemed, would require the labour and attention of several days, in
order to couch it in the full and ample terms which he knew would
be required by the king. He had to give long explanations, and to
enter into details which he had not previously considered, so that
the greater part of a spring day was consumed before he left the
dim and dingy den where the man of law held his abode. On his
return to his own house he passed more than an hour in walking up
and down the large and handsome sitting-room, and meditating over
the past and the future. If it be asked whether his thoughts were
sad or bright, I must answer, very much mixed, as is ever the case
with a man of strong sense and active imagination. But Gowrie, it
must be remembered, was in the spring of life, in that bright season
when the song of the wild bird, hope, is the most loud and sweet
and seducing. The circumstances which surrounded him might alarm
or sadden him for the time, but the cheering voice still spoke up in
his heart, and the syren sang not in vain. At length he ordered lights
to be brought, and casting himself into a chair, took up a book--his
favourite Sallust--and began to read. The pages opened at the
Catiline, and the first words struck him, as strangely applicable to
the half-formed resolution which had been floating vaguely in his
mind, of passing life in peaceful retirement.
He had not time, however, to turn the pages of the book before
the door quietly opened behind him, and a step was heard upon the
floor. He did not turn his head, however; and the person who came
in proceeded round the table to the opposite side of the fireplace,
when Gowrie, suddenly looking up, beheld his servant, Austin Jute.