Skip to content

Commit

Permalink
renaming cuQuantum to cirq (refs #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Feb 12, 2022
1 parent 18d3924 commit f816668
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 77 deletions.
12 changes: 5 additions & 7 deletions apps/www/app/controllers/backend_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cu_quantum'
require 'cirq'

class BackendController < ApplicationController
# rubocop:disable Metrics/AbcSize
Expand All @@ -10,13 +10,11 @@ def show
steps = params[:steps] ? JSON.parse(params[:steps]) : []
targets = params[:targets].split(',').map(&:to_i) if params[:targets]

raise "Unsupported backend: #{backend}" unless backend == 'cu_quantum'
raise "Unsupported backend: #{backend}" unless backend == 'cirq'

@step_results = CuQuantum.new(circuit_id: circuit_id,
qubit_count: qubit_count,
step_index: step_index,
steps: steps,
targets: targets).run
@step_results =
Cirq.new(circuit_id: circuit_id, qubit_count: qubit_count, step_index: step_index, steps: steps, targets: targets)
.run
end
# rubocop:enable Metrics/AbcSize
end
3 changes: 3 additions & 0 deletions apps/www/app/controllers/cirq_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CirqController < ApplicationController
def show; end
end
3 changes: 0 additions & 3 deletions apps/www/app/controllers/cu_quantum_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
<% content_for :meta_ogp do %>
<eext1>
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="<%= twitter_title %>" />
<% if @json %>
<meta property="og:url" content="<%= circuit_url @json %>" />
<meta property="og:description" content="<%= og_description @json %>" />
<% end %>
<% if @circuit&.social_image&.attached? %>
<meta property="og:image" content="<%= rails_blob_url(@circuit.social_image, disposition: 'inline') %>" />
<% end %>
<% end %>
<meta name="twitter:title" content="eex2eex" />
<eext3>
<meta property="og:url" content="eex4eex" />
<meta property="og:description" content="eex5eex" />
</eext3>
<eext6>
<meta property="og:image" content="eex7eex" />
</eext6>
</eext1>

<div class="relative flex w-full flex-row-reverse overflow-x-scroll md:flex-none md:flex-row">
<quantum-simulator class="inline-block" data-backend="cu_quantum" data-update-url>
<quantum-simulator class="inline-block" data-backend="cirq" data-update-url>
<circuit-editor class="flex w-full flex-row justify-end md:inline-block">
<div
data-controller="share"
data-share-default-title-value="Qni"
data-share-circuit-url-value="<%= circuit_url %>"
>
<%= share_modal %>
<%= menu %>
<div data-controller="share" data-share-default-title-value="Qni" data-share-circuit-url-value="eex8eex">
<eext9 />
<eext10 />
</div>

<div class="fixed top-0 right-0 z-40 rounded-bl-2xl bg-white drop-shadow-xl">
<inspector-button data-target="circuit-editor.inspectorButton" class="inline-block h-10 w-10 p-1">
<div class="flex h-full w-full items-center justify-center rounded-xl hover:bg-gray-200">
<%= icon :mixer_horizontal %>
<eext11 />
</div>
</inspector-button>
</div>

<%= palette_md %>
<eext12 />

<quantum-circuit
class="my-52 mx-6"
Expand All @@ -41,24 +37,18 @@
></quantum-circuit>

<div class="fixed bottom-0 left-0 right-0 z-30 mx-6 mb-6 flex flex-row items-center">
<%=
run_circuit_button class:
'run-circuit-button--mobile inline-block md:hidden w-10 h-10 shrink-0 mr-2 bg-white rounded-full drop-shadow-md'
%>
<%= palette %>
<eext13 />
<eext14 />
</div>

<%= circle_notation %>
<eext15 />
</circuit-editor>

<%=
run_circuit_button class:
'hidden md:inline-block fixed bottom-0 right-0 mr-6 mb-8 w-16 h-16 text-white bg-purple-500 rounded-full drop-shadow-md z-40'
%>
<eext16 />
</quantum-simulator>
</div>

<%= palette_help_templates %>
<eext17 />

<template id="operation-menu">
<div class="operation-menu flex flex-row items-center space-x-2 text-gray-900">
Expand All @@ -82,7 +72,7 @@
class="inline-flex h-8 w-8 items-center justify-center rounded border border-transparent bg-white hover:bg-gray-200 focus:outline-none"
disabled
>
<%= icon :angle %>
<eext18 />
</button>

<button
Expand All @@ -101,7 +91,7 @@
data-operation-menu-delete
class="flex h-8 w-8 cursor-pointer items-center justify-center rounded-full bg-white drop-shadow-lg hover:bg-red-200"
>
<%= icon :trash, class: 'h-4 w-4' %>
<eext19 />
</div>
</div>
</template>
Expand Down
17 changes: 10 additions & 7 deletions apps/www/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do
resources :circuits, only: %i[index] if Rails.env.development?
Rails
.application
.routes
.draw do
resources :circuits, only: %i[index] if Rails.env.development?

get '/backend', to: 'backend#show'
get '/cu_quantum/(:json)', to: 'cu_quantum#show', as: :cu_quantum
get 'svg/(:json)', to: 'circuit_svg#show', as: :circuit_svg, constraints: { json: /.*/ }
get '/(:json)', to: 'circuits#show', as: :circuit, constraints: { json: /.*/ }
end
get '/backend', to: 'backend#show'
get '/cirq/(:json)', to: 'cirq#show', as: :cirq
get 'svg/(:json)', to: 'circuit_svg#show', as: :circuit_svg, constraints: { json: /.*/ }
get '/(:json)', to: 'circuits#show', as: :circuit, constraints: { json: /.*/ }
end
41 changes: 17 additions & 24 deletions apps/www/lib/cu_quantum.rb → apps/www/lib/cirq.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CuQuantum
class Cirq
def initialize(circuit_id:, qubit_count:, step_index:, steps:, targets:)
@circuit_id = circuit_id
@qubit_count = qubit_count
Expand All @@ -8,9 +8,7 @@ def initialize(circuit_id:, qubit_count:, step_index:, steps:, targets:)
end

def run
@steps.map.with_index do |each, index|
execute_step each, index
end
@steps.map.with_index { |each, index| execute_step each, index }
end

private
Expand All @@ -24,47 +22,42 @@ def execute_step(step, index)
step.each_with_index do |each, bit|
case each.fetch('type')
when 'H'
# {"type"=>"H", "controls"=>[], "if"=>nil}
# {"type"=>"H", "controls"=>[], "if"=>nil}
when 'X'
# {"type"=>"X", "controls"=>[], "if"=>nil}
# {"type"=>"X", "controls"=>[], "if"=>nil}
when 'Y'
# {"type"=>"Y", "controls"=>[], "if"=>nil}
# {"type"=>"Y", "controls"=>[], "if"=>nil}
when 'Z'
# {"type"=>"Z", "controls"=>[], "if"=>nil}
# {"type"=>"Z", "controls"=>[], "if"=>nil}
when 'P'
# {"type"=>"P", "phi"=>"pi/2", "controls"=>[], "targets"=>[0], "if"=>nil}
# {"type"=>"P", "phi"=>"pi/2", "controls"=>[], "targets"=>[0], "if"=>nil}
when 'X^½'
# {"type"=>"X^½", "controls"=>[], "if"=>nil}
# {"type"=>"X^½", "controls"=>[], "if"=>nil}
when 'Rx'
# {"type"=>"Rx", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
# {"type"=>"Rx", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
when 'Ry'
# {"type"=>"Ry", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
# {"type"=>"Ry", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
when 'Rz'
# {"type"=>"Rz", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
# {"type"=>"Rz", "theta"=>"pi/2", "controls"=>[], "targets"=>[], "if"=>nil}
when 'Swap'
# {"type"=>"Swap", "controls"=>[], "targets"=>[]}
# {"type"=>"Swap", "controls"=>[], "targets"=>[]}
when '•'
# {"type"=>"•", "targets"=>[0]}
# {"type"=>"•", "targets"=>[0]}
when 'Bloch'
# {"type"=>"Bloch"}
# {"type"=>"Bloch"}
when 'Write'
# {"type"=>"Write", "value"=>0}
# {"type"=>"Write", "value"=>0}
when 'Measure'
# {"type"=>"Measure", "flag"=>""}
measured_bits[bit] = [0, 1].sample # rubocop:disable Performance/CollectionLiteralInLoop
when '1'
# NOP
# NOP
else
raise "Unknown operation: #{each.inspect}"
end
end

amplitudes =
if index == @step_index
@targets.index_with do
[rand, 0]
end
end
amplitudes = (@targets.index_with { [rand, 0] } if index == @step_index)

{ amplitudes: amplitudes, measuredBits: measured_bits, blochVectors: {} }
end
Expand Down
2 changes: 1 addition & 1 deletion apps/www/test/controllers/backend_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class BackendControllerTest < ActionDispatch::IntegrationTest
test 'should get show' do
get backend_url(format: :json, backend: 'cu_quantum')
get backend_url(format: :json, backend: 'cirq')
assert_response :success
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'test_helper'

class CuQuantumControllerTest < ActionDispatch::IntegrationTest
class CirqControllerTest < ActionDispatch::IntegrationTest
test 'should get show' do
get cu_quantum_url
get cirq_url
assert_response :success
end
end

0 comments on commit f816668

Please sign in to comment.